Skip to content

armgit / core

Public Imported from GitHub
0

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

4.1 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 as setup, userStatePath } from "./fixtures/manager";
import { users } from "./fixtures/data/users";

const { admin, smartcity } = users;

// Must always run tests in setup sequentially to ensure the "Wait for manager to be healthy"
// setup test runs first
setup.describe.configure({ mode: "serial" });

setup(`Wait for the manager to be healthy`, async ({ manager }) => {
  await expect
    .poll(
      async () => {
        const noop = () => null;
        const token = await manager.getAccessToken("master", "admin", "secret").catch(noop);
        const response = await manager.api.StatusResource.getHealthStatus({
          headers: { Authorization: "Bearer " + token },
        }).catch(noop);
        return response?.status;
      },
      {
        message: "Manager to become healthy",
        intervals: [5_000, 1_000, 2_000, 5_000],
        timeout: 60_000,
      }
    )
    .toBe(200);
  await manager.resetLocale("master", "admin", admin.password);
});

setup(`Login as "admin" user`, async ({ page, manager, context }) => {
  await manager.goToRealmStartPage("master");
  await manager.login(admin.username);
  await page.waitForURL("**/manager/**");
  await page.waitForTimeout(2000);
  await context.storageState({ path: adminStatePath });
});

setup.describe(async () => {
  setup.use({ storageState: adminStatePath });

  /**
   * @given Logged into the "master" realm as "admin"
   * @when Navigating to the "Realms" page
   * @and Adding a new realm "smartcity"
   * @and Selecting the "smartcity" realm
   * @then The realm picker should show "smartcity"
   */
  setup(`Add realm called "smartcity"`, async ({ page, manager, realmsPage }) => {
    await manager.goToRealmStartPage("master");
    await realmsPage.goto();
    await realmsPage.addRealm("smartcity");
    await manager.switchToRealmByRealmPicker("smartcity");
    await expect(page.locator("#desktop-right #realm-picker")).toContainText("smartcity");
  });

  /**
   * @given The "smartcity" realm is set up
   * @when Logged into the "master" realm as "admin"
   * @and Switched to the "smartcity" realm
   * @and Navigated to the "Users" page
   * @and Added a new user "smartcity"
   * @then The user "smartcity" should be visible
   * @and All default roles should be selected
   */
  setup(`Add user called "smartcity"`, async ({ page, manager, usersPage }) => {
    const { username, password } = smartcity;
    await manager.setup("smartcity");
    await manager.goToRealmStartPage("master");
    await manager.switchToRealmByRealmPicker("smartcity");
    await manager.navigateToMenuItem("Users");
    await usersPage.addUser(username, password);
    await expect(page.getByRole("cell", { name: "smartcity" })).toHaveCount(1);
    await page.getByRole("cell", { name: "smartcity" }).click();
    await usersPage.toHaveAllRoles();
  });
});

setup(`Login as "smartcity" user`, async ({ page, manager, context }) => {
  await manager.resetLocale("smartcity", "smartcity", smartcity.password);
  await manager.goToRealmStartPage("smartcity");
  await manager.login("smartcity");
  await page.waitForURL("**/manager/**");
  await context.storageState({ path: userStatePath });
  await expect(page.getByRole("menuitem", { name: "More options" })).toBeVisible();
  await expect(page.locator("#realm-picker")).not.toBeVisible();
});