@@ -13,6 +13,14 @@ jest.mock("react-router-dom", () => ({
1313 useNavigate : ( ) => jest . fn ( ) ,
1414} ) ) ;
1515
16+ // Mock the import of the css
17+ jest . mock ( "simplebar-react/dist/simplebar.min.css" , ( ) => "" ) ;
18+ // Mock the simplebar-react component
19+ jest . mock ( "simplebar-react" , ( ) => ( {
20+ __esModule : true ,
21+ default : ( { children} : { children : React . JSX . Element } ) => < div > { children } </ div > ,
22+ } ) ) ;
23+
1624/* eslint-disable react-refresh/only-export-components */
1725const Authenticated = {
1826 checkValidity : jest . fn ( ) . mockReturnValue ( Promise . resolve ( true ) ) ,
@@ -24,6 +32,16 @@ const Authenticated = {
2432 getUserDetails : jest . fn ( ) . mockReturnValue ( { username : "kay" , email : "kay" } ) ,
2533 clear : jest . fn ( ) ,
2634} ;
35+ const AuthenticatedWithOrgsWithErrors = {
36+ checkValidity : jest . fn ( ) . mockReturnValue ( Promise . resolve ( true ) ) ,
37+ authenticateInGitHub : jest . fn ( ) . mockReturnValue ( Promise ) ,
38+ fetchOrgs : jest . fn ( ) . mockReturnValue ( { orgs : [ { account : { login : "org-1" } , id : 1 , isAdmin : false } , { account : { login : "org-2" } , id : 2 , requiresSsoLogin : true } , { account : { login : "org-3" } , id : 3 , isIPBlocked : true } , { account : { login : "org-4" } , id : 4 , isAdmin : true } ] } ) ,
39+ installNewApp : jest . fn ( ) ,
40+ connectOrg : jest . fn ( ) ,
41+ setTokens : jest . fn ( ) ,
42+ getUserDetails : jest . fn ( ) . mockReturnValue ( { username : "kay" , email : "kay" } ) ,
43+ clear : jest . fn ( ) ,
44+ } ;
2745const AuthenticatedWithNoOrgs = {
2846 checkValidity : jest . fn ( ) . mockReturnValue ( Promise . resolve ( true ) ) ,
2947 authenticateInGitHub : jest . fn ( ) . mockReturnValue ( Promise ) ,
@@ -33,7 +51,6 @@ const AuthenticatedWithNoOrgs = {
3351 getUserDetails : jest . fn ( ) . mockReturnValue ( { username : "kay" , email : "kay" } ) ,
3452 clear : jest . fn ( ) ,
3553} ;
36-
3754/* eslint-disable react-refresh/only-export-components */
3855const UnAuthenticated = {
3956 checkValidity : jest . fn ( ) . mockReturnValue ( Promise . resolve ( false ) ) ,
@@ -166,6 +183,52 @@ test("Connect GitHub Screen - Checking the GitHub Cloud flow when authenticated
166183 expect ( AppManager . connectOrg ) . toBeCalled ( ) ;
167184} ) ;
168185
186+ test ( "Connect GitHub Screen - Checking the GitHub Cloud flow when authenticated with orgs with errors" , async ( ) => {
187+ jest . mocked ( OAuthManager ) . getUserDetails = AuthenticatedWithOrgsWithErrors . getUserDetails ;
188+ jest . mocked ( OAuthManager ) . checkValidity = AuthenticatedWithOrgsWithErrors . checkValidity ;
189+ jest . mocked ( AppManager ) . fetchOrgs = AuthenticatedWithOrgsWithErrors . fetchOrgs ;
190+ jest . mocked ( AppManager ) . installNewApp = AuthenticatedWithOrgsWithErrors . installNewApp ;
191+ jest . mocked ( AppManager ) . connectOrg = jest . fn ( ) . mockImplementation ( async ( ) => {
192+ //do not return, so that to assert on the loading icon
193+ return new Promise ( _ => { } ) ;
194+ } ) ;
195+
196+ const { container } = render (
197+ < BrowserRouter >
198+ < ConfigSteps />
199+ </ BrowserRouter >
200+ ) ;
201+ await act ( async ( ) => container ) ;
202+
203+ expect ( screen . queryByText ( GITHUB_CLOUD ) ) . not . toBeInTheDocument ( ) ;
204+ expect ( screen . queryByText ( GITHUB_ENTERPRISE ) ) . not . toBeInTheDocument ( ) ;
205+ expect ( screen . queryByText ( "Next " ) ) . not . toBeInTheDocument ( ) ;
206+ expect ( screen . queryByText ( SELECT_GH_PRODUCT ) ) . not . toBeInTheDocument ( ) ;
207+
208+ // Checking if all the orgs are being displayed
209+ expect ( screen . queryByText ( SELECT_GH_TEXT ) ) . toBeInTheDocument ( ) ;
210+ expect ( screen . queryByText ( "org-1" ) ) . toBeInTheDocument ( ) ;
211+ expect ( screen . queryByText ( "org-2" ) ) . toBeInTheDocument ( ) ;
212+ expect ( screen . queryByText ( "org-3" ) ) . toBeInTheDocument ( ) ;
213+ expect ( screen . queryByText ( "org-4" ) ) . toBeInTheDocument ( ) ;
214+
215+ // 3 orgs have errors, only 1 can be connected
216+ expect ( await screen . findAllByRole ( "button" , { name : "Connect" } ) ) . toHaveLength ( 1 ) ;
217+
218+ const errorForNonAdmins = container . querySelectorAll ( "[class$='-ErrorForNonAdmins']" ) ;
219+ expect ( errorForNonAdmins [ 0 ] . textContent ) . toBe ( "Can't connect, you're not the organization owner.Ask an organization owner to complete this step." ) ;
220+
221+ const errorForSSO = container . querySelectorAll ( "[class$='-ErrorForSSO']" ) ;
222+ expect ( errorForSSO [ 0 ] . textContent ) . toBe ( "Can't connect, single sign-on(SSO) required." ) ;
223+ expect ( errorForSSO [ 1 ] . textContent ) . toBe ( "1. Log into GitHub with SSO." ) ;
224+ expect ( errorForSSO [ 3 ] . textContent ) . toBe ( "2. Retry connection in Jira (once logged in)." ) ;
225+
226+ const errorForIPBlocked = container . querySelectorAll ( "[class$='-ErrorForIPBlocked']" ) ;
227+ expect ( errorForIPBlocked [ 0 ] . textContent ) . toBe ( "Can't connect, blocked by your IP allow list." ) ;
228+ expect ( errorForIPBlocked [ 1 ] . textContent ) . toBe ( "How to update allowlist" ) ;
229+ expect ( errorForIPBlocked [ 3 ] . textContent ) . toBe ( "Retry" ) ;
230+ } ) ;
231+
169232test ( "Connect GitHub Screen - Checking the GitHub Cloud flow when authenticated with no orgs" , async ( ) => {
170233 jest . mocked ( OAuthManager ) . getUserDetails = AuthenticatedWithNoOrgs . getUserDetails ;
171234 jest . mocked ( OAuthManager ) . checkValidity = AuthenticatedWithNoOrgs . checkValidity ;
@@ -220,3 +283,4 @@ test("Connect GitHub Screen - Changing GitHub login when authenticated", async (
220283 expect ( screen . queryByText ( SELECT_GH_PRODUCT_CTA ) ) . toBeInTheDocument ( ) ;
221284} ) ;
222285
286+
0 commit comments