1
0
mirror of https://gitlab.nic.cz/turris/reforis/foris-js.git synced 2024-12-26 00:21:36 +01:00

Fix tests

This commit is contained in:
Aleksandr Gumroian 2020-08-18 15:40:07 +02:00
parent a2acac255d
commit 5ae129b0f5
No known key found for this signature in database
GPG Key ID: 9E77849C64F0A733

View File

@ -13,7 +13,12 @@ import { fireEvent, render, wait } from "customTestRender";
import { WebSockets } from "webSockets/WebSockets"; import { WebSockets } from "webSockets/WebSockets";
import { mockJSONError } from "testUtils/network"; import { mockJSONError } from "testUtils/network";
import { wifiSettingsFixture, oneDevice, twoDevices, threeDevices } from "./__fixtures__/wifiSettings"; import {
wifiSettingsFixture,
oneDevice,
twoDevices,
threeDevices,
} from "./__fixtures__/wifiSettings";
import { WiFiSettings, validator } from "../WiFiSettings"; import { WiFiSettings, validator } from "../WiFiSettings";
describe("<WiFiSettings/>", () => { describe("<WiFiSettings/>", () => {
@ -26,7 +31,13 @@ describe("<WiFiSettings/>", () => {
beforeEach(async () => { beforeEach(async () => {
const webSockets = new WebSockets(); const webSockets = new WebSockets();
const renderRes = render(<WiFiSettings ws={webSockets} endpoint={endpoint} resetEndpoint="foo" />); const renderRes = render(
<WiFiSettings
ws={webSockets}
endpoint={endpoint}
resetEndpoint="foo"
/>
);
asFragment = renderRes.asFragment; asFragment = renderRes.asFragment;
getAllByText = renderRes.getAllByText; getAllByText = renderRes.getAllByText;
getAllByLabelText = renderRes.getAllByLabelText; getAllByLabelText = renderRes.getAllByLabelText;
@ -38,7 +49,14 @@ describe("<WiFiSettings/>", () => {
it("should handle error", async () => { it("should handle error", async () => {
const webSockets = new WebSockets(); const webSockets = new WebSockets();
const { getByText } = render(<WiFiSettings ws={webSockets} ws={webSockets} endpoint={endpoint} resetEndpoint="foo" />); const { getByText } = render(
<WiFiSettings
ws={webSockets}
ws={webSockets}
endpoint={endpoint}
resetEndpoint="foo"
/>
);
const errorMessage = "An API error occurred."; const errorMessage = "An API error occurred.";
mockJSONError(errorMessage); mockJSONError(errorMessage);
await wait(() => { await wait(() => {
@ -51,21 +69,21 @@ describe("<WiFiSettings/>", () => {
}); });
it("Snapshot one module enabled.", () => { it("Snapshot one module enabled.", () => {
fireEvent.click(getAllByText("Enable")[0]); fireEvent.click(getByText("Wi-Fi 1"));
expect(diffSnapshot(firstRender, asFragment())).toMatchSnapshot(); expect(diffSnapshot(firstRender, asFragment())).toMatchSnapshot();
}); });
it("Snapshot 2.4 GHz", () => { it("Snapshot 2.4 GHz", () => {
fireEvent.click(getAllByText("Enable")[0]); fireEvent.click(getByText("Wi-Fi 1"));
const enabledRender = asFragment(); const enabledRender = asFragment();
fireEvent.click(getAllByText("2.4")[0]); fireEvent.click(getAllByText("2.4")[0]);
expect(diffSnapshot(enabledRender, asFragment())).toMatchSnapshot(); expect(diffSnapshot(enabledRender, asFragment())).toMatchSnapshot();
}); });
it("Snapshot guest network.", () => { it("Snapshot guest network.", () => {
fireEvent.click(getAllByText("Enable")[0]); fireEvent.click(getByText("Wi-Fi 1"));
const enabledRender = asFragment(); const enabledRender = asFragment();
fireEvent.click(getAllByText("Enable Guest Wifi")[0]); fireEvent.click(getAllByText("Enable Guest Wi-Fi")[0]);
expect(diffSnapshot(enabledRender, asFragment())).toMatchSnapshot(); expect(diffSnapshot(enabledRender, asFragment())).toMatchSnapshot();
}); });
@ -78,11 +96,15 @@ describe("<WiFiSettings/>", () => {
{ enabled: false, id: 1 }, { enabled: false, id: 1 },
], ],
}; };
expect(mockAxios.post).toHaveBeenCalledWith(endpoint, data, expect.anything()); expect(mockAxios.post).toHaveBeenCalledWith(
endpoint,
data,
expect.anything()
);
}); });
it("Post form: one module enabled.", () => { it("Post form: one module enabled.", () => {
fireEvent.click(getAllByText("Enable")[0]); fireEvent.click(getByText("Wi-Fi 1"));
fireEvent.click(getByText("Save")); fireEvent.click(getByText("Save"));
expect(mockAxios.post).toBeCalled(); expect(mockAxios.post).toBeCalled();
@ -102,11 +124,15 @@ describe("<WiFiSettings/>", () => {
{ enabled: false, id: 1 }, { enabled: false, id: 1 },
], ],
}; };
expect(mockAxios.post).toHaveBeenCalledWith(endpoint, data, expect.anything()); expect(mockAxios.post).toHaveBeenCalledWith(
endpoint,
data,
expect.anything()
);
}); });
it("Post form: 2.4 GHz", () => { it("Post form: 2.4 GHz", () => {
fireEvent.click(getAllByText("Enable")[0]); fireEvent.click(getByText("Wi-Fi 1"));
fireEvent.click(getAllByText("2.4")[0]); fireEvent.click(getAllByText("2.4")[0]);
fireEvent.click(getByText("Save")); fireEvent.click(getByText("Save"));
@ -127,13 +153,19 @@ describe("<WiFiSettings/>", () => {
{ enabled: false, id: 1 }, { enabled: false, id: 1 },
], ],
}; };
expect(mockAxios.post).toHaveBeenCalledWith(endpoint, data, expect.anything()); expect(mockAxios.post).toHaveBeenCalledWith(
endpoint,
data,
expect.anything()
);
}); });
it("Post form: guest network.", () => { it("Post form: guest network.", () => {
fireEvent.click(getAllByText("Enable")[0]); fireEvent.click(getByText("Wi-Fi 1"));
fireEvent.click(getAllByText("Enable Guest Wifi")[0]); fireEvent.click(getAllByText("Enable Guest Wi-Fi")[0]);
fireEvent.change(getAllByLabelText("Password")[1], { target: { value: "test_password" } }); fireEvent.change(getAllByLabelText("Password")[1], {
target: { value: "test_password" },
});
fireEvent.click(getByText("Save")); fireEvent.click(getByText("Save"));
expect(mockAxios.post).toBeCalled(); expect(mockAxios.post).toBeCalled();
@ -157,7 +189,11 @@ describe("<WiFiSettings/>", () => {
{ enabled: false, id: 1 }, { enabled: false, id: 1 },
], ],
}; };
expect(mockAxios.post).toHaveBeenCalledWith(endpoint, data, expect.anything()); expect(mockAxios.post).toHaveBeenCalledWith(
endpoint,
data,
expect.anything()
);
}); });
it("Validator function using regex for one device", () => { it("Validator function using regex for one device", () => {
@ -170,7 +206,11 @@ describe("<WiFiSettings/>", () => {
}); });
it("Validator function using regex for three devices", () => { it("Validator function using regex for three devices", () => {
const threeDevicesFormErrors = [{}, {}, {password: "Password must contain at least 8 symbols"}]; const threeDevicesFormErrors = [
{},
{},
{ password: "Password must contain at least 8 symbols" },
];
expect(validator(threeDevices)).toEqual(threeDevicesFormErrors); expect(validator(threeDevices)).toEqual(threeDevicesFormErrors);
}); });
}); });