element-web-Github/playwright/e2e/settings/account-user-settings-tab.spec.ts
Michael Telatynski c05c429803
Absorb the matrix-react-sdk repository (#28192)
Co-authored-by: github-merge-queue <118344674+github-merge-queue@users.noreply.github.com>
Co-authored-by: github-merge-queue <github-merge-queue@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Florian Duros <florian.duros@ormaz.fr>
Co-authored-by: Kim Brose <kim.brose@nordeck.net>
Co-authored-by: Florian Duros <florianduros@element.io>
Co-authored-by: R Midhun Suresh <hi@midhun.dev>
Co-authored-by: dbkr <986903+dbkr@users.noreply.github.com>
Co-authored-by: ElementRobot <releases@riot.im>
Co-authored-by: dbkr <dbkr@users.noreply.github.com>
Co-authored-by: David Baker <dbkr@users.noreply.github.com>
Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
Co-authored-by: David Langley <davidl@element.io>
Co-authored-by: Michael Weimann <michaelw@matrix.org>
Co-authored-by: Timshel <Timshel@users.noreply.github.com>
Co-authored-by: Sahil Silare <32628578+sahil9001@users.noreply.github.com>
Co-authored-by: Will Hunt <will@half-shot.uk>
Co-authored-by: Hubert Chathi <hubert@uhoreg.ca>
Co-authored-by: Andrew Ferrazzutti <andrewf@element.io>
Co-authored-by: Robin <robin@robin.town>
Co-authored-by: Tulir Asokan <tulir@maunium.net>
2024-10-16 13:31:55 +01:00

144 lines
6.6 KiB
TypeScript

/*
Copyright 2024 New Vector Ltd.
Copyright 2023 Suguru Hirahara
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
Please see LICENSE files in the repository root for full details.
*/
import { test, expect } from "../../element-web-test";
const USER_NAME = "Bob";
const USER_NAME_NEW = "Alice";
test.describe("Account user settings tab", () => {
test.use({
displayName: USER_NAME,
config: {
default_country_code: "US", // For checking the international country calling code
},
uut: async ({ app, user }, use) => {
const locator = await app.settings.openUserSettings("Account");
await use(locator);
},
});
test("should be rendered properly", async ({ uut, user }) => {
await expect(uut).toMatchScreenshot("account.png");
// Assert that the top heading is rendered
await expect(uut.getByRole("heading", { name: "Account", exact: true })).toBeVisible();
const profile = uut.locator(".mx_UserProfileSettings_profile");
await profile.scrollIntoViewIfNeeded();
await expect(profile.getByRole("textbox", { name: "Display Name" })).toHaveValue(USER_NAME);
// Assert that a userId is rendered
expect(uut.getByLabel("Username")).toHaveText(user.userId);
// Wait until spinners disappear
await expect(uut.getByTestId("accountSection").locator(".mx_Spinner")).not.toBeVisible();
await expect(uut.getByTestId("discoverySection").locator(".mx_Spinner")).not.toBeVisible();
const accountSection = uut.getByTestId("accountSection");
accountSection.scrollIntoViewIfNeeded();
// Assert that input areas for changing a password exists
await expect(accountSection.getByLabel("Current password")).toBeVisible();
await expect(accountSection.getByLabel("New Password")).toBeVisible();
await expect(accountSection.getByLabel("Confirm password")).toBeVisible();
// Check email addresses area
const emailAddresses = uut.getByTestId("mx_AccountEmailAddresses");
await emailAddresses.scrollIntoViewIfNeeded();
// Assert that an input area for a new email address is rendered
await expect(emailAddresses.getByRole("textbox", { name: "Email Address" })).toBeVisible();
// Assert the add button is visible
await expect(emailAddresses.getByRole("button", { name: "Add" })).toBeVisible();
// Check phone numbers area
const phoneNumbers = uut.getByTestId("mx_AccountPhoneNumbers");
await phoneNumbers.scrollIntoViewIfNeeded();
// Assert that an input area for a new phone number is rendered
await expect(phoneNumbers.getByRole("textbox", { name: "Phone Number" })).toBeVisible();
// Assert that the add button is rendered
await expect(phoneNumbers.getByRole("button", { name: "Add" })).toBeVisible();
// Assert the account deactivation button is displayed
const accountManagementSection = uut.getByTestId("account-management-section");
await accountManagementSection.scrollIntoViewIfNeeded();
await expect(accountManagementSection.getByRole("button", { name: "Deactivate Account" })).toHaveClass(
/mx_AccessibleButton_kind_danger/,
);
});
test("should respond to small screen sizes", async ({ page, uut }) => {
await page.setViewportSize({ width: 700, height: 600 });
await expect(uut).toMatchScreenshot("account-smallscreen.png");
});
test("should show tooltips on narrow screen", async ({ page, uut }) => {
await page.setViewportSize({ width: 700, height: 600 });
await page.getByRole("tab", { name: "Account" }).hover();
await expect(page.getByRole("tooltip")).toHaveText("Account");
});
test("should support adding and removing a profile picture", async ({ uut, page }) => {
const profileSettings = uut.locator(".mx_UserProfileSettings");
// Upload a picture
await profileSettings.getByAltText("Upload").setInputFiles("playwright/sample-files/riot.png");
// Image should be visible
await expect(profileSettings.locator(".mx_AvatarSetting_avatar img")).toBeVisible();
// Open the menu & click remove
await profileSettings.getByRole("button", { name: "Profile Picture" }).click();
await page.getByRole("menuitem", { name: "Remove" }).click();
// Assert that the image disappeared
await expect(profileSettings.locator(".mx_AvatarSetting_avatar img")).not.toBeVisible();
});
test("should set a country calling code based on default_country_code", async ({ uut }) => {
// Check phone numbers area
const accountPhoneNumbers = uut.getByTestId("mx_AccountPhoneNumbers");
await accountPhoneNumbers.scrollIntoViewIfNeeded();
// Assert that an input area for a new phone number is rendered
await expect(accountPhoneNumbers.getByRole("textbox", { name: "Phone Number" })).toBeVisible();
// Check a new phone number dropdown menu
const dropdown = accountPhoneNumbers.locator(".mx_PhoneNumbers_country");
await dropdown.scrollIntoViewIfNeeded();
// Assert that the country calling code of the United States is visible
await expect(dropdown.getByText(/\+1/)).toBeVisible();
// Click the button to display the dropdown menu
await dropdown.getByRole("button", { name: "Country Dropdown" }).click();
// Assert that the option for calling code of the United Kingdom is visible
await expect(dropdown.getByRole("option", { name: /United Kingdom/ })).toBeVisible();
// Click again to close the dropdown
await dropdown.getByRole("button", { name: "Country Dropdown" }).click();
// Assert that the default value is rendered again
await expect(dropdown.getByText(/\+1/)).toBeVisible();
await expect(accountPhoneNumbers.getByRole("button", { name: "Add" })).toBeVisible();
});
test("should support changing a display name", async ({ uut, page, app }) => {
// Change the diaplay name to USER_NAME_NEW
const displayNameInput = uut
.locator(".mx_SettingsTab .mx_UserProfileSettings")
.getByRole("textbox", { name: "Display Name" });
await displayNameInput.fill(USER_NAME_NEW);
await displayNameInput.press("Enter");
await app.closeDialog();
// Assert the avatar's initial characters are set
await expect(page.locator(".mx_UserMenu .mx_BaseAvatar").getByText("A")).toBeVisible(); // Alice
await expect(page.locator(".mx_RoomView_wrapper .mx_BaseAvatar").getByText("A")).toBeVisible(); // Alice
});
});