From fabb5c622cc347650b23758d3bff57f6367d685a Mon Sep 17 00:00:00 2001 From: Georgy Karataev Date: Tue, 7 Mar 2023 11:24:56 +0100 Subject: [PATCH] test: Stabilize cypress component tests (#1785) This rewrites some of the tests and makes sure there are no dangling requests in the browser (testing environment) before the next test is executed. Also, it makes all the component tests run in chrome due to the often errors in CI when using electron (by default). --- package.json | 2 +- src/components/GroupsTable/GroupsTable.cy.js | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 8b13cfd92..88b0b0b1a 100644 --- a/package.json +++ b/package.json @@ -176,7 +176,7 @@ "verify": "npm-run-all build lint test", "nightly": "npm run travis:verify", "start:federated": "fec static --config config/dev.webpack.config.js", - "test:ct": "BABEL_ENV=componentTest cypress run --component", + "test:ct": "BABEL_ENV=componentTest cypress run --component --browser chrome", "test:openct": "BABEL_ENV=componentTest cypress open --component", "test:openct:mock": "MOCK=true npm run test:openct", "coverage": "bash coverage.sh", diff --git a/src/components/GroupsTable/GroupsTable.cy.js b/src/components/GroupsTable/GroupsTable.cy.js index da549e698..f13df86b1 100644 --- a/src/components/GroupsTable/GroupsTable.cy.js +++ b/src/components/GroupsTable/GroupsTable.cy.js @@ -79,6 +79,8 @@ describe('renders correctly', () => { beforeEach(() => { interceptors['successful with some items'](); // comment out if the mock server is running mountTable(); + + cy.wait('@getGroups'); // first initial call }); it('the root container is rendered', () => { @@ -98,10 +100,11 @@ describe('defaults', () => { beforeEach(() => { interceptors['successful with some items'](); mountTable(); + + cy.wait('@getGroups'); // first initial call }); it(`pagination is set to ${DEFAULT_ROW_COUNT}`, () => { - cy.wait('@getGroups'); cy.get('.pf-c-options-menu__toggle-text') .find('b') .eq(0) @@ -117,6 +120,8 @@ describe('pagination', () => { beforeEach(() => { interceptors['successful with some items'](); mountTable(); + + cy.wait('@getGroups'); // first initial call }); it('shows correct total number of groups', () => { @@ -128,7 +133,6 @@ describe('pagination', () => { }); it('can change page limit', () => { - cy.wait('@getGroups'); // first initial call PAGINATION_VALUES.forEach((el) => { changePagination(el).then(() => { cy.wait('@getGroups') @@ -139,7 +143,6 @@ describe('pagination', () => { }); it('can change page', () => { - cy.wait('@getGroups'); cy.get('button[data-action=next]').eq(0).click(); // click "next page" button cy.wait('@getGroups').its('request.url').should('include', `page=2`); }); @@ -149,6 +152,8 @@ describe('sorting', () => { beforeEach(() => { interceptors['successful with some items'](); mountTable(); + + cy.wait('@getGroups'); // first initial call }); const checkSorting = (label, order, dataField) => { @@ -181,6 +186,8 @@ describe('filtering', () => { beforeEach(() => { interceptors['successful with some items'](); mountTable(); + + cy.wait('@getGroups'); // first initial call }); const applyNameFilter = () => @@ -190,6 +197,7 @@ describe('filtering', () => { it('renders filter chip', () => { applyNameFilter(); hasChip('Name', 'lorem'); + cy.wait('@getGroups'); }); it('sends correct request', () => {