mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore(site): Add unit tests, mocks (#514)
* Extract and unit test redirect functions * Move router to make app more testable * Make mock entities more consistent * Use labels instead of placeholders * Fill out handlers * Lint * Reorganize App * Make mock entities reference each other * Add describes in tests * Clean up api and mocks
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { useActor } from "@xstate/react"
|
||||
import React, { useContext } from "react"
|
||||
import { Navigate, useLocation } from "react-router"
|
||||
import { embedRedirect } from "../../util/redirect"
|
||||
import { XServiceContext } from "../../xServices/StateContext"
|
||||
import { FullScreenLoader } from "../Loader/FullScreenLoader"
|
||||
|
||||
@@ -12,9 +13,10 @@ export const RequireAuth: React.FC<RequireAuthProps> = ({ children }) => {
|
||||
const xServices = useContext(XServiceContext)
|
||||
const [userState] = useActor(xServices.userXService)
|
||||
const location = useLocation()
|
||||
const redirectTo = embedRedirect(location.pathname)
|
||||
|
||||
if (userState.matches("signedOut") || !userState.context.me) {
|
||||
return <Navigate to={"/login?redirect=" + encodeURIComponent(location.pathname)} />
|
||||
return <Navigate to={redirectTo} />
|
||||
} else if (userState.hasTag("loading")) {
|
||||
return <FullScreenLoader />
|
||||
} else {
|
||||
|
||||
@@ -61,6 +61,7 @@ export const SignInForm: React.FC<SignInFormProps> = ({ isLoading, authErrorMess
|
||||
<form onSubmit={form.handleSubmit}>
|
||||
<div>
|
||||
<FormTextField
|
||||
label="Email"
|
||||
autoComplete="email"
|
||||
autoFocus
|
||||
className={styles.loginTextField}
|
||||
@@ -71,10 +72,10 @@ export const SignInForm: React.FC<SignInFormProps> = ({ isLoading, authErrorMess
|
||||
inputProps={{
|
||||
id: "signin-form-inpt-email",
|
||||
}}
|
||||
placeholder="Email"
|
||||
variant="outlined"
|
||||
/>
|
||||
<FormTextField
|
||||
label="Password"
|
||||
autoComplete="current-password"
|
||||
className={styles.loginTextField}
|
||||
form={form}
|
||||
@@ -84,7 +85,6 @@ export const SignInForm: React.FC<SignInFormProps> = ({ isLoading, authErrorMess
|
||||
id: "signin-form-inpt-password",
|
||||
}}
|
||||
isPassword
|
||||
placeholder="Password"
|
||||
variant="outlined"
|
||||
/>
|
||||
{authErrorMessage && (
|
||||
|
||||
Reference in New Issue
Block a user