Skip to content

Commit e16e8d8

Browse files
authored
fix: make cloud/operator test more reliable (#4013)
1 parent 1143025 commit e16e8d8

File tree

1 file changed

+75
-104
lines changed

1 file changed

+75
-104
lines changed

cypress/e2e/cloud/operator.test.ts

Lines changed: 75 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,9 @@ describe('Operator Page', () => {
2121
)
2222

2323
it('should render the Operator page and allow for RUD operations', () => {
24-
// Validates that the default behavior is to open to the account tab
25-
cy.getByTestID('accountTab').should('satisfy', element => {
26-
const classList = Array.from(element[0].classList)
27-
return classList.includes('cf-tabs--tab__active')
28-
})
29-
30-
// Expect the org tab to be inactive
31-
cy.getByTestID('orgTab').should('satisfy', element => {
32-
const classList = Array.from(element[0].classList)
33-
return classList.includes('cf-tabs--tab__active') === false
34-
})
24+
// validates that the default behavior is to open to the account tab
25+
cy.getByTestID('accountTab').should('have.class', 'cf-tabs--tab__active')
26+
cy.getByTestID('orgTab').should('not.have.class', 'cf-tabs--tab__active')
3527

3628
cy.get('.cf-refless-popover--trigger').click()
3729

@@ -44,33 +36,44 @@ describe('Operator Page', () => {
4436
cy.getByTestID('table-row').should('have.length', 6)
4537
})
4638

47-
// filter the results by email
39+
// placeholder says filter by email
4840
cy.getByTestID('operator-resource--searchbar')
4941
.invoke('attr', 'placeholder')
5042
.should('contain', 'Filter accounts by email')
5143

52-
cy.focused()
53-
cy.getByTestID('operator-resource--searchbar')
54-
.scrollIntoView()
55-
.type('asalem', {
56-
force: true,
57-
delay: 50,
58-
})
44+
// get ready to search accounts
45+
cy.intercept('GET', '/api/v2/quartz/operator/accounts*').as(
46+
'quartzSearchAccounts'
47+
)
5948

60-
cy.getByTestID('table-body').within(() => {
61-
cy.getByTestID('table-row').should('have.length', 1)
62-
})
49+
// Search for a known user
50+
const knownUser = ['a', 's', 'a', 'l', 'e', 'm']
51+
for (let index = 0; index < knownUser.length; index += 1) {
52+
cy.getByTestID('operator-resource--searchbar').type(knownUser[index])
53+
cy.wait('@quartzSearchAccounts')
54+
cy.getByTestID('table-body').within(() => {
55+
cy.getByTestID('table-row').should('have.length', index === 0 ? 6 : 1)
56+
})
57+
}
6358

6459
// Make sure that the popover closes when clicking out
6560
cy.getByTestID('refless-popover--contents').should('not.exist')
6661

67-
cy.getByTestID('operator-resource--searchbar')
68-
.clear()
69-
.type('salt_bae', {force: true, delay: 50})
62+
// Search for an unknown user
63+
cy.getByTestID('operator-resource--searchbar').clear()
64+
const unknownUser = ['s', 'a', 'l', 't', '_', 'b', 'a', 'e']
65+
for (let index = 0; index < unknownUser.length; index += 1) {
66+
cy.getByTestID('operator-resource--searchbar').type(unknownUser[index])
67+
cy.wait('@quartzSearchAccounts')
68+
69+
// all letters up to 'sal' will match, any more will not
70+
if (index > 2) {
71+
cy.getByTestID('empty-state--text').should('be.visible')
72+
} else {
73+
cy.getByTestID('empty-state--text').should('not.exist')
74+
}
75+
}
7076

71-
cy.getByTestID('empty-state--text').contains(
72-
'Looks like there were no accounts that matched your search'
73-
)
7477
cy.getByTestID('operator-resource--searchbar').clear()
7578

7679
cy.getByTestID('orgTab').click()
@@ -79,43 +82,45 @@ describe('Operator Page', () => {
7982
expect(loc.pathname).to.eq('/operator/orgs')
8083
})
8184

82-
// Expect the org tab to be active
83-
cy.getByTestID('orgTab').should('satisfy', element => {
84-
const classList = Array.from(element[0].classList)
85-
return classList.includes('cf-tabs--tab__active')
86-
})
87-
88-
// Expect the account tab to be inactive
89-
cy.getByTestID('accountTab').should('satisfy', element => {
90-
const classList = Array.from(element[0].classList)
91-
return classList.includes('cf-tabs--tab__active') === false
92-
})
85+
cy.getByTestID('orgTab').should('have.class', 'cf-tabs--tab__active')
86+
cy.getByTestID('accountTab').should(
87+
'not.have.class',
88+
'cf-tabs--tab__active'
89+
)
9390

9491
// preloads 6 organizations
9592
cy.getByTestID('table-body').within(() => {
9693
cy.getByTestID('table-row').should('have.length', 6)
9794
})
9895

99-
// filter the results by email
96+
// placeholder says filter by id
10097
cy.getByTestID('operator-resource--searchbar')
10198
.invoke('attr', 'placeholder')
10299
.should('contain', 'Filter organizations by id')
103100

104-
cy.getByTestID('operator-resource--searchbar').type('678', {
105-
force: true,
106-
delay: 50,
107-
})
108-
cy.getByTestID('table-body').within(() => {
109-
cy.getByTestID('table-row').should('have.length', 1)
110-
})
101+
// get ready to search orgs
102+
cy.intercept('GET', '/api/v2/quartz/operator/orgs*').as('quartzSearchOrgs')
111103

112-
cy.getByTestID('operator-resource--searchbar')
113-
.clear()
114-
.type('invalid', {force: true, delay: 50})
104+
// search for a known org
105+
const knownOrg = ['6', '7', '8']
106+
for (let index = 0; index < knownOrg.length; index += 1) {
107+
cy.getByTestID('operator-resource--searchbar').type(knownOrg[index])
108+
cy.wait('@quartzSearchOrgs')
109+
cy.getByTestID('table-body').within(() => {
110+
cy.getByTestID('table-row').should('have.length', 1)
111+
})
112+
}
113+
114+
cy.getByTestID('operator-resource--searchbar').clear()
115+
116+
// search for an unknown org
117+
const unknownOrg = ['i', 'n', 'v', 'a', 'l', 'i', 'd']
118+
for (let index = 0; index < unknownOrg.length; index += 1) {
119+
cy.getByTestID('operator-resource--searchbar').type(unknownOrg[index])
120+
cy.wait('@quartzSearchOrgs')
121+
cy.getByTestID('empty-state--text').should('be.visible')
122+
}
115123

116-
cy.getByTestID('empty-state--text').contains(
117-
'Looks like there were no organizations that matched your search'
118-
)
119124
cy.getByTestID('operator-resource--searchbar').clear()
120125

121126
cy.getByTestID('accountTab').click()
@@ -124,6 +129,9 @@ describe('Operator Page', () => {
124129
expect(loc.pathname).to.eq('/operator/accounts')
125130
})
126131

132+
cy.getByTestID('accountTab').should('have.class', 'cf-tabs--tab__active')
133+
cy.getByTestID('orgTab').should('not.have.class', 'cf-tabs--tab__active')
134+
127135
cy.getByTestID('account-id')
128136
.first()
129137
.within(() => {
@@ -149,22 +157,9 @@ describe('Operator Page', () => {
149157
cy.getByTestID('subscription-status--header').should('exist')
150158
cy.getByTestID('billing-contact--header').should('exist')
151159

152-
// Validate that associated users appear
153-
// TODO(ariel): reenable this. Deleting the user seems to be causing issues with the data
154-
// cy.getByTestID('associated-users--table-body').within(() => {
155-
// cy.getByTestID('table-row').should('have.length', 1)
156-
// cy.getByTestID('remove-user--button').click()
157-
// })
158-
159-
// // Remove the associated user
160-
// cy.getByTestID('remove-user--confirm-button').click()
161-
162-
// // Confirm that the associated user was deleted
163-
// cy.getByTestID('empty-state').should('exist')
164-
165-
cy.getByTestID('associated-orgs--title')
166-
.contains('Associated Organizations')
167-
.scrollIntoView()
160+
cy.getByTestID('associated-orgs--title').contains(
161+
'Associated Organizations'
162+
)
168163

169164
cy.getByTestID('associated-orgs--table-body').within(() => {
170165
cy.getByTestID('table-row').should('have.length', 6)
@@ -181,51 +176,26 @@ describe('Operator Page', () => {
181176
expect(loc.pathname).to.eq('/operator/orgs/678')
182177
})
183178

179+
cy.getByTestID('overlay--container').should('be.visible')
184180
cy.getByTestID('overlay--header').contains('678')
185181

186182
cy.getByTestID('limits-rate.readKBs--input')
187183
.clear()
188-
.type('666', {delay: 50})
184+
.type('666')
189185

190186
cy.getByTestID('org-overlay--submit-button').click()
191187

192188
cy.getByTestID('account-view--back-button').click()
193189

194-
// cy.getByTestID('operator-resource--searchbar').type('ariel', {
195-
// force: true,
196-
// delay: 50,
197-
// })
198-
199-
// cy.getByTestID('account-id')
200-
// .last()
201-
// .within(() => {
202-
// cy.get('a').click()
203-
// })
204-
205-
// cy.location().should(loc => {
206-
// expect(loc.pathname).to.eq('/operator/accounts/3')
207-
// })
208-
209-
// cy.getByTestID('account-delete--button').click()
210-
211-
// cy.getByTestID('cf-icon alert-triangle cf-alert--icon').should('exist')
212-
213-
// cy.getByTestID('delete-account--confirmation-button').click()
214-
215-
// redirect the operator back to the operator page once deleting an account
216-
// cy.location().should(loc => {
217-
// expect(loc.pathname).to.eq('/operator')
218-
// })
219-
220-
// cy.getByTestID('operator-resource--searchbar').type('ariel', {
221-
// force: true,
222-
// delay: 50,
223-
// })
224-
225-
// // confirm that the account has been deleted
226-
// cy.getByTestID('empty-state').should('exist')
190+
cy.getByTestID('accountTab').should('have.class', 'cf-tabs--tab__active')
191+
cy.getByTestID('orgTab').should('not.have.class', 'cf-tabs--tab__active')
227192

228193
cy.getByTestID('orgTab').click()
194+
cy.getByTestID('orgTab').should('have.class', 'cf-tabs--tab__active')
195+
cy.getByTestID('accountTab').should(
196+
'not.have.class',
197+
'cf-tabs--tab__active'
198+
)
229199

230200
cy.getByTestID('org-id')
231201
.last()
@@ -237,6 +207,7 @@ describe('Operator Page', () => {
237207
expect(loc.pathname).to.eq('/operator/orgs/678')
238208
})
239209

210+
cy.getByTestID('overlay--container').should('be.visible')
240211
cy.getByTestID('overlay--header').contains('678')
241212

242213
cy.getByTestID('limits-rate.readKBs--input')
@@ -245,7 +216,7 @@ describe('Operator Page', () => {
245216

246217
// should be able to view the operator link in the navbar
247218
cy.visit('/')
248-
cy.getByTestID('nav-item--operator').should('exist')
219+
cy.getByTestID('nav-item--operator').should('be.visible')
249220
})
250221
})
251222

0 commit comments

Comments
 (0)