mirror of https://github.com/coder/coder.git
fix(site): fix redirection to login after logout/change password (#6870)
* fix(site): fix redirection to login after logout/change password * chore: add login verification assert * prettier
This commit is contained in:
parent
90da09bc2c
commit
3d91fe8895
|
@ -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
|
||||
|
|
|
@ -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
|
||||
})
|
|
@ -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("/"))
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -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
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue