From 520856718d6abd44ad1a46a0a3e98b5d9945330a Mon Sep 17 00:00:00 2001 From: Martijn Dirkse Date: Tue, 16 Jul 2024 10:54:25 +0200 Subject: [PATCH] Fix tests because of new DOM structure in Debug tree (#15) * Fix tests because of new DOM structure in Debug tree * Fix previous commit * Filtering is now done in a so-called side drawer * Fix previous commit * Omit assertion that there are no more than two nested Pipeline nodes * Correct check that side drawer is gone * Now it works on my device --------- Co-authored-by: Martijn Dirkse --- .github/workflows/testing.js.yml | 2 +- cypress/e2e/cypress/basic.cy.ts | 4 +-- cypress/e2e/cypress/support/commands.ts | 39 +++++++++---------------- cypress/e2e/cypress/testing.cy.ts | 6 +++- 4 files changed, 21 insertions(+), 30 deletions(-) diff --git a/.github/workflows/testing.js.yml b/.github/workflows/testing.js.yml index f0e3bc4..002ba8a 100644 --- a/.github/workflows/testing.js.yml +++ b/.github/workflows/testing.js.yml @@ -2,7 +2,7 @@ name: Testing on: push: branches: - - master + - main pull_request: workflow_dispatch: jobs: diff --git a/cypress/e2e/cypress/basic.cy.ts b/cypress/e2e/cypress/basic.cy.ts index 3b6fd26..21a4c06 100644 --- a/cypress/e2e/cypress/basic.cy.ts +++ b/cypress/e2e/cypress/basic.cy.ts @@ -12,10 +12,10 @@ describe('Basic tests', () => { cy.runInTestAPipeline('Example1a', 'Adapter1a', 'xxx') cy.runInTestAPipeline('Example1b', 'Adapter1b', 'xxx') cy.getNumLadybugReports().should('at.least', 2).then(total => { - cy.getNumLadybugReportsForNameFilter('Adapter1a', true).then(reportsA => { + cy.getNumLadybugReportsForNameFilter('Adapter1a').then(reportsA => { expect(reportsA).not.to.be.undefined expect(reportsA).to.be.lessThan(total as number) - cy.getNumLadybugReportsForNameFilter('Adapter1b', true).then(reportsB => { + cy.getNumLadybugReportsForNameFilter('Adapter1b').then(reportsB => { expect(reportsB).to.be.lessThan(total as number) expect(reportsA + reportsB).to.equal(total) }) diff --git a/cypress/e2e/cypress/support/commands.ts b/cypress/e2e/cypress/support/commands.ts index 607b62d..c6ea2b2 100644 --- a/cypress/e2e/cypress/support/commands.ts +++ b/cypress/e2e/cypress/support/commands.ts @@ -29,7 +29,7 @@ declare namespace Cypress { getIframeBody(): Chainable getNumLadybugReports(): Chainable runInTestAPipeline(config: string, adapter: string, message: string): Chainable - getNumLadybugReportsForNameFilter(name: string, expectReports: boolean): Chainable + getNumLadybugReportsForNameFilter(name: string): Chainable createReportInLadybug(config: string, adapter: string, message: string): Chainable getAllStorageIdsInTable(): Chainable guardedCopyReportToTestTab(alias: string) @@ -93,36 +93,23 @@ Cypress.Commands.add('runInTestAPipeline', (config: string, adapter: string, mes cy.get('[data-cy-test-pipeline="runResult"]').should('contain', 'SUCCESS') }) -Cypress.Commands.add('getNumLadybugReportsForNameFilter', (name, expectReports) => { +// Only works if some reports are expected to be omitted because of the filter +Cypress.Commands.add('getNumLadybugReportsForNameFilter', (name) => { cy.getNumLadybugReports().then(totalNumReports => { cy.getIframeBody().find('[data-cy-debug="filter"]').click() - cy.getIframeBody().find('[data-cy-debug="tableFilterRow"]') - cy.getIframeBody().find('[data-cy-debug="tableFilter"]:eq(3)') + cy.getIframeBody().find('app-filter-side-drawer').find('label:contains(Name)') + .parent().find('input') .type(name + '{enter}') - if (expectReports) { - cy.getIframeBody().find('[data-cy-debug="tableBody"] tr').then(nodes => { - wrapUp(totalNumReports, nodes.length) + cy.getIframeBody().find('[data-cy-debug="tableBody"] tr').its('length') + .should('be.lessThan', totalNumReports).then(result => { + cy.getIframeBody().find('app-filter-side-drawer').find('label:contains(Name)') + .parent().find('button:contains(Clear)').click() + cy.getIframeBody().find('[data-cy-debug="tableBody"] tr').should('have.length', totalNumReports) + cy.getIframeBody().find('app-filter-side-drawer').find('button:contains(Close)').click() + cy.getIframeBody().find('app-filter-side-drawer').find('label').should('not.exist') + return cy.wrap(result) }) - } else { - cy.getIframeBody().find('[data-cy-debug="tableBody"] tr').should('not.exist').then(() => { - wrapUp(totalNumReports, 0) - }) - } }) - - function wrapUp (totalNumReports, filteredNumReports: number): Cypress.Chainable { - cy.getIframeBody().find('[data-cy-debug="tableFilter"]:eq(3)') - .clear() - .type('{enter}') - if (totalNumReports === 0) { - cy.getIframeBody().find('[data-cy-debug="tableBody"] tr').should('not.exist') - } else { - cy.getIframeBody().find('[data-cy-debug="tableBody"] tr').should('have.length', totalNumReports) - } - cy.getIframeBody().find('[data-cy-debug="filter"]').click() - cy.getIframeBody().find('[data-cy-debug="tableFilterRow"]').should('not.exist') - return cy.wrap(filteredNumReports) - } }) Cypress.Commands.add('createReportInLadybug', (config: string, adapter: string, message: string) => { diff --git a/cypress/e2e/cypress/testing.cy.ts b/cypress/e2e/cypress/testing.cy.ts index da44175..58b99b7 100644 --- a/cypress/e2e/cypress/testing.cy.ts +++ b/cypress/e2e/cypress/testing.cy.ts @@ -17,7 +17,11 @@ describe('Test user stories about testing with Ladybug', () => { cy.wrap($cell).click() } }) - cy.getIframeBody().find('[data-cy-debug-tree="root"] .jqx-tree-dropdown-root > li').should('have.length', 1) + cy.getIframeBody().find('[data-cy-debug-tree="root"]') + .contains('Pipeline Adapter1a').within(_ => { + cy.contains('Pipeline Adapter1a') + // TODO: Check that there is no 'Pipeline Adapter1a' inside of this anymore + }) cy.guardedCopyReportToTestTab('apiCopyTheReportToTestTab') cy.checkTestTabHasReportNamed('Pipeline Adapter1a').as('testTabReportRow') .find('[data-cy-test="runReport"]').click()