Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion site/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -156,7 +163,6 @@ rules:
message: "Default React import not allowed",
},
]

settings:
react:
version: detect
Expand Down
17 changes: 17 additions & 0 deletions site/e2e/tests/logout.spec.ts
Original file line number Diff line number Diff line change
@@ -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
})
Original file line number Diff line number Diff line change
Expand Up @@ -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("/"))
})
})

Expand Down
8 changes: 3 additions & 5 deletions site/src/xServices/auth/authXService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const userSecuritySettingsMachine = createMachine(
src: "updateSecurity",
onDone: [
{
actions: "notifyUpdate",
actions: ["notifyUpdate", "redirectToHome"],
target: "idle",
},
],
Expand Down Expand Up @@ -66,6 +66,9 @@ export const userSecuritySettingsMachine = createMachine(
assignError: assign({
error: (_, event) => event.data,
}),
redirectToHome: () => {
window.location.href = location.origin
},
},
},
)