Playwright test: ensure that links are preserved over login (#12657)

pull/28217/head
Richard van der Hoff 2024-06-20 18:18:11 +01:00 committed by GitHub
parent 0317755e9c
commit 5bcf76c9ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 34 additions and 20 deletions

View File

@ -14,20 +14,21 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { test, expect } from "../../element-web-test"; import { Page } from "@playwright/test";
import { expect, test } from "../../element-web-test";
import { doTokenRegistration } from "./utils"; import { doTokenRegistration } from "./utils";
import { isDendrite } from "../../plugins/homeserver/dendrite"; import { isDendrite } from "../../plugins/homeserver/dendrite";
test.describe("Login", () => { test.describe("Login", () => {
test.describe("m.login.password", () => { test.describe("Password login", () => {
test.use({ startHomeserverOpts: "consent" }); test.use({ startHomeserverOpts: "consent" });
const username = "user1234"; const username = "user1234";
const password = "p4s5W0rD"; const password = "p4s5W0rD";
test.beforeEach(async ({ page, homeserver }) => { test.beforeEach(async ({ homeserver }) => {
await homeserver.registerUser(username, password); await homeserver.registerUser(username, password);
await page.goto("/#/login");
}); });
test("logs in with an existing account and lands on the home screen", async ({ test("logs in with an existing account and lands on the home screen", async ({
@ -35,15 +36,10 @@ test.describe("Login", () => {
homeserver, homeserver,
checkA11y, checkA11y,
}) => { }) => {
// first pick the homeserver, as otherwise the user picker won't be visible await page.goto("/#/login");
await page.getByRole("button", { name: "Edit" }).click();
await page.getByRole("textbox", { name: "Other homeserver" }).fill(homeserver.config.baseUrl);
await page.getByRole("button", { name: "Continue", exact: true }).click();
// wait for the dialog to go away
await expect(page.locator(".mx_ServerPickerDialog")).toHaveCount(0);
await expect(page.locator(".mx_Spinner")).toHaveCount(0); // first pick the homeserver, as otherwise the user picker won't be visible
await expect(page.locator(".mx_ServerPicker_server")).toHaveText(homeserver.config.baseUrl); await selectHomeserver(page, homeserver.config.baseUrl);
await page.getByRole("button", { name: "Edit" }).click(); await page.getByRole("button", { name: "Edit" }).click();
@ -56,14 +52,7 @@ test.describe("Login", () => {
await expect(page.locator(".mx_ServerPicker_server")).toHaveText("server.invalid"); await expect(page.locator(".mx_ServerPicker_server")).toHaveText("server.invalid");
// switch back to the custom homeserver // switch back to the custom homeserver
await page.getByRole("button", { name: "Edit" }).click(); await selectHomeserver(page, homeserver.config.baseUrl);
await page.getByRole("textbox", { name: "Other homeserver" }).fill(homeserver.config.baseUrl);
await page.getByRole("button", { name: "Continue", exact: true }).click();
// wait for the dialog to go away
await expect(page.locator(".mx_ServerPickerDialog")).toHaveCount(0);
await expect(page.locator(".mx_Spinner")).toHaveCount(0);
await expect(page.locator(".mx_ServerPicker_server")).toHaveText(homeserver.config.baseUrl);
await expect(page.getByRole("textbox", { name: "Username" })).toBeVisible(); await expect(page.getByRole("textbox", { name: "Username" })).toBeVisible();
// Disabled because flaky - see https://github.com/vector-im/element-web/issues/24688 // Disabled because flaky - see https://github.com/vector-im/element-web/issues/24688
@ -76,6 +65,31 @@ test.describe("Login", () => {
await expect(page).toHaveURL(/\/#\/home$/); await expect(page).toHaveURL(/\/#\/home$/);
}); });
test("Follows the original link after login", async ({ page, homeserver }) => {
await page.goto("/#/room/!room:id"); // should redirect to the welcome page
await page.getByRole("link", { name: "Sign in" }).click();
await selectHomeserver(page, homeserver.config.baseUrl);
await page.getByRole("textbox", { name: "Username" }).fill(username);
await page.getByPlaceholder("Password").fill(password);
await page.getByRole("button", { name: "Sign in" }).click();
await expect(page).toHaveURL(/\/#\/room\/!room:id$/);
await expect(page.getByRole("button", { name: "Join the discussion" })).toBeVisible();
});
async function selectHomeserver(page: Page, homeserverUrl: string) {
await page.getByRole("button", { name: "Edit" }).click();
await page.getByRole("textbox", { name: "Other homeserver" }).fill(homeserverUrl);
await page.getByRole("button", { name: "Continue", exact: true }).click();
// wait for the dialog to go away
await expect(page.locator(".mx_ServerPickerDialog")).toHaveCount(0);
await expect(page.locator(".mx_Spinner")).toHaveCount(0);
await expect(page.locator(".mx_ServerPicker_server")).toHaveText(homeserverUrl);
}
}); });
// tests for old-style SSO login, in which we exchange tokens with Synapse, and Synapse talks to an auth server // tests for old-style SSO login, in which we exchange tokens with Synapse, and Synapse talks to an auth server