Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Add back change alarm status field (#3124)

Koen3997a997afe5
diff --git a/ui/app/manager/src/pages/page-alarms.ts b/ui/app/manager/src/pages/page-alarms.ts
index 7268526ec..2375bac10 100644
--- a/ui/app/manager/src/pages/page-alarms.ts
+++ b/ui/app/manager/src/pages/page-alarms.ts
@@ -691,7 +691,16 @@ export class PageAlarms extends Page<AppStateKeyed> {
}}>
<or-translate slot="label" value="alarm.severity"></or-translate>
</or-vaadin-select>
-
+
+ <or-vaadin-select class="alarm-input" ?readonly=${!write}
+ .items=${this._getAddStatusOptions()} value=${alarm.status}
+ @change=${(ev: Event) => {
+ alarm.status = (ev.currentTarget as OrVaadinSelect).value as AlarmStatus;
+ this.onAlarmChanged(ev);
+ }}>
+ <or-translate slot="label" value="alarm.status"></or-translate>
+ </or-vaadin-select>
+
<or-vaadin-select class="alarm-input"
?readonly=${!manager.hasRole("read:users") && !manager.hasRole("read:admin")}
.items=${this._getUsers()} value=${alarm.assigneeId}
diff --git a/ui/app/manager/test/alarms.test.ts b/ui/app/manager/test/alarms.test.ts
new file mode 100644
index 000000000..04619ee3f
--- /dev/null
+++ b/ui/app/manager/test/alarms.test.ts
@@ -0,0 +1,131 @@
+/*
+ * Copyright 2026, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+import { expect } from "@openremote/test";
+import { Alarm, AlarmSeverity, AlarmStatus } from "@openremote/model";
+import { Manager, adminStatePath, test } from "./fixtures/manager.js";
+
+test.use({ storageState: adminStatePath });
+
+/** Alarms seeded through the REST API, removed again after each test. */
+const seededAlarmIds: number[] = [];
+
+/** Persist an alarm via REST and return its id and title, for table lookups and assertions. */
+async function seedAlarm(
+ manager: Manager,
+ { realm = "master", status = AlarmStatus.OPEN, severity = AlarmSeverity.MEDIUM } = {}
+) {
+ const title = `E2E alarm ${Date.now()}`;
+ const config = await manager.adminConfig();
+ const alarm = (await manager.api.AlarmResource.createAlarm({
+ realm,
+ title,
+ content: "seeded by the alarms E2E test",
+ severity,
+ status,
+ } as Alarm, {}, config)).data;
+
+ expect(alarm.id).toBeTruthy();
+ seededAlarmIds.push(alarm.id!);
+ return { id: alarm.id!, title };
+}
+
+test.afterEach(async ({ manager }) => {
+ if (seededAlarmIds.length > 0) {
+ await manager.api.AlarmResource.removeAlarms(seededAlarmIds.splice(0), await manager.adminConfig());
+ }
+ await manager.cleanUp();
+});
+
+/**
+ * @given Logged into the "master" realm as "admin"
+ * @and An open alarm seeded via REST
+ * @when The alarm is opened and its status is changed to "In Progress" and saved
+ * @then The overview row shows the new status, and the change is persisted on the alarm itself
+ */
+test("should change the status of an existing alarm", async ({ manager, alarmsPage }) => {
+ const { id, title } = await seedAlarm(manager);
+
+ await manager.goToRealmStartPage("master");
+ await alarmsPage.goto();
+ await alarmsPage.openAlarmByText(title);
+
+ // the seeded status is shown, and saving is only offered once something changes
+ await expect(alarmsPage.getStatusSelect()).toContainText("Open");
+ await expect(alarmsPage.getSaveButton()).toBeDisabled();
+
+ await alarmsPage.setStatus("In Progress");
+ await expect(alarmsPage.getStatusSelect()).toContainText("In Progress");
+ await expect(alarmsPage.getSaveButton()).toBeEnabled();
+
+ // saving returns to the overview, where the row reflects the new status ...
+ await alarmsPage.getSaveButton().click();
+ await expect(alarmsPage.getTable()).toBeVisible();
+ await expect(alarmsPage.getRowByText(title)).toContainText("In Progress");
+
+ // ... and the alarm itself was updated, not just the table
+ const stored = (await manager.api.AlarmResource.getAlarm(id, await manager.adminConfig())).data;
+ expect(stored.status).toBe(AlarmStatus.IN_PROGRESS);
+});
+
+/**
+ * @given Logged into the "master" realm as "admin"
+ * @and An open alarm seeded via REST
+ * @when The alarm is resolved through the single-alarm view
+ * @then It drops out of the overview, which defaults to showing active alarms only
+ */
+test("should drop a resolved alarm from the default active filter", async ({ manager, alarmsPage }) => {
+ const { title } = await seedAlarm(manager);
+
+ await manager.goToRealmStartPage("master");
+ await alarmsPage.goto();
+ await expect(alarmsPage.getRowByText(title)).toBeVisible();
+
+ await alarmsPage.openAlarmByText(title);
+ await alarmsPage.setStatus("Resolved");
+ await alarmsPage.getSaveButton().click();
+
+ await expect(alarmsPage.getTable()).toBeVisible();
+ await expect(alarmsPage.getRowByText(title)).toHaveCount(0);
+});
+
+test.describe("Role-Based Access Control", () => {
+ // Start from a clean session so we can log in as the low-privilege user rather than a stored admin state.
+ test.use({ storageState: { cookies: [], origins: [] } });
+
+ /**
+ * @given An alarm seeded into "smartcity" and a "smartcity" user with read:alarms only
+ * @when That user opens the alarm
+ * @then The status is shown but cannot be changed, and no alarm can be added
+ */
+ test("should show the status read-only for a user without write permission", async ({ manager, alarmsPage }) => {
+ const { title } = await seedAlarm(manager, { realm: "smartcity" });
+ await manager.provisionUserAndLogin("smartcity", {
+ username: "e2e-alarm-viewer",
+ roles: ["read:alarms"],
+ });
+
+ await alarmsPage.goto();
+ await expect(alarmsPage.getAddButton()).not.toBeVisible();
+
+ await alarmsPage.openAlarmByText(title);
+ await expect(alarmsPage.getStatusSelect()).toContainText("Open");
+ await expect(alarmsPage.getStatusSelect()).toHaveAttribute("readonly", "");
+ });
+});
diff --git a/ui/app/manager/test/fixtures/manager.ts b/ui/app/manager/test/fixtures/manager.ts
index 10db5634b..e42b5470b 100644
--- a/ui/app/manager/test/fixtures/manager.ts
+++ b/ui/app/manager/test/fixtures/manager.ts
@@ -37,7 +37,7 @@ import {
withPage,
} from "@openremote/test";
import { playwrightRequestAdapter } from "./request-adapter";
-import { AssetsPage, InsightsPage, NotificationsPage, RealmsPage, RolesPage, RulesPage, UsersPage } from "./pages";
+import { AlarmsPage, AssetsPage, InsightsPage, NotificationsPage, RealmsPage, RolesPage, RulesPage, UsersPage } from "./pages";
import { AssetViewer } from "../../../../component/or-asset-viewer/test/fixtures";
import { CollapsiblePanel } from "../../../../component/or-components/test/fixtures";
import { MwcInput, MwcMenu } from "../../../../component/or-mwc-components/test/fixtures";
@@ -144,18 +144,36 @@ export class Manager {
/**
* Login as user, waits for username and password fields to be visible.
* @param user Username (admin or other)
+ * @param password Password to log in with, defaulting to the one held for the known test users
*/
- async login(user: Usernames) {
- const username = this.page.getByRole("textbox", { name: "Username or email" });
- const password = this.page.getByRole("textbox", { name: "Password" });
- await username.waitFor();
- if ((await username.isVisible()) && (await password.isVisible())) {
- await username.fill(user);
- await password.fill(users[user].password);
+ async login(user: Usernames | string, password: string = users[user as Usernames]?.password) {
+ const usernameField = this.page.getByRole("textbox", { name: "Username or email" });
+ const passwordField = this.page.getByRole("textbox", { name: "Password" });
+ await usernameField.waitFor();
+ if ((await usernameField.isVisible()) && (await passwordField.isVisible())) {
+ await usernameField.fill(user);
+ await passwordField.fill(password);
await this.page.keyboard.press("Enter");
}
}
+ /**
+ * Create a user with the given client roles in a realm (REST), then log in as them through the UI.
+ *
+ * Used to exercise a page under a specific permission set without disturbing the stored admin session.
+ * Requires a clean `storageState`, otherwise the stored session is used instead of the login form.
+ * @param realm The realm to create the user in
+ * @param user The username and client roles to give them
+ */
+ async provisionUserAndLogin(realm: string, { username, roles }: { username: string; roles?: string[] }) {
+ // set an initial password (== username) so the throwaway user can log in via the UI
+ await this.provisionUser(realm, { username, roles, password: username });
+
+ await this.goToRealmStartPage(realm);
+ await this.login(username, username);
+ await this.page.waitForURL("**/manager/**");
+ }
+
/**
* Logout from the manager.
*
@@ -574,6 +592,7 @@ function withManager<R>(managerPage: Function): TestFixture<R, { page: Page; sha
}
interface PageFixtures {
+ alarmsPage: AlarmsPage;
assetsPage: AssetsPage;
insightsPage: InsightsPage;
notificationsPage: NotificationsPage;
@@ -599,6 +618,7 @@ interface Fixtures extends PageFixtures, ComponentFixtures {
export const test = base.extend<Fixtures>({
manager: async ({ page, baseURL, request }, use) => await use(new Manager(page, baseURL!, request)),
// Pages
+ alarmsPage: withManager(AlarmsPage),
assetsPage: withManager(AssetsPage),
insightsPage: withManager(InsightsPage),
notificationsPage: withManager(NotificationsPage),
diff --git a/ui/app/manager/test/fixtures/pages/alarms.ts b/ui/app/manager/test/fixtures/pages/alarms.ts
new file mode 100644
index 000000000..da0e52875
--- /dev/null
+++ b/ui/app/manager/test/fixtures/pages/alarms.ts
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2026, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+import { BasePage, Locator, Page, Shared, expect } from "@openremote/test";
+import { Manager } from "../manager.js";
+
+/**
+ * Page object for the alarms page (page-alarms).
+ *
+ * The overview is an `or-alarms-table`; clicking a row opens the single-alarm view, whose properties column
+ * (`#prop-panel`) holds the severity, status and assignee `or-vaadin-select`s. Those carry no id, so they are
+ * located by the translation key of their slotted label. Opening one shows its items in a
+ * `vaadin-select-list-box`.
+ */
+export class AlarmsPage implements BasePage {
+ constructor(private readonly page: Page, private readonly shared: Shared, private readonly manager: Manager) {}
+
+ async goto() {
+ // alarms are reached through the bell button in the header, not the drawer menu
+ await this.page.getByTitle("Alarms", { exact: true }).click();
+ await expect(this.getTable()).toBeVisible();
+ }
+
+ // --- Overview table ----------------------------------------------------
+
+ getTable(): Locator {
+ return this.page.locator("or-alarms-table");
+ }
+
+ getRows(): Locator {
+ return this.getTable().locator("tbody tr");
+ }
+
+ /** A table row containing the given text (e.g. an alarm's title). */
+ getRowByText(text: string): Locator {
+ return this.getRows().filter({ hasText: text });
+ }
+
+ getAddButton(): Locator {
+ return this.page.getByRole("button", { name: "Add Alarm" });
+ }
+
+ // --- Single alarm view -------------------------------------------------
+
+ /** The properties column of the single-alarm view, holding the severity/status/assignee selects. */
+ getPropertiesPanel(): Locator {
+ return this.page.locator("#prop-panel");
+ }
+
+ /** A properties-column select, located by the translation key of its slotted label. */
+ private getPropertySelect(labelKey: string): Locator {
+ return this.getPropertiesPanel()
+ .locator("or-vaadin-select")
+ .filter({ has: this.page.locator(`or-translate[value="${labelKey}"]`) });
+ }
+
+ getStatusSelect(): Locator {
+ return this.getPropertySelect("alarm.status");
+ }
+
+ getSeveritySelect(): Locator {
+ return this.getPropertySelect("alarm.severity");
+ }
+
+ getSaveButton(): Locator {
+ return this.page.locator("#savebtn");
+ }
+
+ /** Open the single-alarm view of the (first) row containing the given text. */
+ async openAlarmByText(text: string) {
+ await this.getRowByText(text).first().click();
+ await expect(this.getPropertiesPanel()).toBeVisible();
+ }
+
+ /** Pick a status (e.g. "In Progress") in the single-alarm view. */
+ async setStatus(label: string) {
+ await this.getStatusSelect().click();
+ await this.pickOverlayOption(label);
+ }
+
+ /**
+ * Click the option with the given exact label in the currently-open Vaadin select overlay.
+ *
+ * Vaadin slots the items into a `vaadin-select-list-box` that it projects into an overlay, so the options live
+ * under the list box rather than the select. Only the open one is visible; scoping the lookup to it (and
+ * waiting for it to open and close) avoids clicking an item that is still repositioning under the trigger.
+ */
+ private async pickOverlayOption(label: string) {
+ const listBox = this.page.locator("vaadin-select-list-box:visible");
+ await expect(listBox).toBeVisible();
+ await listBox.getByRole("option", { name: label, exact: true }).click();
+ await expect(listBox).not.toBeVisible();
+ }
+}
diff --git a/ui/app/manager/test/fixtures/pages/index.ts b/ui/app/manager/test/fixtures/pages/index.ts
index 354760748..586e74eec 100644
--- a/ui/app/manager/test/fixtures/pages/index.ts
+++ b/ui/app/manager/test/fixtures/pages/index.ts
@@ -17,6 +17,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+export { AlarmsPage } from "./alarms";
export { AssetsPage } from "./assets";
export { InsightsPage } from "./insights";
export { RealmsPage } from "./realms";
diff --git a/ui/app/manager/test/notifications.test.ts b/ui/app/manager/test/notifications.test.ts
index 9f9215f97..d8ed2fe88 100644
--- a/ui/app/manager/test/notifications.test.ts
+++ b/ui/app/manager/test/notifications.test.ts
@@ -17,7 +17,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import { expect, Page } from "@openremote/test";
+import { expect } from "@openremote/test";
import { Asset, EmailNotificationMessage, Notification, NotificationTargetType } from "@openremote/model";
import { type AxiosRequestConfig } from "axios";
import { Manager, adminStatePath, test } from "./fixtures/manager.js";
@@ -101,25 +101,6 @@ async function createConsoleForUser(manager: Manager, realm: string, userId: str
await linkUsersToAsset(manager, realm, consoleId, [userId], config);
}
-/**
- * Create a throwaway user with the given client roles in the given realm (REST), then log in as them through the UI.
- * Used to exercise the page under a specific permission set without disturbing the stored admin session.
- */
-async function createUserAndLogin(
- manager: Manager,
- page: Page,
- { realm, username, roles }: { realm: string; username: string; roles: string[] },
-) {
- // set an initial password (== username) so the throwaway user can log in via the UI
- await manager.provisionUser(realm, { username, roles, password: username });
-
- await manager.goToRealmStartPage(realm);
- await page.getByRole("textbox", { name: "Username or email" }).fill(username);
- await page.getByRole("textbox", { name: "Password" }).fill(username);
- await page.keyboard.press("Enter");
- await page.waitForURL("**/manager/**");
-}
-
/** Format a Date as the local `YYYY-MM-DDTHH:mm` string the date-range pickers use. */
function pickerValue(d: Date): string {
return new Date(d.getTime() - d.getTimezoneOffset() * 60000).toISOString().slice(0, 16);
@@ -367,9 +348,8 @@ test.describe("Role-Based Access Control", () => {
* @given A "smartcity" user with read:notifications only (no write:admin/write:notifications)
* @then The table is visible but the write-gated "Send new" button is hidden
*/
- test("should hide the send button for a user without write permission", async ({ page, manager, notificationsPage }) => {
- await createUserAndLogin(manager, page, {
- realm: "smartcity",
+ test("should hide the send button for a user without write permission", async ({ manager, notificationsPage }) => {
+ await manager.provisionUserAndLogin("smartcity", {
username: "e2e-readonly",
roles: ["read:notifications"],
});
@@ -382,9 +362,8 @@ test.describe("Role-Based Access Control", () => {
* @given A "smartcity" user with write:notifications but no read:admin/read:users/read:assets
* @then The "Send new" button is shown (write permission) but disabled (no recipient type can be chosen)
*/
- test("should disable the send button for a user who cannot choose any recipient type", async ({ page, manager, notificationsPage }) => {
- await createUserAndLogin(manager, page, {
- realm: "smartcity",
+ test("should disable the send button for a user who cannot choose any recipient type", async ({ manager, notificationsPage }) => {
+ await manager.provisionUserAndLogin("smartcity", {
username: "e2e-sender",
roles: ["read:notifications", "write:notifications"],
});
@@ -399,10 +378,9 @@ test.describe("Role-Based Access Control", () => {
* @when The create dialog is opened for the first time
* @then The target type is forced to Users and the recipient checkbox list is populated
*/
- test("should list user recipients on first open for a user who cannot read assets", async ({ page, manager, notificationsPage }) => {
+ test("should list user recipients on first open for a user who cannot read assets", async ({ manager, notificationsPage }) => {
await ensureRecipient(manager, "smartcity", await manager.adminConfig());
- await createUserAndLogin(manager, page, {
- realm: "smartcity",
+ await manager.provisionUserAndLogin("smartcity", {
username: "e2e-user-sender",
roles: ["read:notifications", "write:notifications", "read:users"],
});
@@ -418,10 +396,9 @@ test.describe("Role-Based Access Control", () => {
* @when That user opens the notification's details dialog
* @then The recipient type is shown, but the recipient's identity is sanitised away (shown as "-")
*/
- test("should hide the recipient identity for a viewer without user/asset read permission", async ({ page, manager, notificationsPage }) => {
+ test("should hide the recipient identity for a viewer without user/asset read permission", async ({ manager, notificationsPage }) => {
const subject = await seedNotification(manager, "smartcity");
- await createUserAndLogin(manager, page, {
- realm: "smartcity",
+ await manager.provisionUserAndLogin("smartcity", {
username: "e2e-viewer",
roles: ["read:notifications"],
});