Skip to content

armgit / core

Public Imported from GitHub
0

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

6.9 KB
Raw Blame
/*
 * Copyright 2026, OpenRemote Inc.
 *
 * 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 <https://www.gnu.org/licenses/>.
 *
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
import { expect } from "@openremote/test";
import { adminStatePath, test } from "./fixtures/manager";

test.use({ storageState: adminStatePath });

/**
 * @given Logged into the "smartcity" realm as "admin"
 * @and Navigated to the "Users" page
 * @when Creating multiple regular users with different tags
 * @and Searching by tag in the regular user table
 * @then Only the user with the matching tag should be visible
 */
test(`Create regular users with tags and search by tag`, async ({ page, manager, usersPage }) => {
  await manager.goToRealmStartPage("master");
  await manager.switchToRealmByRealmPicker("smartcity");
  await manager.navigateToMenuItem("Users");
  await usersPage.addUser("user1", "password123", "Company1");
  await usersPage.addUser("user2", "password123", "Company2");
  await expect(page.getByRole("cell", { name: "user1", exact: true })).toBeVisible();
  await expect(page.getByRole("cell", { name: "user2", exact: true })).toBeVisible();

  await usersPage.searchRegularUsers("Company1");
  await expect(page.getByRole("cell", { name: "user1", exact: true })).toBeVisible();
  await expect(page.getByRole("cell", { name: "user2", exact: true })).not.toBeVisible();

  await usersPage.searchRegularUsers("Company2");
  await expect(page.getByRole("cell", { name: "user1", exact: true })).not.toBeVisible();
  await expect(page.getByRole("cell", { name: "user2", exact: true })).toBeVisible();

  await usersPage.searchRegularUsers("");
  await expect(page.getByRole("cell", { name: "user1", exact: true })).toBeVisible();
  await expect(page.getByRole("cell", { name: "user2", exact: true })).toBeVisible();
});

/**
 * @given Logged into the "smartcity" realm as "admin"
 * @and Navigated to the "Users" page
 * @when Creating multiple service users with different tags
 * @and Searching by tag in the service user table
 * @then Only the service user with the matching tag should be visible
 */
test(`Create service users with tags and search by tag`, async ({ page, manager, usersPage }) => {
  await manager.goToRealmStartPage("master");
  await manager.switchToRealmByRealmPicker("smartcity");
  await manager.navigateToMenuItem("Users");
  await usersPage.addServiceUser("serviceuser1", "api");
  await usersPage.addServiceUser("serviceuser2", "integration");
  await expect(page.getByRole("cell", { name: "serviceuser1", exact: true })).toBeVisible();
  await expect(page.getByRole("cell", { name: "serviceuser2", exact: true })).toBeVisible();

  await usersPage.searchServiceUsers("api");
  await expect(page.getByRole("cell", { name: "serviceuser1", exact: true })).toBeVisible();
  await expect(page.getByRole("cell", { name: "serviceuser2", exact: true })).not.toBeVisible();

  await usersPage.searchServiceUsers("integration");
  await expect(page.getByRole("cell", { name: "serviceuser1", exact: true })).not.toBeVisible();
  await expect(page.getByRole("cell", { name: "serviceuser2", exact: true })).toBeVisible();

  await usersPage.searchServiceUsers("");
  await expect(page.getByRole("cell", { name: "serviceuser1", exact: true })).toBeVisible();
  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.getByLabel("Username").fill("mycustomusername");
  await page.getByLabel("Email").fill("[email protected]");
  await usersPage.toHaveRoles();
  await usersPage.toggleCompositeRoles("Read", "Write");
  await usersPage.toHaveAllRoles();
  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.toHaveAllRoles();
});

/**
 * @given Logged into the "smartcity" realm as "admin"
 * @when Creating a gateway asset
 * @and Waiting for the clientId to be populated
 * @and Navigating to the gateway service user
 * @then All fields should be visible but read-only and no save button should be available
 */
test(`Verify gateway service user is read-only`, async ({ page, manager, usersPage, assetsPage }) => {
  await manager.goToRealmStartPage("master");
  await manager.switchToRealmByRealmPicker("smartcity");
  await manager.navigateToTab("Assets");
  await assetsPage.addAsset("Gateway Asset", "TestGateway");
  await page.waitForURL("**/assets/**");
  const clientIdInput = page.locator(`#field-clientId input`);
  await expect(clientIdInput).not.toHaveValue("", { timeout: 15000 });
  const clientId = await clientIdInput.inputValue();
  expect(clientId).toBeTruthy();
  expect(clientId).toContain("gateway-");
  await manager.navigateToMenuItem("Users");
  const gatewayUsername = `${clientId}`;
  await usersPage.searchServiceUsers(gatewayUsername);
  await expect(page.getByRole("cell", { name: gatewayUsername, exact: true })).toBeVisible();
  await page.getByRole("cell", { name: gatewayUsername, exact: true }).click();
  const usernameInput = page.locator('[id*="username"]');
  await expect(usernameInput).toHaveAttribute("readonly");
  const tagInput = page.getByLabel("Tag");
  await expect(tagInput).toHaveAttribute("readonly");
  const activeCheckbox = page.getByRole("checkbox", { name: "Active" });
  await expect(activeCheckbox).toHaveAttribute("aria-readonly");
  const realmRolesSelect = page.getByLabel("Realm roles");
  await expect(realmRolesSelect).toHaveAttribute("readonly");
  const managerRolesSelect = page.getByLabel("Manager roles");
  await expect(managerRolesSelect).toHaveAttribute("readonly");
  const saveButton = page.getByRole("button", { name: "Save" });
  await expect(saveButton).toBeDisabled();
});