From 01d4ae74e482613cb14a60d247959bab81c8e609 Mon Sep 17 00:00:00 2001 From: Stepan Henek Date: Thu, 17 Oct 2024 12:11:10 +0200 Subject: [PATCH 1/6] WiFi API update Deprecated option `hwmode=11g/11a` was replaced by `band=2g/5g/6g` --- src/common/WiFiSettings/WiFiForm.js | 24 +++++++++---------- .../__tests__/WiFiSettings.test.js | 6 ++--- .../__tests__/__fixtures__/wifiSettings.js | 22 ++++++++--------- .../__snapshots__/WiFiSettings.test.js.snap | 16 ++++++------- src/common/WiFiSettings/constants.js | 11 +++++---- 5 files changed, 40 insertions(+), 39 deletions(-) diff --git a/src/common/WiFiSettings/WiFiForm.js b/src/common/WiFiSettings/WiFiForm.js index 074f133..40198d9 100644 --- a/src/common/WiFiSettings/WiFiForm.js +++ b/src/common/WiFiSettings/WiFiForm.js @@ -9,7 +9,7 @@ import React from "react"; import PropTypes from "prop-types"; -import { HELP_TEXTS, HTMODES, HWMODES, ENCRYPTIONMODES } from "./constants"; +import { HELP_TEXTS, HTMODES, BANDS, ENCRYPTIONMODES } from "./constants"; import WifiGuestForm from "./WiFiGuestForm"; import WiFiQRCode from "./WiFiQRCode"; import PasswordInput from "../../bootstrap/PasswordInput"; @@ -60,7 +60,7 @@ DeviceForm.propTypes = { SSID: PropTypes.string.isRequired, password: PropTypes.string.isRequired, hidden: PropTypes.bool.isRequired, - hwmode: PropTypes.string.isRequired, + band: PropTypes.string.isRequired, htmode: PropTypes.string.isRequired, channel: PropTypes.string.isRequired, guest_wifi: PropTypes.object.isRequired, @@ -155,11 +155,11 @@ function DeviceForm({ /> { // Get the last item in an array of available HT modes @@ -168,7 +168,7 @@ function DeviceForm({ return { devices: { [deviceIndex]: { - hwmode: { $set: value }, + band: { $set: value }, channel: { $set: "0" }, htmode: { $set: @@ -263,7 +263,7 @@ function getChannelChoices(device) { }; device.available_bands.forEach((availableBand) => { - if (availableBand.hwmode !== device.hwmode) return; + if (availableBand.band !== device.band) return; availableBand.available_channels.forEach((availableChannel) => { channelChoices[availableChannel.number.toString()] = ` @@ -282,7 +282,7 @@ function getHtmodeChoices(device) { const htmodeChoices = {}; device.available_bands.forEach((availableBand) => { - if (availableBand.hwmode !== device.hwmode) return; + if (availableBand.band !== device.band) return; availableBand.available_htmodes.forEach((availableHtmod) => { htmodeChoices[availableHtmod] = HTMODES[availableHtmod]; @@ -291,10 +291,10 @@ function getHtmodeChoices(device) { return htmodeChoices; } -function getHwmodeChoices(device) { +function getBandChoices(device) { return device.available_bands.map((availableBand) => ({ - label: HWMODES[availableBand.hwmode], - value: availableBand.hwmode, + label: BANDS[availableBand.band], + value: availableBand.band, })); } diff --git a/src/common/WiFiSettings/__tests__/WiFiSettings.test.js b/src/common/WiFiSettings/__tests__/WiFiSettings.test.js index f06c152..7afd10a 100644 --- a/src/common/WiFiSettings/__tests__/WiFiSettings.test.js +++ b/src/common/WiFiSettings/__tests__/WiFiSettings.test.js @@ -118,7 +118,7 @@ describe("", () => { guest_wifi: { enabled: false }, hidden: false, htmode: "HT80", - hwmode: "11a", + band: "5g", id: 0, password: "TestPass", encryption: "WPA3", @@ -148,7 +148,7 @@ describe("", () => { guest_wifi: { enabled: false }, hidden: false, htmode: "VHT80", - hwmode: "11g", + band: "2g", id: 0, password: "TestPass", encryption: "WPA3", @@ -185,7 +185,7 @@ describe("", () => { }, hidden: false, htmode: "HT80", - hwmode: "11a", + band: "5g", id: 0, password: "TestPass", encryption: "WPA3", diff --git a/src/common/WiFiSettings/__tests__/__fixtures__/wifiSettings.js b/src/common/WiFiSettings/__tests__/__fixtures__/wifiSettings.js index 7110c42..928e1dd 100644 --- a/src/common/WiFiSettings/__tests__/__fixtures__/wifiSettings.js +++ b/src/common/WiFiSettings/__tests__/__fixtures__/wifiSettings.js @@ -77,7 +77,7 @@ export function wifiSettingsFixture() { "VHT40", "VHT80", ], - hwmode: "11g", + band: "2g", }, { available_channels: [ @@ -215,7 +215,7 @@ export function wifiSettingsFixture() { "VHT40", "VHT80", ], - hwmode: "11a", + band: "5g", }, ], channel: 60, @@ -227,7 +227,7 @@ export function wifiSettingsFixture() { }, hidden: false, htmode: "HT80", - hwmode: "11a", + band: "5g", id: 0, password: "TestPass", encryption: "WPA3", @@ -294,7 +294,7 @@ export function wifiSettingsFixture() { }, ], available_htmodes: ["NOHT", "HT20", "HT40"], - hwmode: "11g", + band: "2g", }, ], channel: 11, @@ -306,7 +306,7 @@ export function wifiSettingsFixture() { }, hidden: false, htmode: "HT40", - hwmode: "11g", + band: "2g", id: 1, password: "TestPass", encryption: "WPA3", @@ -323,7 +323,7 @@ const oneDevice = { guest_wifi: { enabled: false }, hidden: false, htmode: "HT40", - hwmode: "11a", + band: "5g", id: 0, password: "TestPass", encryption: "WPA3", @@ -340,7 +340,7 @@ const twoDevices = { guest_wifi: { enabled: false }, hidden: false, htmode: "HT40", - hwmode: "11a", + band: "5g", id: 0, password: "TestPass", encryption: "WPA3", @@ -352,7 +352,7 @@ const twoDevices = { guest_wifi: { enabled: false }, hidden: false, htmode: "HT40", - hwmode: "11a", + band: "5g", id: 1, password: "TestPass", encryption: "WPA3", @@ -369,7 +369,7 @@ const threeDevices = { guest_wifi: { enabled: false }, hidden: false, htmode: "HT40", - hwmode: "11a", + band: "5g", id: 0, password: "TestPass", encryption: "WPA3", @@ -381,7 +381,7 @@ const threeDevices = { guest_wifi: { enabled: false }, hidden: false, htmode: "HT40", - hwmode: "11a", + band: "5g", id: 1, password: "TestPass", encryption: "WPA3", @@ -393,7 +393,7 @@ const threeDevices = { guest_wifi: { enabled: false }, hidden: false, htmode: "HT40", - hwmode: "11a", + band: "5g", id: 2, password: "", encryption: "WPA3", diff --git a/src/common/WiFiSettings/__tests__/__snapshots__/WiFiSettings.test.js.snap b/src/common/WiFiSettings/__tests__/__snapshots__/WiFiSettings.test.js.snap index 8b14453..d8b0d81 100644 --- a/src/common/WiFiSettings/__tests__/__snapshots__/WiFiSettings.test.js.snap +++ b/src/common/WiFiSettings/__tests__/__snapshots__/WiFiSettings.test.js.snap @@ -562,14 +562,14 @@ exports[` Snapshot one module enabled. 1`] = ` + > + + @@ -580,14 +580,14 @@ exports[` Snapshot one module enabled. 1`] = ` + + diff --git a/src/common/WiFiSettings/constants.js b/src/common/WiFiSettings/constants.js index eff44e6..1b940bc 100644 --- a/src/common/WiFiSettings/constants.js +++ b/src/common/WiFiSettings/constants.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2022 CZ.NIC z.s.p.o. (https://www.nic.cz/) + * Copyright (C) 2019-2024 CZ.NIC z.s.p.o. (https://www.nic.cz/) * * This is free software, licensed under the GNU General Public License v3. * See /LICENSE for more information. @@ -18,9 +18,10 @@ export const HTMODES = { HE80: _("802.11ax - 80 MHz wide channel"), HE160: _("802.11ax - 160 MHz wide channel"), }; -export const HWMODES = { - "11g": "2.4", - "11a": "5", +export const BANDS = { + "2g": "2.4", + "5g": "5", + "6g": "6", }; export const ENCRYPTIONMODES = { WPA3: _("WPA3 only"), @@ -37,7 +38,7 @@ export const HELP_TEXTS = { hidden: _( "If set, network is not visible when scanning for available networks." ), - hwmode: _( + band: _( "The 2.4 GHz band is more widely supported by clients, but tends to have more interference. The 5 GHz band is a newer standard and may not be supported by all your devices. It usually has less interference, but the signal does not carry so well indoors." ), htmode: _( From 30fa79b55e0128c26fc4659be12436bbccb8a05a Mon Sep 17 00:00:00 2001 From: Aleksandr Gumroian Date: Thu, 5 Dec 2024 09:36:47 +0100 Subject: [PATCH 2/6] !fixup WiFi API update --- src/common/WiFiSettings/WiFiForm.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/common/WiFiSettings/WiFiForm.js b/src/common/WiFiSettings/WiFiForm.js index 40198d9..9475f57 100644 --- a/src/common/WiFiSettings/WiFiForm.js +++ b/src/common/WiFiSettings/WiFiForm.js @@ -156,25 +156,25 @@ function DeviceForm({ { - // Get the last item in an array of available HT modes - const [best2] = bnds[0].available_htmodes.slice(-1); - const [best5] = bnds[1].available_htmodes.slice(-1); + // Find the selected band + const selectedBand = bnds.find( + (band) => band.band === value + ); + // Get the last item in the available HT modes for the selected band + const bestHtmode = + selectedBand.available_htmodes.slice(-1)[0]; return { devices: { [deviceIndex]: { band: { $set: value }, channel: { $set: "0" }, - htmode: { - $set: - // Set HT mode depending on checked frequency - value === "11a" ? best5 : best2, - }, + htmode: { $set: bestHtmode }, }, }, }; @@ -293,7 +293,7 @@ function getHtmodeChoices(device) { function getBandChoices(device) { return device.available_bands.map((availableBand) => ({ - label: BANDS[availableBand.band], + label: BANDS[availableBand.band] + _(" GHz"), value: availableBand.band, })); } From a7f36be30cd92b92e945904887de4ea2c7daa8c8 Mon Sep 17 00:00:00 2001 From: Stepan Henek Date: Thu, 5 Dec 2024 09:39:17 +0100 Subject: [PATCH 3/6] fixup! !fixup WiFi API update --- src/common/WiFiSettings/WiFiForm.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/WiFiSettings/WiFiForm.js b/src/common/WiFiSettings/WiFiForm.js index 9475f57..1be0c6e 100644 --- a/src/common/WiFiSettings/WiFiForm.js +++ b/src/common/WiFiSettings/WiFiForm.js @@ -293,7 +293,7 @@ function getHtmodeChoices(device) { function getBandChoices(device) { return device.available_bands.map((availableBand) => ({ - label: BANDS[availableBand.band] + _(" GHz"), + label: BANDS[availableBand.band] + " GHz", value: availableBand.band, })); } From 10c328f15fb287652f96efeccd06bcfacfdc7d6c Mon Sep 17 00:00:00 2001 From: Aleksandr Gumroian Date: Thu, 5 Dec 2024 17:47:11 +0100 Subject: [PATCH 4/6] fixup! fixup! !fixup WiFi API update --- src/common/WiFiSettings/WiFiForm.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/WiFiSettings/WiFiForm.js b/src/common/WiFiSettings/WiFiForm.js index 1be0c6e..8d821e6 100644 --- a/src/common/WiFiSettings/WiFiForm.js +++ b/src/common/WiFiSettings/WiFiForm.js @@ -293,7 +293,7 @@ function getHtmodeChoices(device) { function getBandChoices(device) { return device.available_bands.map((availableBand) => ({ - label: BANDS[availableBand.band] + " GHz", + label: `${BANDS[availableBand.band]} GHz`, value: availableBand.band, })); } From 25181db628622d4bc8149f7cfc3954f1c30156ac Mon Sep 17 00:00:00 2001 From: Aleksandr Gumroian Date: Thu, 5 Dec 2024 17:48:10 +0100 Subject: [PATCH 5/6] Fix tests --- src/common/WiFiSettings/__tests__/WiFiSettings.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/WiFiSettings/__tests__/WiFiSettings.test.js b/src/common/WiFiSettings/__tests__/WiFiSettings.test.js index 7afd10a..9bd4471 100644 --- a/src/common/WiFiSettings/__tests__/WiFiSettings.test.js +++ b/src/common/WiFiSettings/__tests__/WiFiSettings.test.js @@ -77,7 +77,7 @@ describe("", () => { it("Snapshot 2.4 GHz", () => { fireEvent.click(getByText("Wi-Fi 1")); const enabledRender = asFragment(); - fireEvent.click(getAllByText("2.4")[0]); + fireEvent.click(getAllByText(/2.4/)[0]); expect(diffSnapshot(enabledRender, asFragment())).toMatchSnapshot(); }); @@ -135,7 +135,7 @@ describe("", () => { it("Post form: 2.4 GHz", () => { fireEvent.click(getByText("Wi-Fi 1")); - fireEvent.click(getAllByText("2.4")[0]); + fireEvent.click(getAllByText(/2.4/)[0]); fireEvent.click(getByText("Save")); expect(mockAxios.post).toBeCalled(); From 605f61bdd68f7a701572710c5a4c7d593846cd11 Mon Sep 17 00:00:00 2001 From: Aleksandr Gumroian Date: Thu, 5 Dec 2024 17:48:19 +0100 Subject: [PATCH 6/6] Update Snapshots --- .../__tests__/__snapshots__/WiFiSettings.test.js.snap | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/WiFiSettings/__tests__/__snapshots__/WiFiSettings.test.js.snap b/src/common/WiFiSettings/__tests__/__snapshots__/WiFiSettings.test.js.snap index d8b0d81..72f0225 100644 --- a/src/common/WiFiSettings/__tests__/__snapshots__/WiFiSettings.test.js.snap +++ b/src/common/WiFiSettings/__tests__/__snapshots__/WiFiSettings.test.js.snap @@ -555,7 +555,7 @@ exports[` Snapshot one module enabled. 1`] = ` + class="d-block" + for="6" + > -+ GHz ++ Band + +
Snapshot one module enabled. 1`] = ` + class="form-check-label" + for="band-0-0" + > -+ 2.4 ++ 2.4 GHz + +
+
Snapshot one module enabled. 1`] = ` + class="form-check-label" + for="band-0-1" + > -+ 5 ++ 5 GHz + +
+