From d03a83bd2ebfe4a2591f8902817875a444c274e3 Mon Sep 17 00:00:00 2001 From: Yanick Minder Date: Fri, 8 Nov 2024 09:02:35 +0100 Subject: [PATCH] fix objective-backlog tests --- frontend/cypress/e2e/objective-backlog.cy.ts | 105 ++++--------------- frontend/cypress/e2e/objective.cy.ts | 27 +---- frontend/cypress/e2e/teammanagement.cy.ts | 8 +- frontend/cypress/support/objective-helper.ts | 25 +++++ 4 files changed, 50 insertions(+), 115 deletions(-) create mode 100644 frontend/cypress/support/objective-helper.ts diff --git a/frontend/cypress/e2e/objective-backlog.cy.ts b/frontend/cypress/e2e/objective-backlog.cy.ts index d60a268525..a38fea83e2 100644 --- a/frontend/cypress/e2e/objective-backlog.cy.ts +++ b/frontend/cypress/e2e/objective-backlog.cy.ts @@ -1,4 +1,5 @@ import * as users from '../fixtures/users.json'; +import { getObjectiveByNameAndState, selectFromThreeDotMenu } from '../support/objective-helper'; describe('OKR Objective Backlog e2e tests', () => { beforeEach(() => { @@ -16,10 +17,9 @@ describe('OKR Objective Backlog e2e tests', () => { cy.contains('Als Draft speichern'); cy.getByTestId('safe-draft').click(); - cy.get('Objective in quarter backlog').should('not.exist'); + cy.contains('Objective in quarter backlog').should('not.exist'); cy.visit('/?quarter=999'); - cy.contains('Objective in quarter backlog'); }); @@ -27,22 +27,14 @@ describe('OKR Objective Backlog e2e tests', () => { cy.getByTestId('add-objective').first().click(); cy.fillOutObjective('Move to another quarter on edit', 'safe-draft', undefined, '', false); - cy.getByTestId('objective') - .filter(':contains("Move to another quarter on edit")') - .last() - .findByTestId('three-dot-menu') - .click() - .wait(500) - .get('.objective-menu-option') - .contains('Objective bearbeiten') - .click(); + getObjectiveByNameAndState('Move to another quarter on edit', 'draft').findByTestId('three-dot-menu').click(); + selectFromThreeDotMenu('Objective bearbeiten'); cy.fillOutObjective('This goes now to backlog', 'safe', 'Backlog', '', false); - cy.get('This goes now to backlog').should('not.exist'); + cy.contains('This goes now to backlog').should('not.exist'); cy.visit('/?quarter=999'); - cy.contains('This goes now to backlog'); }); @@ -50,15 +42,8 @@ describe('OKR Objective Backlog e2e tests', () => { cy.getByTestId('add-objective').first().click(); cy.fillOutObjective('We can not move this to backlog', 'safe', undefined, '', false); - cy.getByTestId('objective') - .filter(':contains("We can not move this to backlog")') - .last() - .findByTestId('three-dot-menu') - .click() - .wait(500) - .get('.objective-menu-option') - .contains('Objective bearbeiten') - .click(); + getObjectiveByNameAndState('We can not move this to backlog', 'ongoing').findByTestId('three-dot-menu').click(); + selectFromThreeDotMenu('Objective bearbeiten'); cy.get('select#quarter').should('contain', 'GJ ForTests'); cy.get('select#quarter').should('not.contain', 'Backlog'); @@ -67,25 +52,12 @@ describe('OKR Objective Backlog e2e tests', () => { it(`Can release Objective to another quarter from backlog`, () => { cy.visit('/?quarter=999'); cy.getByTestId('add-objective').first().click(); - cy.getByTestId('title').first().clear().type('We can not release this'); - cy.getByTestId('safe').should('not.exist'); - cy.getByTestId('safe-draft').click(); + cy.fillOutObjective('We can not release this', 'safe-draft', 'Backlog', '', false); - cy.getByTestId('objective') - .filter(':contains("We can not release this")') - .last() - .findByTestId('three-dot-menu') - .click(); + getObjectiveByNameAndState('We can not release this', 'draft').findByTestId('three-dot-menu').click(); + selectFromThreeDotMenu('Objective veröffentlichen'); - cy.wait(500); - cy.contains('Objective bearbeiten'); - cy.contains('Objective duplizieren'); cy.contains('Objective veröffentlichen'); - - cy.get('.objective-menu-option').contains('Objective veröffentlichen').click(); - - cy.contains('Objective veröffentlichen'); - cy.getByTestId('title').first().clear().type('This is our first released objective'); cy.get('select#quarter').should('not.contain', 'Backlog'); @@ -98,7 +70,6 @@ describe('OKR Objective Backlog e2e tests', () => { cy.contains('This is our first released objective').should('not.exist'); cy.visit('/?quarter=998'); - cy.contains('This is our first released objective'); }); @@ -109,18 +80,10 @@ describe('OKR Objective Backlog e2e tests', () => { cy.contains('This is possible for edit'); - cy.getByTestId('objective') - .filter(':contains("This is possible for edit")') - .last() - .getByTestId('three-dot-menu') - .click() - .wait(500) - .get('.objective-menu-option') - .contains('Objective bearbeiten') - .click(); + getObjectiveByNameAndState('This is possible for edit', 'draft').findByTestId('three-dot-menu').click(); + selectFromThreeDotMenu('Objective bearbeiten'); cy.fillOutObjective('My new title', 'safe', undefined, '', false); - cy.contains('My new title'); }); @@ -129,15 +92,8 @@ describe('OKR Objective Backlog e2e tests', () => { cy.getByTestId('add-objective').first().click(); cy.fillOutObjective('This goes to other quarter later', 'safe-draft', undefined, '', false); - cy.getByTestId('objective') - .filter(':contains("This goes to other quarter later")') - .last() - .getByTestId('three-dot-menu') - .click() - .wait(500) - .get('.objective-menu-option') - .contains('Objective bearbeiten') - .click(); + getObjectiveByNameAndState('This goes to other quarter later', 'draft').findByTestId('three-dot-menu').click(); + selectFromThreeDotMenu('Objective bearbeiten'); cy.get('select#quarter').select('GJ ForTests'); cy.getByTestId('safe').first().click(); @@ -151,30 +107,16 @@ describe('OKR Objective Backlog e2e tests', () => { cy.getByTestId('add-objective').first().click(); cy.fillOutObjective('Ready for duplicate', 'safe-draft', undefined, '', false); - cy.getByTestId('objective') - .filter(':contains("Ready for duplicate")') - .last() - .getByTestId('three-dot-menu') - .click() - .wait(500) - .get('.objective-menu-option') - .contains('Objective duplizieren') - .click(); + getObjectiveByNameAndState('Ready for duplicate', 'draft').findByTestId('three-dot-menu').click(); + selectFromThreeDotMenu('Objective duplizieren'); cy.fillOutObjective('This is a new duplication', 'safe', undefined, '', false); cy.contains('Ready for duplicate'); cy.contains('This is a new duplication'); - cy.getByTestId('objective') - .filter(':contains("Ready for duplicate")') - .last() - .getByTestId('three-dot-menu') - .click() - .wait(500) - .get('.objective-menu-option') - .contains('Objective duplizieren') - .click(); + getObjectiveByNameAndState('Ready for duplicate', 'draft').findByTestId('three-dot-menu').click(); + selectFromThreeDotMenu('Objective duplizieren'); cy.fillOutObjective('New duplication for other quarter', 'safe', 'GJ ForTests', '', false); cy.get('New duplication for other quarter').should('not.exist'); @@ -186,15 +128,8 @@ describe('OKR Objective Backlog e2e tests', () => { cy.getByTestId('add-objective').first().click(); cy.fillOutObjective('Possible to duplicate into backlog', 'safe', undefined, '', false); - cy.getByTestId('objective') - .filter(':contains("Possible to duplicate into backlog")') - .last() - .getByTestId('three-dot-menu') - .click() - .wait(500) - .get('.objective-menu-option') - .contains('Objective duplizieren') - .click(); + getObjectiveByNameAndState('Possible to duplicate into backlog', 'ongoing').findByTestId('three-dot-menu').click(); + selectFromThreeDotMenu('Objective duplizieren'); cy.get('select#quarter').select('Backlog'); cy.getByTestId('safe').first().click(); diff --git a/frontend/cypress/e2e/objective.cy.ts b/frontend/cypress/e2e/objective.cy.ts index 5225df5f97..e447c910c7 100644 --- a/frontend/cypress/e2e/objective.cy.ts +++ b/frontend/cypress/e2e/objective.cy.ts @@ -1,5 +1,6 @@ import * as users from '../fixtures/users.json'; import { onlyOn } from '@cypress/skip-test'; +import { getObjectiveByNameAndState, selectFromThreeDotMenu } from '../support/objective-helper'; describe('OKR Objective e2e tests', () => { describe('tests via click', () => { @@ -181,29 +182,3 @@ describe('tests via keyboard', () => { cy.url().should('include', 'objective'); }); }); - -function getObjectiveByNameAndState(objectiveName: string, state: string) { - return getObjectivesByNameAndState(objectiveName, state).first().should('exist'); -} - -function selectFromThreeDotMenu(optionName: string) { - cy.contains(optionName).should('exist'); - cy.get('.objective-three-dot-menu').contains(optionName).should('have.class', 'objective-menu-option').click(); -} - -function getObjectivesByNameAndState(objectiveName: string, state: string) { - return getObjectiveColumns() - .filter((index, element) => filterByObjectiveName(element, objectiveName)) - .filter((index, element) => filterByState(element, state)); -} - -const filterByState = (element: HTMLElement, icon: string) => { - return Cypress.$(element).find(`[src='assets/icons/${icon}-icon.svg']`).length > 0; -}; -const filterByObjectiveName = (element: HTMLElement, objectiveName: string) => { - return Cypress.$(element).find(`:contains("${objectiveName}")`).length > 0; -}; - -function getObjectiveColumns() { - return cy.get('.objective'); -} diff --git a/frontend/cypress/e2e/teammanagement.cy.ts b/frontend/cypress/e2e/teammanagement.cy.ts index 3e43ea7860..48c0503fa8 100644 --- a/frontend/cypress/e2e/teammanagement.cy.ts +++ b/frontend/cypress/e2e/teammanagement.cy.ts @@ -149,7 +149,7 @@ describe('Team management tests', () => { }); describe('Search', () => { - it('Search user', () => { + it.only('Search user', () => { cy.get('app-team-management-banner').getByTestId('teamManagementSearch').click().type('pa'); cy.contains('.mat-mdc-autocomplete-panel mat-option', 'Paco Eggimann (peggimann@puzzle.ch)'); @@ -159,7 +159,7 @@ describe('Team management tests', () => { cy.contains('app-member-detail h2', 'Robin Papierer'); }); - it('Search team', () => { + it.only('Search team', () => { cy.get('app-team-management-banner').getByTestId('teamManagementSearch').click().type('we are'); cy.contains('.mat-mdc-autocomplete-panel mat-option', 'we are cube.³').click(); @@ -167,7 +167,7 @@ describe('Team management tests', () => { cy.contains('app-member-list h2', 'we are cube.³'); }); - it('Search mixed', () => { + it.only('Search mixed', () => { cy.get('app-team-management-banner').getByTestId('teamManagementSearch').click().type('puz'); cy.contains('.mat-mdc-autocomplete-panel .mat-mdc-optgroup-label', 'Members'); @@ -280,7 +280,7 @@ describe('Team management tests', () => { }); }); - it.only('Navigate to user Esha and set as okr champion', () => { + it('Navigate to user Esha and set as okr champion', () => { navigateToUser(nameEsha); cy.getByTestId('edit-okr-champion-readonly').contains('OKR Champion:'); cy.getByTestId('edit-okr-champion-readonly').contains('Nein'); diff --git a/frontend/cypress/support/objective-helper.ts b/frontend/cypress/support/objective-helper.ts new file mode 100644 index 0000000000..3dc0c80ca4 --- /dev/null +++ b/frontend/cypress/support/objective-helper.ts @@ -0,0 +1,25 @@ +export function getObjectiveByNameAndState(objectiveName: string, state: string) { + return getObjectivesByNameAndState(objectiveName, state).first().should('exist'); +} + +export function selectFromThreeDotMenu(optionName: string) { + cy.contains(optionName).should('exist'); + cy.get('.objective-three-dot-menu').contains(optionName).should('have.class', 'objective-menu-option').click(); +} + +function getObjectivesByNameAndState(objectiveName: string, state: string) { + return getObjectiveColumns() + .filter((index, element) => filterByObjectiveName(element, objectiveName)) + .filter((index, element) => filterByState(element, state)); +} + +const filterByState = (element: HTMLElement, icon: string) => { + return Cypress.$(element).find(`[src='assets/icons/${icon}-icon.svg']`).length > 0; +}; +const filterByObjectiveName = (element: HTMLElement, objectiveName: string) => { + return Cypress.$(element).find(`:contains("${objectiveName}")`).length > 0; +}; + +function getObjectiveColumns() { + return cy.get('.objective'); +} \ No newline at end of file