100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
UI bugfix for fields being cleared while on the user creation page (#2385)
Martin Peeters2d7274091491
diff --git a/ui/app/manager/src/pages/page-users.ts b/ui/app/manager/src/pages/page-users.tsindex e571a75e8..a03b0d264 100644--- a/ui/app/manager/src/pages/page-users.ts+++ b/ui/app/manager/src/pages/page-users.ts@@ -1181,7 +1181,13 @@ export class PageUsers extends Page<AppStateKeyed> {if (state.app.page == 'users') { // it seems that the check is necessary herethis.realm = state.app.realm;this.userId = (state.app.params && state.app.params.id) ? state.app.params.id : undefined;- this.creationState = (state.app.params?.type ? {userModel: this.getNewUserModel(state.app.params.type == 'serviceuser')} : undefined);++ // If the user creation parameters have changed from `/regular` to `/serviceuser` (or the other way around)+ // we need to update the creationState to a modified user model.+ const userType: string | undefined = state.app.params?.type;+ if (userType && (this.creationState?.userModel.serviceAccount !== (userType === "serviceuser"))) {+ this.creationState = {userModel: this.getNewUserModel(userType === "serviceuser")};+ }}}diff --git a/ui/app/manager/test/fixtures/pages/users.ts b/ui/app/manager/test/fixtures/pages/users.tsindex 4b400c2f8..746d5fa71 100644--- a/ui/app/manager/test/fixtures/pages/users.ts+++ b/ui/app/manager/test/fixtures/pages/users.ts@@ -10,6 +10,10 @@ export class UsersPage implements BasePage {this.manager.navigateToMenuItem("Users");}+ async gotoUserCreation(realm: string, type: "serviceuser" | "regular") {+ return this.page.goto(this.manager.getAppUrl(realm) + `#/users/new/${type}`);+ }+/*** Get permission locator by name.* @param permission The permission namediff --git a/ui/app/manager/test/users.test.ts b/ui/app/manager/test/users.test.tsindex 944612ad2..9a9a6ec07 100644--- a/ui/app/manager/test/users.test.ts+++ b/ui/app/manager/test/users.test.ts@@ -1,5 +1,6 @@import { expect } from "@openremote/test";import { adminStatePath, test} from "./fixtures/manager";+import permissions from "./fixtures/data/permissions";test.use({ storageState: adminStatePath });@@ -61,6 +62,28 @@ test(`Create service users with tags and search by tag`, async ({ page, manager,await expect(page.getByRole("cell", { name: "serviceuser2", exact: true })).toBeVisible();});+/**+ * @given Logged into the "master" realm as "admin"+ * @and Navigated to the "Users" page+ * @when Trying to create a regular user in the creation window+ * @and You switch to a different tab in your browser, and navigate back later. (simulated using the visibilitychange event)+ * @then The creation window still has the same state, so you can continue creating that user.+ */+test(`Verify browser behavior while creating regular users`, async ({ page, usersPage }) => {+ await usersPage.gotoUserCreation("master", "regular");+ await page.locator("label").filter({ hasText: "Username" }).fill("mycustomusername");+ await page.locator("label").filter({ hasText: "Email" }).fill("[email protected]");+ await usersPage.toHavePermissions();+ await usersPage.toggleUserRoles("Read", "Write");+ await usersPage.toHavePermissions(...permissions);+ await page.evaluate(() => {+ document.dispatchEvent(new Event('visibilitychange'));+ });+ await expect(await page.getByRole('textbox', {name: /username/i }).inputValue()).toBe("mycustomusername");+ await expect(await page.getByRole('textbox', {name: /email/i }).inputValue()).toBe("[email protected]");+ await usersPage.toHavePermissions(...permissions);+});+/*** @given Logged into the "smartcity" realm as "admin"* @when Creating a gateway asset