Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

2.5 KB
Raw Blame
import { expect, test } from "./coverage-fixture";
import { LoginPage } from "./pages/login.page";
import { ProfileFormPage } from "./pages/profile-form.page";
import { SettingsPage } from "./pages/settings.page";

test("settings happy path: user can save notification preferences and keep them after reload and re-login", async ({
  page,
}) => {
  test.setTimeout(90000);

  const loginPage = new LoginPage(page);
  const settingsPage = new SettingsPage(page);

  await loginPage.loginAsSeededUser("smokeSettings");
  await settingsPage.open();

  const alertsSwitch = settingsPage.getAlertsSwitch();
  // Assert the attribute exists before reading it — defaulting to "false"
  // would silently pass a regression that removes `aria-checked` entirely.
  await expect(alertsSwitch).toHaveAttribute("aria-checked", /^(true|false)$/);
  const initialState = await alertsSwitch.getAttribute("aria-checked");
  const expectedState = initialState === "true" ? "false" : "true";

  await alertsSwitch.click();
  await settingsPage.savePreferences();
  await expect(alertsSwitch).toHaveAttribute("aria-checked", expectedState);

  await page.reload();
  await settingsPage.open();
  await expect(settingsPage.getAlertsSwitch()).toHaveAttribute(
    "aria-checked",
    expectedState,
  );

  await page.getByTestId("profile-popout-menu-trigger").click();
  await page.getByRole("button", { name: "Log out" }).click();
  await expect(page).toHaveURL(/\/login/);

  await loginPage.loginAsSeededUser("smokeSettings");
  await settingsPage.open();
  await expect(settingsPage.getAlertsSwitch()).toHaveAttribute(
    "aria-checked",
    expectedState,
  );
});

test("settings happy path: user can edit display name and keep it after refresh", async ({
  page,
}) => {
  test.setTimeout(90000);

  const loginPage = new LoginPage(page);
  const profileFormPage = new ProfileFormPage(page);
  const updatedDisplayName = `E2E Display ${Date.now()}`;

  await loginPage.loginAsSeededUser("smokeSettings");
  await profileFormPage.open();
  await expect(await profileFormPage.isLoaded()).toBe(true);

  await profileFormPage.setDisplayName(updatedDisplayName);
  await profileFormPage.saveChanges();

  await expect
    .poll(() => profileFormPage.getDisplayName(), { timeout: 15000 })
    .toBe(updatedDisplayName);

  await page.reload();
  await expect(await profileFormPage.isLoaded()).toBe(true);
  await expect
    .poll(() => profileFormPage.getDisplayName(), { timeout: 15000 })
    .toBe(updatedDisplayName);
});