From 72be99655b9318994725b6402deaff71d6ac2ee2 Mon Sep 17 00:00:00 2001 From: Pavel Denisjuk Date: Fri, 17 May 2024 21:15:28 +0200 Subject: [PATCH] test: wait for form data to be loaded --- .../cypress/e2e/admin/i18n/createLocale.cy.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/cypress-tests/cypress/e2e/admin/i18n/createLocale.cy.js b/cypress-tests/cypress/e2e/admin/i18n/createLocale.cy.js index ad9ddb7548a..8d2dfd6d230 100644 --- a/cypress-tests/cypress/e2e/admin/i18n/createLocale.cy.js +++ b/cypress-tests/cypress/e2e/admin/i18n/createLocale.cy.js @@ -1,6 +1,8 @@ context("I18N app", () => { beforeEach(() => cy.login()); + const getFormContainer = () => cy.findByTestId("i18n-locale-form"); + it("should create a locale, select, unselect and immediately delete everything", () => { const newCode = "de-DE"; @@ -20,7 +22,6 @@ context("I18N app", () => { cy.findByText(newCode).as("code").should("exist"); }); cy.get("@code").click(); - cy.wait(20); cy.findByTestId("l18n.locale.save").click(); // Loading should be completed cy.get(".react-spinner-material").should("not.exist"); @@ -79,9 +80,7 @@ context("I18N app", () => { // Create new locale cy.findAllByTestId("new-record-button").first().click(); - const formContainer = cy.findByTestId("i18n-locale-form"); - - formContainer.within(() => { + getFormContainer().within(() => { cy.findByTestId("l18n.locale.code").focus().type(newCode); /** * Testing "Autocomplete" component is tricky. @@ -94,18 +93,23 @@ context("I18N app", () => { cy.get("@code").click(); }); - cy.wait(20); cy.findByTestId("l18n.locale.save").click(); + + // At this point, the browser will reload. + // Loading should be completed cy.get(".react-spinner-material").should("not.exist"); // Check newly created locale in selector cy.findByTestId("app-i18n-content.menu").click(); cy.findByTestId(`app-i18n-content.menu-item.${newCode}`).should("exist"); + // Wait for the form to be fully loaded + getFormContainer().within(() => { + cy.findByText(newCode).should("exist"); + }); // Set it as "Default locale" cy.findByLabelText("Default").click(); // We need to wait a bit, just enough to allow the form to update its internal state, before submitting. // Cypress is clicking the switch button and submit button too fast, and often, the form submits with the previous state. - cy.wait(20); cy.findByTestId("l18n.locale.save").click(); // Wait for loading to complete cy.get(".react-spinner-material").should("not.exist"); @@ -136,9 +140,6 @@ context("I18N app", () => { cy.get(".react-spinner-material").should("not.exist"); // Update it as "default" cy.findByLabelText("Default").click(); - // We need to wait a bit, just enough to allow the form to update its internal state, before submitting. - // Cypress is clicking the switch button and submit button too fast, and often, the form submits with the previous state. - cy.wait(20); cy.findByTestId("l18n.locale.save").click(); // Wait for loading to complete cy.get(".react-spinner-material").should("not.exist");