From d10e2b69e2e30ddcc302faf40162984bc2410a97 Mon Sep 17 00:00:00 2001 From: Jannik Pulfer Date: Wed, 13 Nov 2024 16:04:00 +0100 Subject: [PATCH] Move check-in dialog content checks to check-in dialog helper, rewrite crud tests with new methods --- frontend/cypress/e2e/checkIn.cy.ts | 40 ++++---------- frontend/cypress/e2e/crud.cy.ts | 52 +++++++++---------- .../pom-helper/dialogs/checkInDialog.ts | 27 ++++++++++ .../pom-helper/dialogs/objectiveDialog.ts | 6 +++ 4 files changed, 67 insertions(+), 58 deletions(-) diff --git a/frontend/cypress/e2e/checkIn.cy.ts b/frontend/cypress/e2e/checkIn.cy.ts index d65379e6bc..005473fe6f 100644 --- a/frontend/cypress/e2e/checkIn.cy.ts +++ b/frontend/cypress/e2e/checkIn.cy.ts @@ -27,9 +27,10 @@ describe('OKR Check-in e2e tests', () => { .withMetricValues(Unit.PERCENT, '21', '51') .fillKeyresultDescription('This is my description') .submit(); - keyresultDetailPage.visit('Very important keyresult').createCheckIn(); - checkForDialogTextMetric(); - CheckInDialog.do() + keyresultDetailPage + .visit('Very important keyresult') + .createCheckIn() + .checkForDialogTextMetric() .fillMetricCheckInValue('30') .setCheckInConfidence(6) .fillCheckInCommentary('We bought a new house') @@ -87,9 +88,10 @@ describe('OKR Check-in e2e tests', () => { .withOrdinalValues('New house', 'New car', 'New pool') .fillKeyresultDescription('This is my description') .submit(); - keyresultDetailPage.visit('A new ordinal keyresult for our company').createCheckIn(); - checkForDialogTextOrdinal(); - CheckInDialog.do() + keyresultDetailPage + .visit('A new ordinal keyresult for our company') + .createCheckIn() + .checkForDialogTextOrdinal() .selectOrdinalCheckInZone('commit') .setCheckInConfidence(6) .fillCheckInCommentary('There is a new car') @@ -266,37 +268,13 @@ describe('OKR Check-in e2e tests', () => { .fillCheckInCommentary('changeinfo') .fillCheckInInitiatives('initiatives') .submit(); + cy.contains(`Letztes Check-in (${getCurrentDate()})`); keyresultDetailPage.createCheckIn(); cy.contains('Letzter Wert').siblings('div').contains('10%'); }); }); }); -function checkForDialogTextMetric() { - cy.contains('Very important keyresult'); - cy.contains('Check-in erfassen'); - cy.contains('Key Result'); - cy.contains('Neuer Wert'); - cy.contains('Confidence um Target Zone (42%) zu erreichen'); - cy.contains('Abbrechen'); -} - -function checkForDialogTextOrdinal() { - cy.contains('A new ordinal keyresult for our company'); - cy.contains('Check-in erfassen'); - cy.contains('Key Result'); - cy.contains('Fail:'); - cy.contains('Commit / Target / Stretch noch nicht erreicht'); - cy.contains('Commit:'); - cy.contains('Target:'); - cy.contains('Stretch:'); - cy.contains('New car'); - cy.contains('New house'); - cy.contains('New pool'); - cy.contains('Confidence um Target Zone zu erreichen'); - cy.contains('Abbrechen'); -} - function getCurrentDate() { const today = new Date(); const yyyy = today.getFullYear(); diff --git a/frontend/cypress/e2e/crud.cy.ts b/frontend/cypress/e2e/crud.cy.ts index 254a700b23..32b945df3e 100644 --- a/frontend/cypress/e2e/crud.cy.ts +++ b/frontend/cypress/e2e/crud.cy.ts @@ -1,7 +1,12 @@ import * as users from '../fixtures/users.json'; +import CyOverviewPage from '../support/helper/pom-helper/pages/overviewPage'; +import ObjectiveDialog from '../support/helper/pom-helper/dialogs/objectiveDialog'; describe('CRUD operations', () => { + let op = new CyOverviewPage(); + beforeEach(() => { + op = new CyOverviewPage(); cy.loginAsUser(users.gl); cy.visit('/?quarter=2'); }); @@ -11,28 +16,17 @@ describe('CRUD operations', () => { ['draft objective title', 'safe-draft', 'draft-icon.svg'], ].forEach(([objectiveTitle, buttonTestId, icon]) => { it(`Create objective, no keyresults`, () => { - cy.getByTestId('add-objective').first().click(); - cy.fillOutObjective(objectiveTitle, buttonTestId, '3'); + op.addObjective().fillObjectiveTitle(objectiveTitle).selectQuarter('3'); + cy.getByTestId(buttonTestId).click(); cy.visit('/?quarter=3'); - const objective = cy.contains(objectiveTitle).first().parentsUntil('#objective-column').last(); + const objective = op.getObjectiveByName(objectiveTitle); objective.findByTestId('objective-state').should('have.attr', 'src', `assets/icons/${icon}`); }); }); - [ - ['ongoing objective title', 'safe', 'ongoing-icon.svg'], - ['draft objective title', 'safe-draft', 'draft-icon.svg'], - ].forEach(([objectiveTitle, buttonTestId, icon]) => { - it(`Create objective, no keyresults`, () => { - cy.getByTestId('add-objective').first().click(); - cy.fillOutObjective(objectiveTitle, buttonTestId, '3', '', true); - cy.contains('Key Result erfassen'); - }); - }); - it(`Create objective, should display error message`, () => { - cy.getByTestId('add-objective').first().click(); - cy.getByTestId('title').first().type('description').clear(); + op.addObjective(); + cy.getByTestId('title').first().type('title').clear(); cy.contains('Titel muss folgende Länge haben: 2-250 Zeichen'); cy.getByTestId('safe').should('be.disabled'); cy.getByTestId('safe-draft').should('be.disabled'); @@ -41,17 +35,21 @@ describe('CRUD operations', () => { it(`Create objective, cancel`, () => { const objectiveTitle = 'this is a canceled objective'; - cy.getByTestId('add-objective').first().click(); - cy.fillOutObjective(objectiveTitle, 'cancel', '3'); + op.addObjective().selectQuarter('3').cancel(); cy.visit('/?quarter=3'); cy.contains(objectiveTitle).should('not.exist'); }); it(`Delete existing objective`, () => { cy.get('.objective').first().findByTestId('three-dot-menu').click(); - cy.get('.mat-mdc-menu-content').contains('Objective bearbeiten').click(); - cy.getByTestId('delete').click(); - cy.get("button[type='submit']").contains('Ja').click(); + op.selectFromThreeDotMenu('Objective bearbeiten'); + ObjectiveDialog.do() + .deleteObjective() + .checkTitle('Objective löschen') + .checkDescription( + 'Möchtest du dieses Objective wirklich löschen? Zugehörige Key Results werden dadurch ebenfalls gelöscht!', + ) + .submit(); }); it(`Open objective aside via click`, () => { @@ -62,16 +60,16 @@ describe('CRUD operations', () => { it(`update objective`, () => { const updatedTitle = 'This is an updated title'; cy.get('.objective').first().findByTestId('three-dot-menu').click(); - cy.get('.mat-mdc-menu-content').contains('Objective bearbeiten').click(); - cy.fillOutObjective(updatedTitle, 'safe'); - cy.contains(updatedTitle).first(); + op.selectFromThreeDotMenu('Objective bearbeiten'); + ObjectiveDialog.do().fillObjectiveTitle(updatedTitle).submit(); + cy.contains(updatedTitle).should('exist'); }); it(`Duplicate objective`, () => { const duplicatedTitle = 'This is a duplicated objective'; cy.get('.objective').first().findByTestId('three-dot-menu').click(); - cy.get('.mat-mdc-menu-content').contains('Objective duplizieren').click(); - cy.fillOutObjective(duplicatedTitle, 'safe'); - cy.contains(duplicatedTitle).first(); + op.selectFromThreeDotMenu('Objective duplizieren'); + ObjectiveDialog.do().fillObjectiveTitle(duplicatedTitle).submit(); + cy.contains(duplicatedTitle).should('exist'); }); }); diff --git a/frontend/cypress/support/helper/pom-helper/dialogs/checkInDialog.ts b/frontend/cypress/support/helper/pom-helper/dialogs/checkInDialog.ts index f4f1e77beb..91c47d04a6 100644 --- a/frontend/cypress/support/helper/pom-helper/dialogs/checkInDialog.ts +++ b/frontend/cypress/support/helper/pom-helper/dialogs/checkInDialog.ts @@ -45,6 +45,33 @@ export default class CheckInDialog extends Dialog { return this; } + checkForDialogTextMetric() { + cy.contains('Very important keyresult'); + cy.contains('Check-in erfassen'); + cy.contains('Key Result'); + cy.contains('Neuer Wert'); + cy.contains('Confidence um Target Zone (42%) zu erreichen'); + cy.contains('Abbrechen'); + return this; + } + + checkForDialogTextOrdinal() { + cy.contains('A new ordinal keyresult for our company'); + cy.contains('Check-in erfassen'); + cy.contains('Key Result'); + cy.contains('Fail:'); + cy.contains('Commit / Target / Stretch noch nicht erreicht'); + cy.contains('Commit:'); + cy.contains('Target:'); + cy.contains('Stretch:'); + cy.contains('New car'); + cy.contains('New house'); + cy.contains('New pool'); + cy.contains('Confidence um Target Zone zu erreichen'); + cy.contains('Abbrechen'); + return this; + } + override submit() { cy.getByTestId('submit-check-in').click(); } diff --git a/frontend/cypress/support/helper/pom-helper/dialogs/objectiveDialog.ts b/frontend/cypress/support/helper/pom-helper/dialogs/objectiveDialog.ts index efad504a23..32f625a595 100644 --- a/frontend/cypress/support/helper/pom-helper/dialogs/objectiveDialog.ts +++ b/frontend/cypress/support/helper/pom-helper/dialogs/objectiveDialog.ts @@ -1,4 +1,5 @@ import Dialog from './dialog'; +import ConfirmDialog from './confirmDialog'; export default class ObjectiveDialog extends Dialog { fillObjectiveTitle(title: string) { @@ -21,6 +22,11 @@ export default class ObjectiveDialog extends Dialog { return this; } + deleteObjective() { + cy.getByTestId('delete').click(); + return new ConfirmDialog(); + } + submitDraftObjective() { cy.getByTestId('safe-draft').click(); }