Skip to content

Commit

Permalink
test: wait for form data to be loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed May 17, 2024
1 parent 97befc5 commit 72be996
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions cypress-tests/cypress/e2e/admin/i18n/createLocale.cy.js
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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");
Expand Down Expand Up @@ -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.
Expand All @@ -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");
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 72be996

Please sign in to comment.