|
| 1 | +/* |
| 2 | +Copyright 2023 Suguru Hirahara |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +/// <reference types="cypress" /> |
| 18 | + |
| 19 | +import { HomeserverInstance } from "../../plugins/utils/homeserver"; |
| 20 | + |
| 21 | +const USER_NAME = "Bob"; |
| 22 | +const USER_NAME_NEW = "Alice"; |
| 23 | +const IntegrationManager = "scalar.vector.im"; |
| 24 | + |
| 25 | +describe("General user settings tab", () => { |
| 26 | + let homeserver: HomeserverInstance; |
| 27 | + let userId: string; |
| 28 | + |
| 29 | + beforeEach(() => { |
| 30 | + cy.startHomeserver("default").then((data) => { |
| 31 | + homeserver = data; |
| 32 | + cy.initTestUser(homeserver, USER_NAME).then((user) => (userId = user.userId)); |
| 33 | + cy.tweakConfig({ default_country_code: "US" }); // For checking the international country calling code |
| 34 | + }); |
| 35 | + cy.openUserSettings("General"); |
| 36 | + }); |
| 37 | + |
| 38 | + afterEach(() => { |
| 39 | + cy.stopHomeserver(homeserver); |
| 40 | + }); |
| 41 | + |
| 42 | + it("should be rendered properly", () => { |
| 43 | + // Exclude userId from snapshots |
| 44 | + const percyCSS = ".mx_ProfileSettings_profile_controls_userId { visibility: hidden !important; }"; |
| 45 | + |
| 46 | + cy.get(".mx_SettingsTab.mx_GeneralUserSettingsTab").percySnapshotElement("User settings tab - General", { |
| 47 | + percyCSS, |
| 48 | + }); |
| 49 | + |
| 50 | + cy.get(".mx_SettingsTab.mx_GeneralUserSettingsTab").within(() => { |
| 51 | + // Assert that the top heading is rendered |
| 52 | + cy.findByTestId("general").should("have.text", "General").should("be.visible"); |
| 53 | + |
| 54 | + cy.get(".mx_ProfileSettings_profile") |
| 55 | + .scrollIntoView() |
| 56 | + .within(() => { |
| 57 | + // Assert USER_NAME is rendered |
| 58 | + cy.findByRole("textbox", { name: "Display Name" }) |
| 59 | + .get(`input[value='${USER_NAME}']`) |
| 60 | + .should("be.visible"); |
| 61 | + |
| 62 | + // Assert that a userId is rendered |
| 63 | + cy.get(".mx_ProfileSettings_profile_controls_userId").within(() => { |
| 64 | + cy.findByText(userId).should("exist"); |
| 65 | + }); |
| 66 | + |
| 67 | + // Check avatar setting |
| 68 | + cy.get(".mx_AvatarSetting_avatar") |
| 69 | + .should("exist") |
| 70 | + .realHover() |
| 71 | + .get(".mx_AvatarSetting_avatar_hovering") |
| 72 | + .within(() => { |
| 73 | + // Hover effect |
| 74 | + cy.get(".mx_AvatarSetting_hoverBg").should("exist"); |
| 75 | + cy.get(".mx_AvatarSetting_hover span").within(() => { |
| 76 | + cy.findByText("Upload").should("exist"); |
| 77 | + }); |
| 78 | + }); |
| 79 | + }); |
| 80 | + |
| 81 | + // Wait until spinners disappear |
| 82 | + cy.get(".mx_GeneralUserSettingsTab_accountSection .mx_Spinner").should("not.exist"); |
| 83 | + cy.get(".mx_GeneralUserSettingsTab_discovery .mx_Spinner").should("not.exist"); |
| 84 | + |
| 85 | + cy.get(".mx_GeneralUserSettingsTab_accountSection").within(() => { |
| 86 | + // Assert that input areas for changing a password exists |
| 87 | + cy.get("form.mx_GeneralUserSettingsTab_changePassword") |
| 88 | + .scrollIntoView() |
| 89 | + .within(() => { |
| 90 | + cy.findByLabelText("Current password").should("be.visible"); |
| 91 | + cy.findByLabelText("New Password").should("be.visible"); |
| 92 | + cy.findByLabelText("Confirm password").should("be.visible"); |
| 93 | + }); |
| 94 | + |
| 95 | + // Check email addresses area |
| 96 | + cy.get(".mx_EmailAddresses") |
| 97 | + .scrollIntoView() |
| 98 | + .within(() => { |
| 99 | + // Assert that an input area for a new email address is rendered |
| 100 | + cy.findByRole("textbox", { name: "Email Address" }).should("be.visible"); |
| 101 | + |
| 102 | + // Assert the add button is visible |
| 103 | + cy.findByRole("button", { name: "Add" }).should("be.visible"); |
| 104 | + }); |
| 105 | + |
| 106 | + // Check phone numbers area |
| 107 | + cy.get(".mx_PhoneNumbers") |
| 108 | + .scrollIntoView() |
| 109 | + .within(() => { |
| 110 | + // Assert that an input area for a new phone number is rendered |
| 111 | + cy.findByRole("textbox", { name: "Phone Number" }).should("be.visible"); |
| 112 | + |
| 113 | + // Assert that the add button is rendered |
| 114 | + cy.findByRole("button", { name: "Add" }).should("be.visible"); |
| 115 | + }); |
| 116 | + }); |
| 117 | + |
| 118 | + // Check language and region setting dropdown |
| 119 | + cy.get(".mx_GeneralUserSettingsTab_languageInput") |
| 120 | + .scrollIntoView() |
| 121 | + .within(() => { |
| 122 | + // Check the default value |
| 123 | + cy.findByText("English").should("be.visible"); |
| 124 | + |
| 125 | + // Click the button to display the dropdown menu |
| 126 | + cy.findByRole("button", { name: "Language Dropdown" }).click(); |
| 127 | + |
| 128 | + // Assert that the default option is rendered and highlighted |
| 129 | + cy.findByRole("option", { name: /Bahasa Indonesia/ }) |
| 130 | + .should("be.visible") |
| 131 | + .should("have.class", "mx_Dropdown_option_highlight"); |
| 132 | + |
| 133 | + // Click again to close the dropdown |
| 134 | + cy.findByRole("button", { name: "Language Dropdown" }).click(); |
| 135 | + |
| 136 | + // Assert that the default value is rendered again |
| 137 | + cy.findByText("English").should("be.visible"); |
| 138 | + }); |
| 139 | + |
| 140 | + cy.get("form.mx_SetIdServer") |
| 141 | + .scrollIntoView() |
| 142 | + .within(() => { |
| 143 | + // Assert that an input area for identity server exists |
| 144 | + cy.findByRole("textbox", { name: "Enter a new identity server" }).should("be.visible"); |
| 145 | + }); |
| 146 | + |
| 147 | + cy.get(".mx_SetIntegrationManager") |
| 148 | + .scrollIntoView() |
| 149 | + .within(() => { |
| 150 | + cy.contains(".mx_SetIntegrationManager_heading_manager", IntegrationManager).should("be.visible"); |
| 151 | + |
| 152 | + // Make sure integration manager's toggle switch is enabled |
| 153 | + cy.get(".mx_ToggleSwitch_enabled").should("be.visible"); |
| 154 | + }); |
| 155 | + |
| 156 | + // Assert the account deactivation button is displayed |
| 157 | + cy.findByTestId("account-management-section") |
| 158 | + .scrollIntoView() |
| 159 | + .findByRole("button", { name: "Deactivate Account" }) |
| 160 | + .should("be.visible") |
| 161 | + .should("have.class", "mx_AccessibleButton_kind_danger"); |
| 162 | + }); |
| 163 | + }); |
| 164 | + |
| 165 | + it("should support adding and removing a profile picture", () => { |
| 166 | + cy.get(".mx_SettingsTab.mx_GeneralUserSettingsTab .mx_ProfileSettings").within(() => { |
| 167 | + // Upload a picture |
| 168 | + cy.get(".mx_ProfileSettings_avatarUpload").selectFile("cypress/fixtures/riot.png", { force: true }); |
| 169 | + |
| 170 | + // Find and click "Remove" link button |
| 171 | + cy.get(".mx_ProfileSettings_profile").within(() => { |
| 172 | + cy.findByRole("button", { name: "Remove" }).click(); |
| 173 | + }); |
| 174 | + |
| 175 | + // Assert that the link button disappeared |
| 176 | + cy.get(".mx_AvatarSetting_avatar .mx_AccessibleButton_kind_link_sm").should("not.exist"); |
| 177 | + }); |
| 178 | + }); |
| 179 | + |
| 180 | + it("should set a country calling code based on default_country_code", () => { |
| 181 | + // Check phone numbers area |
| 182 | + cy.get(".mx_PhoneNumbers") |
| 183 | + .scrollIntoView() |
| 184 | + .within(() => { |
| 185 | + // Assert that an input area for a new phone number is rendered |
| 186 | + cy.findByRole("textbox", { name: "Phone Number" }).should("be.visible"); |
| 187 | + |
| 188 | + // Check a new phone number dropdown menu |
| 189 | + cy.get(".mx_PhoneNumbers_country") |
| 190 | + .scrollIntoView() |
| 191 | + .within(() => { |
| 192 | + // Assert that the country calling code of United States is visible |
| 193 | + cy.findByText(/\+1/).should("be.visible"); |
| 194 | + |
| 195 | + // Click the button to display the dropdown menu |
| 196 | + cy.findByRole("button", { name: "Country Dropdown" }).click(); |
| 197 | + |
| 198 | + // Assert that the option for calling code of United Kingdom is visible |
| 199 | + cy.findByRole("option", { name: /United Kingdom/ }).should("be.visible"); |
| 200 | + |
| 201 | + // Click again to close the dropdown |
| 202 | + cy.findByRole("button", { name: "Country Dropdown" }).click(); |
| 203 | + |
| 204 | + // Assert that the default value is rendered again |
| 205 | + cy.findByText(/\+1/).should("be.visible"); |
| 206 | + }); |
| 207 | + |
| 208 | + cy.findByRole("button", { name: "Add" }).should("be.visible"); |
| 209 | + }); |
| 210 | + }); |
| 211 | + |
| 212 | + it("should support changing a display name", () => { |
| 213 | + cy.get(".mx_SettingsTab.mx_GeneralUserSettingsTab .mx_ProfileSettings").within(() => { |
| 214 | + // Change the diaplay name to USER_NAME_NEW |
| 215 | + cy.findByRole("textbox", { name: "Display Name" }).type(`{selectAll}{del}${USER_NAME_NEW}{enter}`); |
| 216 | + }); |
| 217 | + |
| 218 | + cy.closeDialog(); |
| 219 | + |
| 220 | + // Assert the avatar's initial characters are set |
| 221 | + cy.get(".mx_UserMenu .mx_BaseAvatar_initial").findByText("A").should("exist"); // Alice |
| 222 | + cy.get(".mx_RoomView_wrapper .mx_BaseAvatar_initial").findByText("A").should("exist"); // Alice |
| 223 | + }); |
| 224 | +}); |
0 commit comments