diff --git a/site/.eslintrc.yaml b/site/.eslintrc.yaml index 1942b8a8120bb..e2d09dc4b192f 100644 --- a/site/.eslintrc.yaml +++ b/site/.eslintrc.yaml @@ -43,6 +43,13 @@ overrides: # https://coder.com/docs/v2/latest/contributing/frontend#tests-getting-too-slow. testing-library/no-node-access: off testing-library/no-container: off + - files: ["e2e/**/*.[tj]s"] + extends: ["plugin:testing-library/react", "plugin:testing-library/dom"] + rules: + # Sometimes the eslint-plugin-testing-library believes playwright queries are + # also react-testing-library queries, which is not the case. So we disable this + # rule for all e2e tests. + testing-library/prefer-screen-queries: "off" root: true rules: "@typescript-eslint/brace-style": @@ -156,7 +163,6 @@ rules: message: "Default React import not allowed", }, ] - settings: react: version: detect diff --git a/site/e2e/tests/logout.spec.ts b/site/e2e/tests/logout.spec.ts new file mode 100644 index 0000000000000..5f8f4c892afeb --- /dev/null +++ b/site/e2e/tests/logout.spec.ts @@ -0,0 +1,17 @@ +import { test, expect } from "@playwright/test" +import { getStatePath } from "../helpers" + +test.use({ storageState: getStatePath("authState") }) + +test("signing out redirects to login page", async ({ page, baseURL }) => { + await page.goto(`${baseURL}/`, { waitUntil: "networkidle" }) + + await page.getByTestId("user-dropdown-trigger").click() + await page.getByRole("menuitem", { name: "Sign Out" }).click() + + await expect( + page.getByRole("heading", { name: "Sign in to Coder" }), + ).toBeVisible() + + expect(page.url()).toMatch(/\/login$/) // ensure we're on the login page with no query params +}) diff --git a/site/src/pages/UserSettingsPage/SecurityPage/SecurityPage.test.tsx b/site/src/pages/UserSettingsPage/SecurityPage/SecurityPage.test.tsx index 89b3dac89e428..f7aac577c7a9d 100644 --- a/site/src/pages/UserSettingsPage/SecurityPage/SecurityPage.test.tsx +++ b/site/src/pages/UserSettingsPage/SecurityPage/SecurityPage.test.tsx @@ -47,6 +47,8 @@ describe("SecurityPage", () => { expect(successMessage).toBeDefined() expect(API.updateUserPassword).toBeCalledTimes(1) expect(API.updateUserPassword).toBeCalledWith(user.id, newData) + + await waitFor(() => expect(window.location).toBeAt("/")) }) }) diff --git a/site/src/xServices/auth/authXService.ts b/site/src/xServices/auth/authXService.ts index 44030790830e6..7392aaedaf010 100644 --- a/site/src/xServices/auth/authXService.ts +++ b/site/src/xServices/auth/authXService.ts @@ -389,12 +389,10 @@ export const authMachine = }), redirect: (_, { data }) => { if (!("redirectUrl" in data)) { - throw new Error( - "Redirect only should be called with data.redirectUrl", - ) + window.location.href = location.origin + } else { + window.location.replace(data.redirectUrl) } - - window.location.replace(data.redirectUrl) }, }, guards: { diff --git a/site/src/xServices/userSecuritySettings/userSecuritySettingsXService.ts b/site/src/xServices/userSecuritySettings/userSecuritySettingsXService.ts index 6cc8712542b7f..adccf76dbaa43 100644 --- a/site/src/xServices/userSecuritySettings/userSecuritySettingsXService.ts +++ b/site/src/xServices/userSecuritySettings/userSecuritySettingsXService.ts @@ -35,7 +35,7 @@ export const userSecuritySettingsMachine = createMachine( src: "updateSecurity", onDone: [ { - actions: "notifyUpdate", + actions: ["notifyUpdate", "redirectToHome"], target: "idle", }, ], @@ -66,6 +66,9 @@ export const userSecuritySettingsMachine = createMachine( assignError: assign({ error: (_, event) => event.data, }), + redirectToHome: () => { + window.location.href = location.origin + }, }, }, )