mirror of
https://gitlab.nic.cz/turris/reforis/foris-js.git
synced 2024-12-24 00:01:36 +01:00
Merge branch 'one-wifi-module-fix' into 'dev'
Fix form submission button with one Wi-Fi module. Closes reforis#192 See merge request turris/reforis/foris-js!115
This commit is contained in:
commit
ae8baddbdd
|
@ -64,7 +64,7 @@ function prepDataToSubmit(formData) {
|
||||||
return formData;
|
return formData;
|
||||||
}
|
}
|
||||||
|
|
||||||
function validator(formData) {
|
export function validator(formData) {
|
||||||
const formErrors = formData.devices.map(
|
const formErrors = formData.devices.map(
|
||||||
(device) => {
|
(device) => {
|
||||||
if (!device.enabled) return {};
|
if (!device.enabled) return {};
|
||||||
|
@ -89,5 +89,5 @@ function validator(formData) {
|
||||||
return errors;
|
return errors;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
return JSON.stringify(formErrors) === "[{},{}]" ? null : formErrors;
|
return JSON.stringify(formErrors).match(/\[[{},?]+\]/) ? null : formErrors;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,8 @@ 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 } from "./__fixtures__/wifiSettings";
|
import { wifiSettingsFixture, oneDevice, twoDevices, threeDevices } from "./__fixtures__/wifiSettings";
|
||||||
import { WiFiSettings } from "../WiFiSettings";
|
import { WiFiSettings, validator } from "../WiFiSettings";
|
||||||
|
|
||||||
describe("<WiFiSettings/>", () => {
|
describe("<WiFiSettings/>", () => {
|
||||||
let firstRender;
|
let firstRender;
|
||||||
|
@ -159,4 +159,18 @@ describe("<WiFiSettings/>", () => {
|
||||||
};
|
};
|
||||||
expect(mockAxios.post).toHaveBeenCalledWith(endpoint, data, expect.anything());
|
expect(mockAxios.post).toHaveBeenCalledWith(endpoint, data, expect.anything());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Validator function using regex for one device", () => {
|
||||||
|
expect(validator(oneDevice)).toEqual(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Validator function using regex for two devices", () => {
|
||||||
|
const twoDevicesFormErrors = [{SSID: "SSID can't be empty"}, {}];
|
||||||
|
expect(validator(twoDevices)).toEqual(twoDevicesFormErrors);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Validator function using regex for three devices", () => {
|
||||||
|
const threeDevicesFormErrors = [{}, {}, {password: "Password must contain at least 8 symbols"}];
|
||||||
|
expect(validator(threeDevices)).toEqual(threeDevicesFormErrors);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -316,3 +316,85 @@ export function wifiSettingsFixture() {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
const oneDevice = {
|
||||||
|
devices: [
|
||||||
|
{
|
||||||
|
SSID: "Turris1",
|
||||||
|
channel: 60,
|
||||||
|
enabled: true,
|
||||||
|
guest_wifi: { enabled: false },
|
||||||
|
hidden: false,
|
||||||
|
htmode: "HT40",
|
||||||
|
hwmode: "11a",
|
||||||
|
id: 0,
|
||||||
|
password: "TestPass"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
const twoDevices = {
|
||||||
|
devices: [
|
||||||
|
{
|
||||||
|
SSID: "",
|
||||||
|
channel: 60,
|
||||||
|
enabled: true,
|
||||||
|
guest_wifi: { enabled: false },
|
||||||
|
hidden: false,
|
||||||
|
htmode: "HT40",
|
||||||
|
hwmode: "11a",
|
||||||
|
id: 0,
|
||||||
|
password: "TestPass"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
SSID: "Turris2",
|
||||||
|
channel: 60,
|
||||||
|
enabled: true,
|
||||||
|
guest_wifi: { enabled: false },
|
||||||
|
hidden: false,
|
||||||
|
htmode: "HT40",
|
||||||
|
hwmode: "11a",
|
||||||
|
id: 0,
|
||||||
|
password: "TestPass"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
const threeDevices = {
|
||||||
|
devices: [
|
||||||
|
{
|
||||||
|
SSID: "Turris1",
|
||||||
|
channel: 60,
|
||||||
|
enabled: true,
|
||||||
|
guest_wifi: { enabled: false },
|
||||||
|
hidden: false,
|
||||||
|
htmode: "HT40",
|
||||||
|
hwmode: "11a",
|
||||||
|
id: 0,
|
||||||
|
password: "TestPass"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
SSID: "Turris2",
|
||||||
|
channel: 60,
|
||||||
|
enabled: false,
|
||||||
|
guest_wifi: { enabled: false },
|
||||||
|
hidden: false,
|
||||||
|
htmode: "HT40",
|
||||||
|
hwmode: "11a",
|
||||||
|
id: 0,
|
||||||
|
password: "TestPass"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
SSID: "Turris3",
|
||||||
|
channel: 60,
|
||||||
|
enabled: true,
|
||||||
|
guest_wifi: { enabled: false },
|
||||||
|
hidden: false,
|
||||||
|
htmode: "HT40",
|
||||||
|
hwmode: "11a",
|
||||||
|
id: 0,
|
||||||
|
password: ""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
export {oneDevice, twoDevices, threeDevices};
|
Loading…
Reference in New Issue
Block a user