Skip to content

Commit 27612aa

Browse files
committed
Fix bug where a GET triggered by a test, is processed after the test
Sporadically, I was noticing the GET below happening during the teardown of the test: "/api/tenants?filter[]=name=&expand=resources" It turns out we have a form validation for the name field that gets a list of tenant names on form load to prevent the user from providing a duplicate name. For the edit tenant form, we ALSO have an API tenant data request that occurs BEFORE the tenant form loads. Because of this, we need to wait on the single form validation API request for the add form and for the edit form, we need to wait for the load API request first, then, the same validation API request. This should fix the following issue that was happening sporadically locally and in CI: ``` Validate Child Tenant operations: Add, Edit, Add Project, Manage Quotas Validate Add child tenant function ✖(Attempt 1 of 10) Validate Add child tenant form elements ✖(Attempt 2 of 10) Validate Add child tenant form elements ✖(Attempt 3 of 10) Validate Add child tenant form elements ✖(Attempt 4 of 10) Validate Add child tenant form elements ✖(Attempt 5 of 10) Validate Add child tenant form elements ✖(Attempt 6 of 10) Validate Add child tenant form elements ✖(Attempt 7 of 10) Validate Add child tenant form elements ✖(Attempt 8 of 10) Validate Add child tenant form elements ✖(Attempt 9 of 10) Validate Add child tenant form elements ✖(Attempt 10 of 10) "before each" hook for "Validate Add child tenant form elements" ✖ "before each" hook for "Validate Add child tenant form elements" (30358ms) 6 passing (4m) 1 failing 1) Automate Tenant form operations: Settings > Application Settings > Access Control > Tenants Validate Child Tenant operations: Add, Edit, Add Project, Manage Quotas Validate Add child tenant function "before each" hook for "Validate Add child tenant form elements": CypressError: `cy.visit()` failed trying to load: http://localhost:3000/ We attempted to make an http request to this URL but the request failed without a response. We received this error at the network level: > Error: ESOCKETTIMEDOUT ```
1 parent c09cd18 commit 27612aa

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

cypress/e2e/ui/Settings/Application-Settings/tenant.cy.js

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,31 @@ function confirmUiNavigation(callback) {
6868
});
6969
}
7070

71+
function openTenantFormAndWaitForValidation(configOption) {
72+
cy.interceptApi({
73+
method: 'GET',
74+
alias: 'tenantValidationApi',
75+
urlPattern: /\/api\/tenants\?filter\[\]=name=.*&expand=resources/,
76+
triggerFn: () => cy.toolbar(CONFIG_TOOLBAR_BUTTON, configOption),
77+
});
78+
}
79+
80+
function openEditTenantFormAndWaitForLoad(configOption) {
81+
// Tenant edit form triggers two API calls in sequence:
82+
// 1. Load existing tenant data (happens first in useEffect, in ops-tenant-form.jsx)
83+
// 2. Form validation API (happens after load completes and form renders with validateOnMount: true)
84+
// The form doesn't render until isLoading=false, so validation always happens after the form loads.
85+
cy.intercept('GET', /\/api\/tenants\/\d+\?expand=resources&attributes=/).as('tenantLoadApi');
86+
cy.intercept('GET', /\/api\/tenants\?filter\[\]=name=.*&expand=resources/).as('tenantValidationApi');
87+
88+
cy.toolbar(CONFIG_TOOLBAR_BUTTON, configOption);
89+
90+
// Wait for both API calls to complete in order
91+
// Load API must complete first (component logic ensures this)
92+
cy.wait('@tenantLoadApi');
93+
cy.wait('@tenantValidationApi');
94+
}
95+
7196
function cancelFormWithOptionalFlashCheck(assertFlashMessage = true) {
7297
cy.getFormButtonByTypeWithText({
7398
buttonText: CANCEL_BUTTON_TEXT,
@@ -162,7 +187,7 @@ function validateFormElements(isEditForm = true) {
162187
}
163188

164189
function createAndSelectChildTenant() {
165-
cy.toolbar(CONFIG_TOOLBAR_BUTTON, ADD_CHILD_TENANT_CONFIG_OPTION);
190+
openTenantFormAndWaitForValidation(ADD_CHILD_TENANT_CONFIG_OPTION);
166191
updateNameAndDescription(
167192
INITIAL_CHILD_TENANT_NAME,
168193
INITIAL_CHILD_TENANT_DESCRIPTION
@@ -186,7 +211,7 @@ function resetParentTenantForm() {
186211
// Check if the text matches the edited parent tenant name, if yes reset
187212
if (text === EDITED_TENANT_NAME_VALUE) {
188213
cy.wrap(item).click();
189-
cy.toolbar(CONFIG_TOOLBAR_BUTTON, EDIT_TENANT_CONFIG_OPTION);
214+
openEditTenantFormAndWaitForLoad(EDIT_TENANT_CONFIG_OPTION);
190215
updateNameAndDescription(
191216
INITIAL_PARENT_TENANT_NAME,
192217
INITIAL_PARENT_TENANT_DESCRIPTION
@@ -229,7 +254,7 @@ function deleteAccordionItems(accordionsToDelete) {
229254
}
230255

231256
function addProjectToTenant() {
232-
cy.toolbar(CONFIG_TOOLBAR_BUTTON, ADD_PROJECT_CONFIG_OPTION);
257+
openTenantFormAndWaitForValidation(ADD_PROJECT_CONFIG_OPTION);
233258
updateNameAndDescription(PROJECT_NAME_VALUE, EDITED_DESCRIPTION_VALUE);
234259
saveFormWithOptionalFlashCheck({
235260
button: ADD_BUTTON_TEXT,
@@ -275,7 +300,7 @@ describe('Automate Tenant form operations: Settings > Application Settings > Acc
275300
describe('Validate Parent Tenant operations: Edit, Add Project, Manage Quotas', () => {
276301
describe('Validate Edit parent tenant', () => {
277302
beforeEach(() => {
278-
cy.toolbar(CONFIG_TOOLBAR_BUTTON, EDIT_TENANT_CONFIG_OPTION);
303+
openEditTenantFormAndWaitForLoad(EDIT_TENANT_CONFIG_OPTION);
279304
});
280305

281306
afterEach(() => {
@@ -347,7 +372,7 @@ describe('Automate Tenant form operations: Settings > Application Settings > Acc
347372
describe('Validate Child Tenant operations: Add, Edit, Add Project, Manage Quotas', () => {
348373
describe('Validate Add child tenant function', () => {
349374
beforeEach(() => {
350-
cy.toolbar(CONFIG_TOOLBAR_BUTTON, ADD_CHILD_TENANT_CONFIG_OPTION);
375+
openTenantFormAndWaitForValidation(ADD_CHILD_TENANT_CONFIG_OPTION);
351376
});
352377

353378
afterEach(() => {
@@ -364,7 +389,7 @@ describe('Automate Tenant form operations: Settings > Application Settings > Acc
364389
INITIAL_CHILD_TENANT_DESCRIPTION
365390
);
366391
cancelFormWithOptionalFlashCheck();
367-
cy.toolbar(CONFIG_TOOLBAR_BUTTON, ADD_CHILD_TENANT_CONFIG_OPTION);
392+
openTenantFormAndWaitForValidation(ADD_CHILD_TENANT_CONFIG_OPTION);
368393
updateNameAndDescription(
369394
INITIAL_CHILD_TENANT_NAME,
370395
INITIAL_CHILD_TENANT_DESCRIPTION
@@ -387,7 +412,7 @@ describe('Automate Tenant form operations: Settings > Application Settings > Acc
387412
button: ADD_BUTTON_TEXT,
388413
flashMessageSnippet: FLASH_MESSAGE_ADDED,
389414
});
390-
cy.toolbar(CONFIG_TOOLBAR_BUTTON, ADD_CHILD_TENANT_CONFIG_OPTION);
415+
openTenantFormAndWaitForValidation(ADD_CHILD_TENANT_CONFIG_OPTION);
391416
cy.getFormInputFieldByIdAndType({ inputId: 'name' }).type(
392417
INITIAL_CHILD_TENANT_NAME
393418
);
@@ -401,7 +426,7 @@ describe('Automate Tenant form operations: Settings > Application Settings > Acc
401426
describe('Validate Edit child tenant', () => {
402427
beforeEach(() => {
403428
createAndSelectChildTenant();
404-
cy.toolbar(CONFIG_TOOLBAR_BUTTON, EDIT_TENANT_CONFIG_OPTION);
429+
openEditTenantFormAndWaitForLoad(EDIT_TENANT_CONFIG_OPTION);
405430
});
406431

407432
afterEach(() => {

0 commit comments

Comments
 (0)