From 557b08d2ce3a7b4dc1d536d84a824fcb0b46784f Mon Sep 17 00:00:00 2001 From: Manuel Date: Wed, 4 Dec 2024 16:01:41 +0100 Subject: [PATCH] Finish e2e tests for duplicating --- .../cypress/e2e/duplicate-objective.cy.ts | 192 +++++++++--------- .../dom-helper/dialogs/objectiveDialog.ts | 7 + .../helper/dom-helper/pages/overviewPage.ts | 8 +- 3 files changed, 113 insertions(+), 94 deletions(-) diff --git a/frontend/cypress/e2e/duplicate-objective.cy.ts b/frontend/cypress/e2e/duplicate-objective.cy.ts index 40eb755140..c31ed22295 100644 --- a/frontend/cypress/e2e/duplicate-objective.cy.ts +++ b/frontend/cypress/e2e/duplicate-objective.cy.ts @@ -10,111 +10,117 @@ beforeEach(() => { cy.loginAsUser(users.gl); }); -describe('Functionality of duplicating objectives and their belonging keyresults', () => { - it('Should be able to duplicate a objective into this quarter, including all keyresults', () => { +describe('Functionality of duplicating objectives and their belonging keyResults', () => { + const firstKeyResultName = 'New structure that rewards funny guys and innovation before the end of Q1.'; + const secondKeyResultName = 'Monthly town halls between our people and leadership teams over the next four months.'; + const thirdKeyResultName = 'High employee satisfaction scores (80%+) throughout the year.'; + + it('Should be able to duplicate a objective into this quarter, including all keyResults', () => { const duplicatedTitle = 'This is a duplicated objective with all keyResults'; + overviewPage - .getObjectiveByName('Build a company culture that kills the competition.') - .findByTestId('three-dot-menu') - .click(); - overviewPage.selectFromThreeDotMenu('Objective duplizieren'); - ObjectiveDialog.do().fillObjectiveTitle(duplicatedTitle).submit(); + .duplicateObjective('Build a company culture that kills the competition.') + .fillObjectiveTitle(duplicatedTitle) + .submit(); + + cy.contains(duplicatedTitle); + overviewPage.getKeyResultOfObjective(duplicatedTitle, firstKeyResultName).should('exist'); + overviewPage.getKeyResultOfObjective(duplicatedTitle, secondKeyResultName).should('exist'); + overviewPage.getKeyResultOfObjective(duplicatedTitle, thirdKeyResultName).should('exist'); + }); + + it('Should be able to duplicate a objective into this quarter, only including one keyResult', () => { + const duplicatedTitle = 'This is a duplicated objective with one keyResult'; - cy.contains('This is a default duplicated objective'); overviewPage - .getKeyresultOfObjective( - 'This is a duplicated objective with all keyResults', - 'New structure that rewards funny guys and innovation before the end of Q1.', - ) - .should('exist'); + .duplicateObjective('Build a company culture that kills the competition.') + .fillObjectiveTitle(duplicatedTitle) + .excludeKeyResults([secondKeyResultName, thirdKeyResultName]) + .submit(); + + overviewPage.getKeyResultOfObjective(duplicatedTitle, firstKeyResultName); + overviewPage - .getKeyresultOfObjective( - 'This is a duplicated objective with all keyResults', - 'Monthly town halls between our people and leadership teams over the next four months.', - ) - .should('exist'); + .getAllKeyResultsOfObjective(duplicatedTitle) + .should('not.contain', secondKeyResultName) + .should('not.contain', thirdKeyResultName); + }); + + it('Should be able to duplicate a objective into the next quarter, including all keyResults', () => { + const duplicatedTitle = 'This is a default objective with all keyResults in quarter 3!'; + overviewPage - .getKeyresultOfObjective( - 'This is a duplicated objective with all keyResults', - 'High employee satisfaction scores (80%+) throughout the year.', - ) - .should('exist'); + .duplicateObjective('Build a company culture that kills the competition.') + .fillObjectiveTitle(duplicatedTitle) + .selectQuarter('3') + .submit(); + + overviewPage.visitNextQuarter(); + + cy.contains(duplicatedTitle); + overviewPage.getKeyResultOfObjective(duplicatedTitle, firstKeyResultName).should('exist'); + overviewPage.getKeyResultOfObjective(duplicatedTitle, secondKeyResultName).should('exist'); + overviewPage.getKeyResultOfObjective(duplicatedTitle, thirdKeyResultName).should('exist'); }); - it('Should be able to duplicate a objective into this quarter, only including one keyresult', () => { - const duplicatedTitle = 'This is a duplicated objective with one keyResult'; + it('Should not duplicate objective when cancel button is clicked', () => { + const duplicatedTitle = 'This is a never existing objective'; + overviewPage - .getObjectiveByName('Build a company culture that kills the competition.') - .findByTestId('three-dot-menu') - .click(); - overviewPage.selectFromThreeDotMenu('Objective duplizieren'); - ObjectiveDialog.do().fillObjectiveTitle(duplicatedTitle).submit(); + .duplicateObjective('Build a company culture that kills the competition.') + .fillObjectiveTitle(duplicatedTitle) + .fillObjectiveDescription('Wow this is a very nice description!') + .cancel(); + + cy.contains(duplicatedTitle).should('not.exist'); + }); +}); - cy.contains('This is a duplicated objective with one keyResult'); +describe('e2e test for scoring adjustment on duplicate objective', () => { + let keyresultDetailPage = new KeyResultDetailPage(); + + it('Duplicate ordinal checkin and validate value of scoring component', () => { overviewPage - .getKeyresultOfObjective( - 'This is a duplicated objective with one keyResult', - 'New structure that rewards funny guys and innovation before the end of Q1.', - ) - .should('exist'); + .addKeyResult('Puzzle ITC', 'Wir wollen die Kundenzufriedenheit steigern') + .fillKeyResultTitle('stretch keyresult for testing') + .withOrdinalValues('Ex. val', 'Ex. val', 'Ex. val') + .submit(); + + cy.contains('stretch keyresult for testing'); + keyresultDetailPage + .visit('stretch keyresult for testing') + .createCheckIn() + .selectOrdinalCheckInZone('stretch') + .setCheckInConfidence(8) + .fillCheckInCommentary('Testveränderungen') + .fillCheckInInitiatives('Testmassnahmen') + .submit(); + + cy.intercept('GET', '**/overview?*').as('indexPage'); + keyresultDetailPage.close(); + cy.wait('@indexPage'); + overviewPage - .getKeyresultOfObjective( - 'This is a duplicated objective with one keyResult', - 'Monthly town halls between our people and leadership teams over the next four months.', - ) - .should('not.exist'); + .duplicateObjective('Wir wollen die Kundenzufriedenheit steigern') + .fillObjectiveTitle('A duplicated Objective for this tool') + .selectQuarter('3') + .submit(); + + overviewPage.checkForToaster('Das Objective wurde erfolgreich erstellt.', 'success'); + + overviewPage.visitNextQuarter(); + overviewPage - .getKeyresultOfObjective( - 'This is a duplicated objective with one keyResult', - 'High employee satisfaction scores (80%+) throughout the year.', - ) - .should('not.exist'); + .getKeyResultByName('stretch keyresult for testing') + .findByTestId('scoring-component') + .findByTestId('fail') + .as('fail-area'); + + cy.get('@fail-area').should(($fail) => { + expect($fail).not.to.have.css('score-red'); + expect($fail).not.to.have.css('score-yellow'); + expect($fail).not.to.have.css('score-green'); + expect($fail).not.to.have.css('score-stretch'); + }); }); }); - -// describe('e2e test for scoring adjustment on duplicate objective', () => { -// it('Duplicate ordinal checkin and validate value of scoring component', () => { -// overviewPage -// .addKeyResult('Puzzle ITC', 'Wir wollen die Kundenzufriedenheit steigern') -// .fillKeyResultTitle('stretch keyresult for testing') -// .withOrdinalValues('Ex. val', 'Ex. val', 'Ex. val') -// .submit(); -// -// cy.contains('stretch keyresult for testing'); -// keyresultDetailPage -// .visit('stretch keyresult for testing') -// .createCheckIn() -// .selectOrdinalCheckInZone('stretch') -// .setCheckInConfidence(8) -// .fillCheckInCommentary('Testveränderungen') -// .fillCheckInInitiatives('Testmassnahmen') -// .submit(); -// -// cy.intercept('GET', '**/overview?*').as('indexPage'); -// keyresultDetailPage.close(); -// cy.wait('@indexPage'); -// -// overviewPage -// .duplicateObjective('Wir wollen die Kundenzufriedenheit steigern') -// .fillObjectiveTitle('A duplicated Objective for this tool') -// .selectQuarter('3') -// .submit(); -// -// overviewPage.checkForToaster('Das Objective wurde erfolgreich erstellt.', 'success'); -// -// overviewPage.visitNextQuarter(); -// -// overviewPage -// .getKeyResultByName('stretch keyresult for testing') -// .findByTestId('scoring-component') -// .findByTestId('fail') -// .as('fail-area'); -// -// cy.get('@fail-area').should(($fail) => { -// expect($fail).not.to.have.css('score-red'); -// expect($fail).not.to.have.css('score-yellow'); -// expect($fail).not.to.have.css('score-green'); -// expect($fail).not.to.have.css('score-stretch'); -// }); -// }); -// }); diff --git a/frontend/cypress/support/helper/dom-helper/dialogs/objectiveDialog.ts b/frontend/cypress/support/helper/dom-helper/dialogs/objectiveDialog.ts index dafddcea5e..5b06bb359f 100644 --- a/frontend/cypress/support/helper/dom-helper/dialogs/objectiveDialog.ts +++ b/frontend/cypress/support/helper/dom-helper/dialogs/objectiveDialog.ts @@ -32,6 +32,13 @@ export default class ObjectiveDialog extends Dialog { cy.getByTestId('save-draft').click(); } + excludeKeyResults(keyResults: string[]) { + keyResults.forEach((keyResult) => { + cy.get('label').contains(keyResult.slice(0, 15)).click(); + }); + return this; + } + getPage(): Chainable { return cy.get('app-objective-form').should('exist'); } diff --git a/frontend/cypress/support/helper/dom-helper/pages/overviewPage.ts b/frontend/cypress/support/helper/dom-helper/pages/overviewPage.ts index 732423a699..3be3fc5f56 100644 --- a/frontend/cypress/support/helper/dom-helper/pages/overviewPage.ts +++ b/frontend/cypress/support/helper/dom-helper/pages/overviewPage.ts @@ -92,7 +92,7 @@ export default class CyOverviewPage extends Page { return cy.get('@team'); } - getKeyresultOfObjective(objectiveName: string, keyResultName: string) { + getKeyResultOfObjective(objectiveName: string, keyResultName: string) { return this.getObjectiveByName(objectiveName) .last() .find('.key-result') @@ -100,6 +100,10 @@ export default class CyOverviewPage extends Page { .last(); } + getAllKeyResultsOfObjective(objectiveName: string) { + return this.getObjectiveByName(objectiveName).find('.key-result'); + } + getObjectivesByName(objectiveName: string) { return getObjectiveColumns().filter(filterByObjectiveName(objectiveName)); } @@ -130,8 +134,10 @@ export default class CyOverviewPage extends Page { } duplicateObjective(objectiveName: string) { + cy.intercept('GET', '**/objectives/*/keyResults').as('keyResults'); this.getObjectiveByName(objectiveName).findByTestId('three-dot-menu').click(); this.selectFromThreeDotMenu('Objective duplizieren'); + cy.wait('@keyResults'); return new ObjectiveDialog(); }