Skip to content

Commit db3102c

Browse files
committed
Add integration test
1 parent 2d36d44 commit db3102c

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

site/src/components/SettingsLayout/Section.tsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { SectionAction } from "../SectionAction/SectionAction"
66
type SectionLayout = "fixed" | "fluid"
77

88
export interface SectionProps {
9+
// Useful for testing
10+
id?: string
911
title?: ReactNode | string
1012
description?: ReactNode
1113
toolbar?: ReactNode
@@ -20,6 +22,7 @@ type SectionFC = FC<PropsWithChildren<SectionProps>> & {
2022
}
2123

2224
export const Section: SectionFC = ({
25+
id,
2326
title,
2427
description,
2528
toolbar,
@@ -30,12 +33,16 @@ export const Section: SectionFC = ({
3033
}) => {
3134
const styles = useStyles({ layout })
3235
return (
33-
<section className={className}>
36+
<section className={className} id={id} data-testid={id}>
3437
<div className={styles.inner}>
3538
{(title || description) && (
3639
<div className={styles.header}>
3740
<div>
38-
{title && <Typography variant="h4" sx={{ fontSize: 24 }}>{title}</Typography>}
41+
{title && (
42+
<Typography variant="h4" sx={{ fontSize: 24 }}>
43+
{title}
44+
</Typography>
45+
)}
3946
{description && typeof description === "string" && (
4047
<Typography className={styles.description}>
4148
{description}

site/src/pages/UserSettingsPage/SecurityPage/SecurityPage.test.tsx

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fireEvent, screen, waitFor } from "@testing-library/react"
1+
import { fireEvent, screen, waitFor, within } from "@testing-library/react"
22
import * as API from "../../../api/api"
33
import * as SecurityForm from "../../../components/SettingsSecurityForm/SettingsSecurityForm"
44
import {
@@ -11,6 +11,7 @@ import {
1111
MockAuthMethodsWithPasswordType,
1212
mockApiError,
1313
} from "testHelpers/entities"
14+
import userEvent from "@testing-library/user-event"
1415

1516
const { t } = i18next
1617

@@ -115,3 +116,29 @@ test("update password when submit returns an unknown error", async () => {
115116
expect(API.updateUserPassword).toBeCalledTimes(1)
116117
expect(API.updateUserPassword).toBeCalledWith(user.id, newSecurityFormValues)
117118
})
119+
120+
test("change login type to OIDC", async () => {
121+
const convertToOAUTHSpy = jest.spyOn(API, "convertToOAUTH")
122+
const user = userEvent.setup()
123+
const { user: userData } = await renderPage()
124+
125+
const ssoSection = screen.getByTestId("sso-section")
126+
const githubButton = within(ssoSection).getByText("GitHub", { exact: false })
127+
await user.click(githubButton)
128+
129+
const confirmationDialog = await screen.findByTestId("dialog")
130+
const confirmPasswordField = within(confirmationDialog).getByLabelText(
131+
"Confirm your password",
132+
)
133+
await user.type(confirmPasswordField, "password123")
134+
const updateButton = within(confirmationDialog).getByText("Update")
135+
await user.click(updateButton)
136+
137+
await waitFor(() => {
138+
expect(convertToOAUTHSpy).toHaveBeenCalledWith({
139+
password: "password123",
140+
to_login_type: "github",
141+
email: userData.email,
142+
})
143+
})
144+
})

site/src/pages/UserSettingsPage/SecurityPage/SingleSignOnSection.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export const SingleSignOnSection = ({
9191
return (
9292
<>
9393
<Section
94+
id="sso-section"
9495
title="Single Sign On"
9596
description="Authenticate in Coder using one-click"
9697
>

0 commit comments

Comments
 (0)