Skip to content

Commit

Permalink
Refactor server and setting tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sir-Thom committed Dec 28, 2023
1 parent 0d149d9 commit 0bdc8e9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 64 deletions.
17 changes: 1 addition & 16 deletions tests/server.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,7 @@ describe("ServerInfo Component", () => {
const titlebarContainer = document.createElement("div");
titlebarContainer.id = "titlebar";
document.body.appendChild(titlebarContainer);
beforeAll(() => {
Object.defineProperty(window, "crypto", {
value: {
getRandomValues: (buffer) => {
return randomFillSync(buffer);
}
}
});
mockIPC((cmd: any, args: any) => {
if (cmd === "close_splashscreen") {
return Promise.resolve();
}
});
const spy = vi.spyOn(window, "__TAURI_IPC__");
expect(invoke("close_splashscreen")).resolves.all;
});


test("renders ServerInfo component with RTSP setting by default", () => {
render(
Expand Down
51 changes: 3 additions & 48 deletions tests/setting.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,7 @@ describe("Setting Component", () => {
titlebarContainer.id = "titlebar";
document.body.appendChild(titlebarContainer);

beforeAll(() => {
mockIPC((cmd, args) => {
if (cmd === "get_server_request") {
return Promise.resolve({ url: "http://127.0.0.1:9997/v3/config/global/get" });
}
if (cmd === "patch_server_request") {
return Promise.resolve({ url: "http://127.0.0.1:9997/v3/config/global/patch"});
}
});
});


test("renders Setting component", () => {
render(
Expand Down Expand Up @@ -200,42 +191,6 @@ describe("Setting Component", () => {

});

test("updates state and invokes save_api_ip", () => {
const initialSettings = {
apiSettings: { api: true },
loggingSettings: { logLevel: "info" },
hlsSettings: { hls: true },
rtspSettings: { rtsp: true },
rtmpSettings: { rtmp: true },
srtSettings: { srt: true },
webrtcSettings: { webrtc: true },
recordSettings: { record: true },
};



const expectedUpdatedSettings = {
apiSettings: { api: false, metrics: true },
loggingSettings: { logLevel: "debug" },
hlsSettings: { hls: false },
rtspSettings: { rtsp: false },
rtmpSettings: { rtmp: false },
srtSettings: { srt: false },
webrtcSettings: { webrtc: false },
recordSettings: { record: false },
};
render(
<MemoryRouter>
<Setting/>
</MemoryRouter>
);
invoke("patch_server_request", {url:"http://127.0.0.1:9997/v3/config/global/patch"});
spyOn(window, "__TAURI_IPC__" as any);
expect(invoke("patch_server_request")).resolves.all;


expect(initialSettings).not.toEqual(expectedUpdatedSettings);
});

});

});

0 comments on commit 0bdc8e9

Please sign in to comment.