From 5773c9708c02e248d5da42a7391534dbc57742dd Mon Sep 17 00:00:00 2001 From: Alican Erdurmaz Date: Thu, 12 Dec 2024 14:58:40 +0300 Subject: [PATCH 1/4] fix: flacky e2e tests --- .../table-material-ui-data-grid-pro/all.cy.ts | 2 +- .../table-material-ui-use-data-grid/all.cy.ts | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/cypress/e2e/table-material-ui-data-grid-pro/all.cy.ts b/cypress/e2e/table-material-ui-data-grid-pro/all.cy.ts index 0b39fdf68930..e1858e4e4534 100644 --- a/cypress/e2e/table-material-ui-data-grid-pro/all.cy.ts +++ b/cypress/e2e/table-material-ui-data-grid-pro/all.cy.ts @@ -58,7 +58,7 @@ describe("table-material-ui-data-grid-pro", () => { cy.get(".MuiDataGrid-menuIcon > button").click({ force: true }), ); // click the filter menu item - cy.contains("Filter").click(); + cy.contains("Filter").click({ force: true }); // type the filter value cy.get("[placeholder='Filter value']").type("lorem"); // url should contain the filter diff --git a/cypress/e2e/table-material-ui-use-data-grid/all.cy.ts b/cypress/e2e/table-material-ui-use-data-grid/all.cy.ts index 88fb505e2d0d..0612fad0b3b5 100644 --- a/cypress/e2e/table-material-ui-use-data-grid/all.cy.ts +++ b/cypress/e2e/table-material-ui-use-data-grid/all.cy.ts @@ -57,7 +57,9 @@ describe("table-material-ui-use-data-grid", () => { cy.get(".MuiDataGrid-menuIcon > button").click({ force: true }), ); - cy.get(".MuiDataGrid-menu > div > .MuiList-root").children().eq(3).click(); + cy.get(".MuiDataGrid-menu > div > .MuiList-root").children().eq(3).click({ + force: true, + }); cy.intercept( { @@ -147,7 +149,10 @@ describe("table-material-ui-use-data-grid", () => { cy.get(".MuiDataGrid-menuIcon > button").click({ force: true }), ); - cy.get(".MuiDataGrid-menu > div > .MuiList-root").children().eq(3).click(); + cy.get(".MuiDataGrid-menu > div > .MuiList-root") + .children() + .eq(3) + .click({ force: true }); cy.get("[placeholder='Filter value']").type("lorem"); @@ -155,9 +160,10 @@ describe("table-material-ui-use-data-grid", () => { }); it("should update a cell", () => { + cy.wait("@getPosts"); cy.getMaterialUILoadingCircular().should("not.exist"); - cy.intercept("/posts/*").as("patchRequest"); + cy.interceptPATCHPost(); cy.getMaterialUIColumnHeader(1).click(); @@ -168,9 +174,14 @@ describe("table-material-ui-use-data-grid", () => { ) .clear() .type("Lorem ipsum refine!") + .focus() .type("{enter}"); - cy.wait("@patchRequest"); + cy.wait("@patchPost").then((interception) => { + const request = interception.request; + const body = request.body; + expect(body.title).to.eq("Lorem ipsum refine!"); + }); cy.get(".MuiDataGrid-cell").eq(1).should("contain", "Lorem ipsum refine!"); }); From ce62b0661f529695e42eaa5b9d9b88eba97f2c70 Mon Sep 17 00:00:00 2001 From: Alican Erdurmaz Date: Thu, 12 Dec 2024 15:48:07 +0300 Subject: [PATCH 2/4] fix: flaky tests --- .../table-material-ui-data-grid-pro/all.cy.ts | 7 +++- .../table-material-ui-use-data-grid/all.cy.ts | 33 ++++++++++--------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/cypress/e2e/table-material-ui-data-grid-pro/all.cy.ts b/cypress/e2e/table-material-ui-data-grid-pro/all.cy.ts index e1858e4e4534..68a607d57154 100644 --- a/cypress/e2e/table-material-ui-data-grid-pro/all.cy.ts +++ b/cypress/e2e/table-material-ui-data-grid-pro/all.cy.ts @@ -4,11 +4,13 @@ describe("table-material-ui-data-grid-pro", () => { beforeEach(() => { cy.interceptGETPosts(); + cy.interceptGETCategories(); cy.visit("/"); }); it("should work with sorter", () => { cy.wait("@getPosts"); + cy.wait("@getCategories"); cy.getMaterialUILoadingCircular().should("not.exist"); // sort by title @@ -49,9 +51,12 @@ describe("table-material-ui-data-grid-pro", () => { }); it("should work with multiple filter", () => { - // wait for loading + // wait for requests cy.wait("@getPosts"); + cy.wait("@getCategories"); + // wait for loadings cy.getMaterialUILoadingCircular().should("not.exist"); + cy.get("[data-field='category.id']").should("not.contain", "Loading..."); // open the column menu of title cy.getMaterialUIColumnHeader(2).within(() => diff --git a/cypress/e2e/table-material-ui-use-data-grid/all.cy.ts b/cypress/e2e/table-material-ui-use-data-grid/all.cy.ts index 0612fad0b3b5..a71b8db31629 100644 --- a/cypress/e2e/table-material-ui-use-data-grid/all.cy.ts +++ b/cypress/e2e/table-material-ui-use-data-grid/all.cy.ts @@ -51,36 +51,37 @@ describe("table-material-ui-use-data-grid", () => { }); it("should work with filter", () => { + // wait for requests + cy.wait("@getPosts"); + cy.wait("@getCategories"); + // wait for loadings cy.getMaterialUILoadingCircular().should("not.exist"); + cy.get("[data-field='category.id']").should("have.length", 16); + cy.get("[data-field='category.id']").should("not.contain", "Loading..."); + // find the filter button cy.getMaterialUIColumnHeader(2).within(() => cy.get(".MuiDataGrid-menuIcon > button").click({ force: true }), ); - + // find the filter option cy.get(".MuiDataGrid-menu > div > .MuiList-root").children().eq(3).click({ force: true, }); - - cy.intercept( - { - url: "/posts*", - query: { - title_like: "lorem", - }, - }, - { - fixture: "posts.json", - }, - ).as("getFilteredPosts"); - + // wait for the request again because initial filter is removed and MUI is refreshing the data. + cy.wait("@getPosts"); + // type the filter value cy.get("[placeholder='Filter value']").type("lorem"); + // url should contain the filter cy.url().should( "include", "filters[0][field]=title&filters[0][value]=lorem&filters[0][operator]=contains", ); - - cy.wait("@getFilteredPosts"); + // check the request for the filter + cy.wait("@getPosts").then((interception) => { + const request = interception.request; + const query = request.query; + }); }); it("should work with pagination", () => { From f715faf1c1851e74d85c95ba5b5a9fe7aef4f448 Mon Sep 17 00:00:00 2001 From: Alican Erdurmaz Date: Thu, 12 Dec 2024 16:25:12 +0300 Subject: [PATCH 3/4] fix: flaky tests --- cypress/e2e/table-material-ui-use-data-grid/all.cy.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/cypress/e2e/table-material-ui-use-data-grid/all.cy.ts b/cypress/e2e/table-material-ui-use-data-grid/all.cy.ts index a71b8db31629..4edebb397996 100644 --- a/cypress/e2e/table-material-ui-use-data-grid/all.cy.ts +++ b/cypress/e2e/table-material-ui-use-data-grid/all.cy.ts @@ -81,6 +81,7 @@ describe("table-material-ui-use-data-grid", () => { cy.wait("@getPosts").then((interception) => { const request = interception.request; const query = request.query; + expect(query.title_like).to.eq("lorem"); }); }); From 99393b41bd0f0f061b88bfee661adbff04eb374b Mon Sep 17 00:00:00 2001 From: Alican Erdurmaz Date: Thu, 12 Dec 2024 17:25:09 +0300 Subject: [PATCH 4/4] chore: trigger ci