2023-11-29 21:50:13 +08:00
|
|
|
/*
|
|
|
|
Copyright 2023 Suguru Hirahara
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { test, expect } from "../../element-web-test";
|
|
|
|
|
|
|
|
const USER_NAME = "Bob";
|
|
|
|
const USER_NAME_NEW = "Alice";
|
|
|
|
|
2024-08-07 01:05:08 +08:00
|
|
|
test.describe("Account user settings tab", () => {
|
2023-11-29 21:50:13 +08:00
|
|
|
test.use({
|
|
|
|
displayName: USER_NAME,
|
|
|
|
config: {
|
|
|
|
default_country_code: "US", // For checking the international country calling code
|
|
|
|
},
|
|
|
|
uut: async ({ app, user }, use) => {
|
2024-08-07 01:05:08 +08:00
|
|
|
const locator = await app.settings.openUserSettings("Account");
|
2023-11-29 21:50:13 +08:00
|
|
|
await use(locator);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2024-06-06 21:56:38 +08:00
|
|
|
test("should be rendered properly", async ({ uut, user }) => {
|
2024-08-07 01:05:08 +08:00
|
|
|
await expect(uut).toMatchScreenshot("account.png");
|
2023-11-29 21:50:13 +08:00
|
|
|
|
|
|
|
// Assert that the top heading is rendered
|
2024-08-07 01:05:08 +08:00
|
|
|
await expect(uut.getByRole("heading", { name: "Account", exact: true })).toBeVisible();
|
2023-11-29 21:50:13 +08:00
|
|
|
|
2024-06-06 21:56:38 +08:00
|
|
|
const profile = uut.locator(".mx_UserProfileSettings_profile");
|
2023-11-29 21:50:13 +08:00
|
|
|
await profile.scrollIntoViewIfNeeded();
|
|
|
|
await expect(profile.getByRole("textbox", { name: "Display Name" })).toHaveValue(USER_NAME);
|
|
|
|
|
|
|
|
// Assert that a userId is rendered
|
2024-06-06 21:56:38 +08:00
|
|
|
expect(uut.getByLabel("Username")).toHaveText(user.userId);
|
2023-11-29 21:50:13 +08:00
|
|
|
|
|
|
|
// 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");
|
2024-08-07 01:05:08 +08:00
|
|
|
accountSection.scrollIntoViewIfNeeded();
|
2023-11-29 21:50:13 +08:00
|
|
|
// Assert that input areas for changing a password exists
|
2024-08-07 01:05:08 +08:00
|
|
|
await expect(accountSection.getByLabel("Current password")).toBeVisible();
|
|
|
|
await expect(accountSection.getByLabel("New Password")).toBeVisible();
|
|
|
|
await expect(accountSection.getByLabel("Confirm password")).toBeVisible();
|
2023-11-29 21:50:13 +08:00
|
|
|
|
|
|
|
// 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/,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2024-05-11 00:29:50 +08:00
|
|
|
test("should respond to small screen sizes", async ({ page, uut }) => {
|
|
|
|
await page.setViewportSize({ width: 700, height: 600 });
|
2024-08-07 01:05:08 +08:00
|
|
|
await expect(uut).toMatchScreenshot("account-smallscreen.png");
|
2024-05-11 00:29:50 +08:00
|
|
|
});
|
|
|
|
|
2024-06-14 22:17:46 +08:00
|
|
|
test("should show tooltips on narrow screen", async ({ page, uut }) => {
|
|
|
|
await page.setViewportSize({ width: 700, height: 600 });
|
2024-08-07 01:05:08 +08:00
|
|
|
await page.getByRole("tab", { name: "Account" }).hover();
|
|
|
|
await expect(page.getByRole("tooltip")).toHaveText("Account");
|
2024-06-14 22:17:46 +08:00
|
|
|
});
|
|
|
|
|
2024-06-07 21:25:21 +08:00
|
|
|
test("should support adding and removing a profile picture", async ({ uut, page }) => {
|
2024-06-06 21:56:38 +08:00
|
|
|
const profileSettings = uut.locator(".mx_UserProfileSettings");
|
2023-11-29 21:50:13 +08:00
|
|
|
// Upload a picture
|
2024-05-21 18:37:02 +08:00
|
|
|
await profileSettings.getByAltText("Upload").setInputFiles("playwright/sample-files/riot.png");
|
2023-11-29 21:50:13 +08:00
|
|
|
|
2024-06-07 21:25:21 +08:00
|
|
|
// Image should be visible
|
|
|
|
await expect(profileSettings.locator(".mx_AvatarSetting_avatar img")).toBeVisible();
|
2023-11-29 21:50:13 +08:00
|
|
|
|
2024-06-07 21:25:21 +08:00
|
|
|
// 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();
|
2023-11-29 21:50:13 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
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
|
2024-06-06 21:56:38 +08:00
|
|
|
.locator(".mx_SettingsTab .mx_UserProfileSettings")
|
2023-11-29 21:50:13 +08:00
|
|
|
.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
|
|
|
|
});
|
|
|
|
});
|