mirror of
https://gitlab.nic.cz/turris/reforis/foris-js.git
synced 2024-12-27 00:31:35 +01:00
Merge branch 'dev' into 'master'
Dev See merge request turris/reforis/foris-js!129
This commit is contained in:
commit
03cf73be6e
|
@ -105,6 +105,7 @@ function DeviceForm({
|
||||||
label="SSID"
|
label="SSID"
|
||||||
value={formData.SSID}
|
value={formData.SSID}
|
||||||
error={formErrors.SSID || null}
|
error={formErrors.SSID || null}
|
||||||
|
helpText={HELP_TEXTS.ssid}
|
||||||
required
|
required
|
||||||
onChange={setFormValue((value) => ({
|
onChange={setFormValue((value) => ({
|
||||||
devices: {
|
devices: {
|
||||||
|
|
|
@ -57,6 +57,7 @@ export default function WifiGuestForm({
|
||||||
label="SSID"
|
label="SSID"
|
||||||
value={formData.SSID}
|
value={formData.SSID}
|
||||||
error={formErrors.SSID}
|
error={formErrors.SSID}
|
||||||
|
helpText={HELP_TEXTS.ssid}
|
||||||
onChange={setFormValue((value) => ({
|
onChange={setFormValue((value) => ({
|
||||||
devices: {
|
devices: {
|
||||||
[formData.id]: {
|
[formData.id]: {
|
||||||
|
|
|
@ -63,6 +63,12 @@ function prepDataToSubmit(formData) {
|
||||||
return formData;
|
return formData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function byteCount(string) {
|
||||||
|
const buffer = Buffer.from(string, "utf-8");
|
||||||
|
const count = buffer.byteLength;
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
export function validator(formData) {
|
export function validator(formData) {
|
||||||
const formErrors = formData.devices.map((device) => {
|
const formErrors = formData.devices.map((device) => {
|
||||||
if (!device.enabled) return {};
|
if (!device.enabled) return {};
|
||||||
|
@ -71,6 +77,8 @@ export function validator(formData) {
|
||||||
if (device.SSID.length > 32)
|
if (device.SSID.length > 32)
|
||||||
errors.SSID = _("SSID can't be longer than 32 symbols");
|
errors.SSID = _("SSID can't be longer than 32 symbols");
|
||||||
if (device.SSID.length === 0) errors.SSID = _("SSID can't be empty");
|
if (device.SSID.length === 0) errors.SSID = _("SSID can't be empty");
|
||||||
|
if (byteCount(device.SSID) > 32)
|
||||||
|
errors.SSID = _("SSID can't be longer than 32 bytes");
|
||||||
|
|
||||||
if (device.password.length < 8)
|
if (device.password.length < 8)
|
||||||
errors.password = _("Password must contain at least 8 symbols");
|
errors.password = _("Password must contain at least 8 symbols");
|
||||||
|
@ -82,6 +90,8 @@ export function validator(formData) {
|
||||||
guest_wifi_errors.SSID = _("SSID can't be longer than 32 symbols");
|
guest_wifi_errors.SSID = _("SSID can't be longer than 32 symbols");
|
||||||
if (device.guest_wifi.SSID.length === 0)
|
if (device.guest_wifi.SSID.length === 0)
|
||||||
guest_wifi_errors.SSID = _("SSID can't be empty");
|
guest_wifi_errors.SSID = _("SSID can't be empty");
|
||||||
|
if (byteCount(device.guest_wifi.SSID) > 32)
|
||||||
|
guest_wifi_errors.SSID = _("SSID can't be longer than 32 bytes");
|
||||||
|
|
||||||
if (device.guest_wifi.password.length < 8)
|
if (device.guest_wifi.password.length < 8)
|
||||||
guest_wifi_errors.password = _(
|
guest_wifi_errors.password = _(
|
||||||
|
|
|
@ -19,7 +19,7 @@ import {
|
||||||
twoDevices,
|
twoDevices,
|
||||||
threeDevices,
|
threeDevices,
|
||||||
} from "./__fixtures__/wifiSettings";
|
} from "./__fixtures__/wifiSettings";
|
||||||
import { WiFiSettings, validator } from "../WiFiSettings";
|
import { WiFiSettings, validator, byteCount } from "../WiFiSettings";
|
||||||
|
|
||||||
describe("<WiFiSettings/>", () => {
|
describe("<WiFiSettings/>", () => {
|
||||||
let firstRender;
|
let firstRender;
|
||||||
|
@ -213,4 +213,8 @@ describe("<WiFiSettings/>", () => {
|
||||||
];
|
];
|
||||||
expect(validator(threeDevices)).toEqual(threeDevicesFormErrors);
|
expect(validator(threeDevices)).toEqual(threeDevicesFormErrors);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("ByteCount function", () => {
|
||||||
|
expect(byteCount("abc")).toEqual(3);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,7 +5,7 @@ exports[`<WiFiSettings/> Snapshot 2.4 GHz 1`] = `
|
||||||
- First value
|
- First value
|
||||||
+ Second value
|
+ Second value
|
||||||
|
|
||||||
@@ -245,207 +245,95 @@
|
@@ -250,207 +250,95 @@
|
||||||
value=\\"0\\"
|
value=\\"0\\"
|
||||||
>
|
>
|
||||||
auto
|
auto
|
||||||
|
@ -336,7 +336,7 @@ exports[`<WiFiSettings/> Snapshot guest network. 1`] = `
|
||||||
- First value
|
- First value
|
||||||
+ Second value
|
+ Second value
|
||||||
|
|
||||||
@@ -474,10 +474,89 @@
|
@@ -479,10 +479,94 @@
|
||||||
Parameters of the guest network can be set in the Guest network tab.
|
Parameters of the guest network can be set in the Guest network tab.
|
||||||
|
|
||||||
</small>
|
</small>
|
||||||
|
@ -375,6 +375,11 @@ exports[`<WiFiSettings/> Snapshot guest network. 1`] = `
|
||||||
+ </button>
|
+ </button>
|
||||||
+ </div>
|
+ </div>
|
||||||
+ </div>
|
+ </div>
|
||||||
|
+ <small
|
||||||
|
+ class=\\"form-text text-muted\\"
|
||||||
|
+ >
|
||||||
|
+ SSID which contains non-standard characters could cause problems on some devices.
|
||||||
|
+ </small>
|
||||||
+ </div>
|
+ </div>
|
||||||
+ <div
|
+ <div
|
||||||
+ class=\\"form-group\\"
|
+ class=\\"form-group\\"
|
||||||
|
@ -426,7 +431,7 @@ exports[`<WiFiSettings/> Snapshot guest network. 1`] = `
|
||||||
class=\\"form-group switch\\"
|
class=\\"form-group switch\\"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
@@ -501,10 +580,11 @@
|
@@ -506,10 +590,11 @@
|
||||||
<div
|
<div
|
||||||
class=\\"text-right\\"
|
class=\\"text-right\\"
|
||||||
>
|
>
|
||||||
|
@ -445,7 +450,7 @@ exports[`<WiFiSettings/> Snapshot one module enabled. 1`] = `
|
||||||
- First value
|
- First value
|
||||||
+ Second value
|
+ Second value
|
||||||
|
|
||||||
@@ -22,10 +22,462 @@
|
@@ -22,10 +22,467 @@
|
||||||
Wi-Fi 1
|
Wi-Fi 1
|
||||||
</h2>
|
</h2>
|
||||||
</label>
|
</label>
|
||||||
|
@ -485,6 +490,11 @@ exports[`<WiFiSettings/> Snapshot one module enabled. 1`] = `
|
||||||
+ </button>
|
+ </button>
|
||||||
+ </div>
|
+ </div>
|
||||||
+ </div>
|
+ </div>
|
||||||
|
+ <small
|
||||||
|
+ class=\\"form-text text-muted\\"
|
||||||
|
+ >
|
||||||
|
+ SSID which contains non-standard characters could cause problems on some devices.
|
||||||
|
+ </small>
|
||||||
+ </div>
|
+ </div>
|
||||||
+ <div
|
+ <div
|
||||||
+ class=\\"form-group\\"
|
+ class=\\"form-group\\"
|
||||||
|
|
|
@ -19,6 +19,9 @@ export const HWMODES = {
|
||||||
"11a": "5",
|
"11a": "5",
|
||||||
};
|
};
|
||||||
export const HELP_TEXTS = {
|
export const HELP_TEXTS = {
|
||||||
|
ssid: _(
|
||||||
|
`SSID which contains non-standard characters could cause problems on some devices.`
|
||||||
|
),
|
||||||
password: _(`
|
password: _(`
|
||||||
WPA2 pre-shared key, that is required to connect to the network.
|
WPA2 pre-shared key, that is required to connect to the network.
|
||||||
`),
|
`),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user