Skip to content

Commit 414b93a

Browse files
authored
fix: refactor user profile test to avoid flake (#5499)
1 parent f2b111e commit 414b93a

File tree

3 files changed

+127
-14
lines changed

3 files changed

+127
-14
lines changed

cypress/e2e/cloud/userProfile.ts renamed to cypress/e2e/cloud/userProfile.test.ts

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ export const setupProfile = (): Promise<any> => {
88
method: 'PUT',
99
url: 'api/v2/quartz/accounts/resetAllAccountOrgs',
1010
})
11+
cy.visit('/')
1112
cy.getByTestID('home-page--header').should('be.visible')
1213
cy.setFeatureFlags(userProfileFeatureFlags).then(() => {
1314
// cy.wait($time) is necessary to consistently ensure sufficient time for the feature flag override.
1415
// The flag reset happens via redux, (it's not a network request), so we can't cy.wait($intercepted_route).
15-
cy.wait(300).then(() => {
16+
cy.wait(1200).then(() => {
1617
cy.visit('/me/profile')
1718
})
1819
})
@@ -96,6 +97,12 @@ describe('User profile page', () => {
9697
})
9798

9899
it("displays the user's name and email", () => {
100+
cy.fixture('multiOrgAccounts1.json').then(quartzAccounts => {
101+
cy.intercept('GET', '/api/v2/quartz/accounts', quartzAccounts).as(
102+
'getAccounts'
103+
)
104+
})
105+
99106
cy.getByTestID('user-profile--page')
100107
.contains('User Profile')
101108
.should('be.visible')
@@ -133,17 +140,22 @@ describe('User profile page', () => {
133140

134141
describe('multi-org users', () => {
135142
it('allows the user to change their default account', () => {
136-
cy.intercept({
137-
path: '/api/v2/quartz/accounts/default',
138-
method: 'PUT',
143+
cy.fixture('multiOrgAccounts1.json').then(quartzAccounts => {
144+
cy.intercept('GET', '/api/v2/quartz/accounts', quartzAccounts).as(
145+
'getAccounts'
146+
)
147+
})
148+
149+
cy.intercept('PUT', '/api/v2/quartz/accounts/default', {
150+
statusCode: 204,
151+
data: '',
139152
}).as('putQuartzDefaultAccount')
140153

141154
cy.getByTestID('user-profile--save-button').should(
142155
'have.attr',
143156
'disabled'
144157
)
145158

146-
// Confirm that the user can change default accounts solely by clicking in the dropdown.
147159
cy.getByTestID('user-profile--change-account-header')
148160
.contains('Default Account')
149161
.should('be.visible')
@@ -157,6 +169,15 @@ describe('User profile page', () => {
157169
.contains('Influx')
158170
.click()
159171

172+
cy.fixture('multiOrgAccounts1.json').then(quartzAccounts => {
173+
quartzAccounts[0].isDefault = true
174+
quartzAccounts[1].isDefault = false
175+
176+
cy.intercept('GET', '/api/v2/quartz/accounts', quartzAccounts).as(
177+
'getAccounts'
178+
)
179+
})
180+
160181
cy.getByTestID('user-profile--save-button')
161182
.should('be.visible')
162183
.click()
@@ -194,6 +215,13 @@ describe('User profile page', () => {
194215
.contains('Veganomicon')
195216
.click()
196217

218+
// Reset to default fixture, where Veganomicon is default.
219+
cy.fixture('multiOrgAccounts1.json').then(quartzAccounts => {
220+
cy.intercept('GET', '/api/v2/quartz/accounts', quartzAccounts).as(
221+
'getAccounts'
222+
)
223+
})
224+
197225
cy.getByTestID('user-profile--save-button')
198226
.should('be.visible')
199227
.click()
@@ -222,9 +250,9 @@ describe('User profile page', () => {
222250
})
223251

224252
it('allows the user to change their default org', () => {
225-
cy.intercept({
226-
path: '/api/v2/quartz/accounts/**/orgs/default',
227-
method: 'PUT',
253+
cy.intercept('PUT', '/api/v2/quartz/accounts/**/orgs/default', {
254+
statusCode: 204,
255+
data: '',
228256
}).as('putQuartzDefaultOrg')
229257

230258
cy.getByTestID('user-profile--current-account-header')
@@ -309,14 +337,14 @@ describe('User profile page', () => {
309337
})
310338

311339
it('allows the user to change both their default account and org', () => {
312-
cy.intercept({
313-
path: '/api/v2/quartz/accounts/default',
314-
method: 'PUT',
340+
cy.intercept('PUT', '/api/v2/quartz/accounts/default', {
341+
statusCode: 204,
342+
data: '',
315343
}).as('putQuartzDefaultAccount')
316344

317-
cy.intercept({
318-
path: '/api/v2/quartz/accounts/**/orgs/default',
319-
method: 'PUT',
345+
cy.intercept('PUT', '/api/v2/quartz/accounts/**/orgs/default', {
346+
statusCode: 204,
347+
data: '',
320348
}).as('putQuartzDefaultOrg')
321349

322350
cy.getByTestID('user-profile--change-account-dropdown').type('Inf')
@@ -335,6 +363,15 @@ describe('User profile page', () => {
335363
.contains('Test Org 1')
336364
.click()
337365

366+
cy.fixture('multiOrgAccounts1.json').then(quartzAccounts => {
367+
quartzAccounts[0].isDefault = true
368+
quartzAccounts[1].isDefault = false
369+
370+
cy.intercept('GET', '/api/v2/quartz/accounts', quartzAccounts).as(
371+
'getAccounts'
372+
)
373+
})
374+
338375
cy.getByTestID('user-profile--save-button').click()
339376

340377
cy.wait(['@putQuartzDefaultOrg', '@putQuartzDefaultAccount']).then(() => {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
"id": 416,
4+
"isActive": true,
5+
"isDefault": false,
6+
"name": "Influx"
7+
},
8+
{
9+
"id": 415,
10+
"isActive": false,
11+
"isDefault": true,
12+
"name": "Veganomicon"
13+
}
14+
]
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
[
2+
{
3+
"id": "9296169091c64567",
4+
"name": "Test Org 0",
5+
"isDefault": true,
6+
"isActive": true
7+
},
8+
{
9+
"id": "a71ced2b8238902b",
10+
"name": "Test Org 1",
11+
"isDefault": false,
12+
"isActive": false
13+
},
14+
{
15+
"id": "ac3d3c04b8f1a545",
16+
"name": "Test Org 2",
17+
"isDefault": false,
18+
"isActive": false
19+
},
20+
{
21+
"id": "fc734484afa0fcac",
22+
"name": "Test Org 3",
23+
"isDefault": false,
24+
"isActive": false
25+
},
26+
{
27+
"id": "62cba0af4760ce02",
28+
"name": "Test Org 4",
29+
"isDefault": false,
30+
"isActive": false
31+
},
32+
{
33+
"id": "58fafbb4f68e05e5",
34+
"name": "Test Org 5",
35+
"isDefault": false,
36+
"isActive": false
37+
},
38+
{
39+
"id": "3f3fd71611a4a0fe",
40+
"name": "Test Org 6",
41+
"isDefault": false,
42+
"isActive": false
43+
},
44+
{
45+
"id": "1232a0085d2af2dd",
46+
"name": "Test Org 7",
47+
"isDefault": false,
48+
"isActive": false
49+
},
50+
{
51+
"id": "e337e5c5ee6439a2",
52+
"name": "Test Org 8",
53+
"isDefault": false,
54+
"isActive": false
55+
},
56+
{
57+
"id": "3b3ca09032853015",
58+
"name": "Test Org 9",
59+
"isDefault": false,
60+
"isActive": false
61+
}
62+
]

0 commit comments

Comments
 (0)