1
0
mirror of https://gitlab.nic.cz/turris/reforis/foris-js.git synced 2024-06-28 20:03:59 +00:00

Merge branch 'dev' into 'new-channel-bandwidth'

# Conflicts:
#   src/common/WiFiSettings/WiFiForm.js
This commit is contained in:
Aleksandr Gumroian 2020-07-17 16:24:43 +02:00
commit e7f9fbca96
4 changed files with 112 additions and 16 deletions

View File

@ -38,12 +38,12 @@ WiFiForm.defaultProps = {
export default function WiFiForm({
formData, formErrors, setFormValue, hasGuestNetwork, disabled,
}) {
return formData.devices.map((device, idx) => (
return formData.devices.map((device, index) => (
<DeviceForm
key={device.id}
formData={device}
deviceNumber={idx}
formErrors={(formErrors || [])[idx]}
deviceIndex={index}
formErrors={(formErrors || [])[index]}
setFormValue={setFormValue}
hasGuestNetwork={hasGuestNetwork}
disabled={disabled}
@ -66,7 +66,7 @@ DeviceForm.propTypes = {
formErrors: PropTypes.object.isRequired,
setFormValue: PropTypes.func.isRequired,
hasGuestNetwork: PropTypes.bool,
deviceNumber: PropTypes.number,
deviceIndex: PropTypes.number,
};
DeviceForm.defaultProps = {
@ -75,7 +75,7 @@ DeviceForm.defaultProps = {
};
function DeviceForm({
formData, formErrors, setFormValue, hasGuestNetwork, deviceNumber, ...props
formData, formErrors, setFormValue, hasGuestNetwork, deviceIndex, ...props
}) {
const deviceID = formData.id;
return (
@ -86,7 +86,7 @@ function DeviceForm({
checked={formData.enabled}
onChange={setFormValue(
(value) => ({ devices: { [deviceNumber]: { enabled: { $set: value } } } }),
(value) => ({ devices: { [deviceIndex]: { enabled: { $set: value } } } }),
)}
{...props}
@ -102,7 +102,7 @@ function DeviceForm({
onChange={setFormValue(
(value) => ({
devices: {
[deviceNumber]: {
[deviceIndex]: {
SSID: { $set: value },
},
},
@ -129,7 +129,7 @@ function DeviceForm({
onChange={setFormValue(
(value) => (
{ devices: { [deviceNumber]: { password: { $set: value } } } }
{ devices: { [deviceIndex]: { password: { $set: value } } } }
),
)}
@ -143,7 +143,7 @@ function DeviceForm({
onChange={setFormValue(
(value) => (
{ devices: { [deviceNumber]: { hidden: { $set: value } } } }
{ devices: { [deviceIndex]: { hidden: { $set: value } } } }
),
)}
@ -160,7 +160,7 @@ function DeviceForm({
onChange={setFormValue(
(value) => ({
devices: {
[deviceNumber]: {
[deviceIndex]: {
hwmode: { $set: value },
channel: { $set: "0" },
},
@ -179,7 +179,7 @@ function DeviceForm({
onChange={setFormValue(
(value) => (
{ devices: { [deviceNumber]: { htmode: { $set: value } } } }
{ devices: { [deviceIndex]: { htmode: { $set: value } } } }
),
)}
@ -193,7 +193,7 @@ function DeviceForm({
onChange={setFormValue(
(value) => (
{ devices: { [deviceNumber]: { channel: { $set: value } } } }
{ devices: { [deviceIndex]: { channel: { $set: value } } } }
),
)}
@ -202,7 +202,7 @@ function DeviceForm({
{hasGuestNetwork && (
<WifiGuestForm
formData={{ id: deviceNumber, ...formData.guest_wifi }}
formData={{ id: deviceIndex, ...formData.guest_wifi }}
formErrors={formErrors.guest_wifi || {}}
setFormValue={setFormValue}

View File

@ -64,7 +64,7 @@ function prepDataToSubmit(formData) {
return formData;
}
function validator(formData) {
export function validator(formData) {
const formErrors = formData.devices.map(
(device) => {
if (!device.enabled) return {};

View File

@ -13,8 +13,8 @@ import { fireEvent, render, wait } from "customTestRender";
import { WebSockets } from "webSockets/WebSockets";
import { mockJSONError } from "testUtils/network";
import { wifiSettingsFixture } from "./__fixtures__/wifiSettings";
import { WiFiSettings } from "../WiFiSettings";
import { wifiSettingsFixture, oneDevice, twoDevices, threeDevices } from "./__fixtures__/wifiSettings";
import { WiFiSettings, validator } from "../WiFiSettings";
describe("<WiFiSettings/>", () => {
let firstRender;
@ -159,4 +159,18 @@ describe("<WiFiSettings/>", () => {
};
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);
});
});

View File

@ -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};