@@ -13,23 +13,33 @@ describe('change-account change-org global header', () => {
1313 }
1414
1515 const makeQuartzUseIDPEOrgID = ( ) => {
16- cy . intercept ( 'GET' , 'api/v2/quartz/identity' , req => {
17- req . continue ( res => {
18- res . body . org . id = idpeOrgID
19- } )
20- } ) . as ( 'getQuartzIdentity' )
16+ cy . fixture ( 'multiOrgAccounts1.json' ) . then ( quartzAccounts => {
17+ cy . intercept ( 'GET' , 'api/v2/quartz/accounts' , quartzAccounts ) . as (
18+ 'getQuartzAccounts'
19+ )
20+ } )
2121
22- cy . intercept ( 'GET' , '/api/v2/quartz/accounts/**/orgs' , req => {
23- req . continue ( res => {
24- res . body [ 0 ] . id = idpeOrgID
25- } )
26- } ) . as ( 'getQuartzOrgs' )
22+ cy . fixture ( 'multiOrgIdentity' ) . then ( quartzIdentity => {
23+ quartzIdentity . org . id = idpeOrgID
24+ cy . intercept ( 'GET' , 'api/v2/quartz/identity' , quartzIdentity ) . as (
25+ 'getQuartzIdentity'
26+ )
27+ } )
2728
28- cy . intercept ( 'GET' , 'api/v2/quartz/orgs/*' , req => {
29- req . continue ( res => {
30- res . body . id = idpeOrgID
31- } )
32- } ) . as ( 'getQuartzOrgDetails' )
29+ cy . fixture ( 'multiOrgOrgs1' ) . then ( quartzOrgs => {
30+ quartzOrgs [ 0 ] . id = idpeOrgID
31+
32+ cy . intercept ( 'GET' , 'api/v2/quartz/accounts/**/orgs' , quartzOrgs ) . as (
33+ 'getQuartzOrgs'
34+ )
35+ } )
36+
37+ cy . fixture ( 'orgDetails' ) . then ( quartzOrgDetails => {
38+ quartzOrgDetails . id = idpeOrgID
39+ cy . intercept ( 'GET' , 'api/v2/quartz/orgs/*' , quartzOrgDetails ) . as (
40+ 'getQuartzOrgDetails'
41+ )
42+ } )
3343 }
3444
3545 const mockQuartzOutage = ( ) => {
@@ -51,10 +61,12 @@ describe('change-account change-org global header', () => {
5161 cy . signin ( ) . then ( ( ) => {
5262 cy . request ( {
5363 method : 'GET' ,
54- url : '/ api/v2/orgs' ,
64+ url : 'api/v2/orgs' ,
5565 } ) . then ( res => {
5666 // Store the IDPE org ID so that it can be cloned when intercepting quartz.
57- idpeOrgID = res . body . orgs [ 0 ] . id
67+ if ( res . body . orgs ) {
68+ idpeOrgID = res . body . orgs [ 0 ] . id
69+ }
5870 } )
5971 } )
6072 )
@@ -63,6 +75,11 @@ describe('change-account change-org global header', () => {
6375 beforeEach ( ( ) => {
6476 // Preserve one session throughout.
6577 Cypress . Cookies . preserveOnce ( 'sid' )
78+ cy . setFeatureFlags ( globalHeaderFeatureFlags )
79+ } )
80+
81+ afterEach ( ( ) => {
82+ cy . wait ( 1200 )
6683 } )
6784
6885 describe ( 'global change-account and change-org header' , ( ) => {
@@ -71,35 +88,20 @@ describe('change-account change-org global header', () => {
7188 interceptPageReload ( )
7289 cy . setFeatureFlags ( globalHeaderFeatureFlags ) . then ( ( ) => {
7390 cy . visit ( '/' )
74- cy . wait ( [ '@getQuartzIdentity' , '@ getQuartzAccounts'] )
91+ cy . wait ( '@ getQuartzAccounts')
7592 cy . getByTestID ( 'global-header--container' ) . should ( 'not.exist' )
7693 } )
7794 } )
7895
7996 describe ( 'change org dropdown' , ( ) => {
8097 before ( ( ) => {
81- cy . request ( {
82- method : 'GET' ,
83- url : '/api/v2/orgs' ,
84- } ) . then ( res => {
85- // Retrieve the user's org ID from IDPE.
86- idpeOrgID = res . body . orgs [ 0 ] . id
87-
88- cy . setFeatureFlags ( globalHeaderFeatureFlags )
89- cy . visit ( '/' )
90- } )
91- } )
92-
93- beforeEach ( ( ) => {
94- // For each test, replace the org id served by quartz-mock with the IDPE org id.
95- // This ensures that routes based on the current org id are compatible with quartz-mock.
9698 makeQuartzUseIDPEOrgID ( )
97- // A short wait is needed to ensure we've completed trailing API calls. Can't consistently cy.wait one route,
98- // as the problem call varies. This adds < 1s to a 35+ second run, which seems acceptable to combat flake.
99- cy . wait ( 200 )
99+ cy . setFeatureFlags ( globalHeaderFeatureFlags )
100+ cy . visit ( '/' )
100101 } )
101102
102103 it ( 'navigates to the org settings page' , ( ) => {
104+ makeQuartzUseIDPEOrgID ( )
103105 cy . getByTestID ( 'globalheader--org-dropdown' )
104106 . should ( 'be.visible' )
105107 . click ( )
@@ -115,6 +117,8 @@ describe('change-account change-org global header', () => {
115117 } )
116118
117119 it ( 'navigates to the org members page' , ( ) => {
120+ makeQuartzUseIDPEOrgID ( )
121+ makeQuartzUseIDPEOrgID ( )
118122 cy . getByTestID ( 'globalheader--org-dropdown' )
119123 . should ( 'be.visible' )
120124 . click ( )
@@ -145,11 +149,7 @@ describe('change-account change-org global header', () => {
145149 } )
146150
147151 it ( 'can change change the active org' , ( ) => {
148- cy . intercept ( 'GET' , 'auth/orgs/58fafbb4f68e05e5' , {
149- statusCode : 200 ,
150- body : 'Reaching this page serves an org change in prod.' ,
151- } ) . as ( 'getNewOrg' )
152-
152+ makeQuartzUseIDPEOrgID ( )
153153 cy . getByTestID ( 'globalheader--org-dropdown' )
154154 . should ( 'exist' )
155155 . click ( )
@@ -167,11 +167,12 @@ describe('change-account change-org global header', () => {
167167 cy . getByTestID ( 'globalheader--org-dropdown-main--contents' )
168168 . contains ( 'Org 5' )
169169 . should ( 'be.visible' )
170- . click ( )
171170
172- cy . contains ( 'Reaching this page serves an org change in prod.' ) . should (
173- 'be.visible'
174- )
171+ // Absent real quartz, testing this redirect will not work, and Firefox doesn't play nicely
172+ // with being asked to intercept the route. So expect the org id as the button's id
173+ // which is where this component pulls the link from.
174+ cy . get ( 'button#58fafbb4f68e05e5' ) . should ( 'contain' , 'Test Org 5' )
175+ cy . getByTestID ( 'globalheader--org-dropdown' ) . click ( )
175176 } )
176177 } )
177178
@@ -186,6 +187,7 @@ describe('change-account change-org global header', () => {
186187 } )
187188
188189 it ( 'navigates to the account settings page' , ( ) => {
190+ makeQuartzUseIDPEOrgID ( )
189191 cy . getByTestID ( 'globalheader--account-dropdown' )
190192 . should ( 'exist' )
191193 . click ( )
@@ -202,6 +204,7 @@ describe('change-account change-org global header', () => {
202204 } )
203205
204206 it ( 'navigates to the account billing page' , ( ) => {
207+ makeQuartzUseIDPEOrgID ( )
205208 cy . getByTestID ( 'globalheader--account-dropdown' )
206209 . should ( 'exist' )
207210 . click ( )
@@ -213,14 +216,14 @@ describe('change-account change-org global header', () => {
213216 cy . getByTestID ( 'globalheader--account-dropdown-main-Billing' )
214217 . should ( 'be.visible' )
215218 . click ( )
219+
220+ cy . getByTestID ( 'accounts-billing-tab' )
221+ . should ( 'be.visible' )
222+ . and ( 'contain' , 'Billing' )
216223 } )
217224
218225 it ( 'can change change the active account' , ( ) => {
219- cy . intercept ( 'GET' , 'auth/accounts/415' , {
220- statusCode : 200 ,
221- body : 'Reaching this page serves an account change in prod.' ,
222- } ) . as ( 'getNewAccount' )
223-
226+ makeQuartzUseIDPEOrgID ( )
224227 cy . getByTestID ( 'globalheader--account-dropdown' )
225228 . should ( 'exist' )
226229 . click ( )
@@ -240,31 +243,18 @@ describe('change-account change-org global header', () => {
240243 cy . getByTestID ( 'globalheader--account-dropdown-main--contents' )
241244 . contains ( 'Veganomicon' )
242245 . should ( 'be.visible' )
243- . click ( )
244246
245- cy . contains (
246- 'Reaching this page serves an account change in prod.'
247- ) . should ( 'be.visible' )
247+ // See earlier comment re: no quartz, so testing based on ID, which generates the URL for
248+ // the redirect link in production.
249+ cy . get ( 'button#415' ) . should ( 'contain' , 'Veganomicon' )
250+ cy . getByTestID ( 'globalheader--account-dropdown' ) . click ( )
248251 } )
249252 } )
250253 } )
251254
252255 describe ( 'user profile avatar' , { scrollBehavior : false } , ( ) => {
253- before ( ( ) => {
254- interceptPageReload ( )
255- makeQuartzUseIDPEOrgID ( )
256- // A reset is required here because the prior test ends on a mocked-up page served by cy.intercept,
257- // which stands in for the 'change account' page actually served by quartz in prod.
258- cy . visit ( '/' ) . then ( ( ) => {
259- cy . wait ( [ '@getOrgs' , '@getFlags' ] )
260- cy . setFeatureFlags ( globalHeaderFeatureFlags ) . then ( ( ) => {
261- cy . wait ( '@getQuartzOrgs' )
262- cy . visit ( '/' )
263- } )
264- } )
265- } )
266-
267256 it ( 'navigates to the `user profile` page' , ( ) => {
257+ makeQuartzUseIDPEOrgID ( )
268258 cy . getByTestID ( 'global-header--user-avatar' )
269259 . should ( 'be.visible' )
270260 . click ( )
@@ -281,15 +271,18 @@ describe('change-account change-org global header', () => {
281271 } )
282272
283273 it ( 'allows the user to log out' , ( ) => {
274+ makeQuartzUseIDPEOrgID ( )
284275 cy . getByTestID ( 'global-header--user-avatar' )
285276 . should ( 'be.visible' )
286277 . click ( )
287278
279+ // Logout can't be handled in the test, and redirects to a 404 that
280+ // Firefox doesn't recognize as a new page. Instead, just check if the
281+ // href of the logout button is correct.
288282 cy . getByTestID ( 'global-header--user-popover-logout-button' )
289283 . should ( 'be.visible' )
290- . click ( )
291- // Logout in remocal looks like a 404 because there is no quartz. This tests the logout URL.
292- cy . location ( 'pathname' ) . should ( 'eq' , '/logout' )
284+ . parent ( )
285+ . should ( 'have.attr' , 'href' , '/logout' )
293286 } )
294287 } )
295288} )
0 commit comments