1
- import { fireEvent , screen , waitFor } from "@testing-library/react"
1
+ import { fireEvent , screen , waitFor , within } from "@testing-library/react"
2
2
import * as API from "../../../api/api"
3
3
import * as SecurityForm from "../../../components/SettingsSecurityForm/SettingsSecurityForm"
4
4
import {
@@ -11,6 +11,7 @@ import {
11
11
MockAuthMethodsWithPasswordType ,
12
12
mockApiError ,
13
13
} from "testHelpers/entities"
14
+ import userEvent from "@testing-library/user-event"
14
15
15
16
const { t } = i18next
16
17
@@ -115,3 +116,29 @@ test("update password when submit returns an unknown error", async () => {
115
116
expect ( API . updateUserPassword ) . toBeCalledTimes ( 1 )
116
117
expect ( API . updateUserPassword ) . toBeCalledWith ( user . id , newSecurityFormValues )
117
118
} )
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
+ } )
0 commit comments