From 6a842f34b60129aebf4d6b9ea584cddb6c7132e3 Mon Sep 17 00:00:00 2001 From: Jannik Pulfer Date: Wed, 13 Nov 2024 15:19:04 +0100 Subject: [PATCH] Refactor keyresult tests with new outsourced methods --- frontend/cypress/e2e/keyresult.cy.ts | 238 ++++++++---------- .../pom-helper/dialogs/keyResultDialog.ts | 37 +++ 2 files changed, 137 insertions(+), 138 deletions(-) diff --git a/frontend/cypress/e2e/keyresult.cy.ts b/frontend/cypress/e2e/keyresult.cy.ts index aaa5d3b709..7344e4262f 100644 --- a/frontend/cypress/e2e/keyresult.cy.ts +++ b/frontend/cypress/e2e/keyresult.cy.ts @@ -1,15 +1,29 @@ import * as users from '../fixtures/users.json'; +import CyOverviewPage from '../support/helper/pom-helper/pages/overviewPage'; +import KeyresultDetailPage from '../support/helper/pom-helper/pages/keyresultDetailPage'; +import { Unit } from '../../src/app/shared/types/enums/Unit'; +import KeyResultDialog from '../support/helper/pom-helper/dialogs/keyResultDialog'; describe('OKR Overview', () => { + let op = new CyOverviewPage(); + let keyresultDetailPage = new KeyresultDetailPage(); + beforeEach(() => { + op = new CyOverviewPage(); + keyresultDetailPage = new KeyresultDetailPage(); cy.loginAsUser(users.gl); cy.visit('/?quarter=2'); }); it('Create new metric KeyResult', () => { - cy.createMetricKeyresult(null, null, null); - - cy.getByTestId('keyresult').contains('I am a metric keyresult').click(); + op.addKeyresult() + .checkForDialogTextMetric() + .fillKeyresultTitle('I am a metric keyresult') + .withMetricValues(Unit.PERCENT, '21', '52') + .fillOwner('Paco Eggimann') + .fillKeyresultDescription('This is my description') + .submit(); + keyresultDetailPage.visit('I am a metric keyresult'); cy.contains('I am a metric keyresult'); cy.contains('Metrisch'); @@ -25,9 +39,15 @@ describe('OKR Overview', () => { }); it('Create new ordinal KeyResult', () => { - cy.createOrdinalKeyresult(null, 'Pac'); + op.addKeyresult() + .fillKeyresultTitle('I am a ordinal keyresult') + .withOrdinalValues('My commit zone', 'My target zone', 'My stretch goal') + .checkForDialogTextOrdinal() + .fillOwner('Paco Eggimann') + .fillKeyresultDescription('This is my description') + .submit(); + keyresultDetailPage.visit('I am a ordinal keyresult'); - cy.getByTestId('keyresult').contains('I am a ordinal keyresult').click(); cy.contains('I am a ordinal keyresult'); cy.contains('Ordinal'); cy.contains('Paco Eggimann'); @@ -46,66 +66,29 @@ describe('OKR Overview', () => { }); it('Create new KeyResult and Save and New', () => { - cy.getByTestId('objective').first().getByTestId('add-keyResult').first().click(); - cy.getByTestId('submit').should('be.disabled'); - cy.contains('Key Result erfassen'); - cy.contains('Jaya Norris'); - cy.checkForDialogText(); - - cy.fillOutKeyResult( - 'I am a metric keyresult with a new one', - 'PERCENT', - '21', - '52', - null, - null, - null, - null, - 'This is my description when creating and then open a new', - ); - cy.getByTestId('submit').should('not.be.disabled'); - cy.getByTestId('saveAndNew').click(); - - cy.getByTestId('submit').should('be.disabled'); - cy.contains('Key Result erfassen'); + op.addKeyresult() + .checkForDialogTextMetric() + .fillKeyresultTitle('I am a metric keyresult with a new one') + .withMetricValues(Unit.PERCENT, '21', '52') + .fillOwner('Paco Eggimann') + .fillKeyresultDescription('This is my description when creating and then open a new') + .saveAndNew(); cy.contains('Jaya Norris'); - cy.checkForDialogText(); + KeyResultDialog.do().checkForDialogTextMetric(); }); it('Create and edit KeyResult with Action Plan', () => { - cy.getByTestId('objective').first().getByTestId('add-keyResult').first().click(); - cy.contains('Key Result erfassen'); - cy.contains('Jaya Norris'); - cy.getByTestId('titleInput').type('Title'); - - cy.getByTestId('ordinalTab').click(); - cy.fillOutKeyResult( - 'This is a keyresult with an action plan', - null, - null, - null, - 'My commit zone', - 'My target zone', - 'My stretch goal', - null, - 'This is my description', - ); - - cy.getByTestId('submit').should('not.be.disabled'); - cy.getByTestId('actionInput').should('have.length', 3); - - cy.getByTestId('actionInput').first().type('A new car'); - cy.getByTestId('actionInput').last().type('A new house'); - cy.getByTestId('add-action-plan-line').click(); - cy.getByTestId('actionInput').last().type('A new company'); - - cy.getByTestId('actionInput').first().should('have.value', 'A new car'); - cy.getByTestId('actionInput').last().should('have.value', 'A new company'); - cy.getByTestId('actionInput').should('have.length', 4); - - cy.getByTestId('submit').click(); - - cy.getByTestId('keyresult').contains('This is a keyresult with an action plan').click(); + op.addKeyresult() + .fillKeyresultTitle('This is a keyresult with an action plan') + .withOrdinalValues('My commit zone', 'My target zone', 'My stretch goal') + .fillOwner('Paco Eggimann') + .fillKeyresultDescription('This is my description') + .addActionPlanElement('A new car') + .addActionPlanElement('A new house') + .addActionPlanElement('A new company') + .submit(); + + keyresultDetailPage.visit('This is a keyresult with an action plan'); cy.contains('This is a keyresult with an action plan'); cy.contains('Ordinal'); @@ -115,20 +98,22 @@ describe('OKR Overview', () => { cy.contains('A new car'); cy.contains('A new house'); cy.contains('A new company'); - cy.getByTestId('edit-keyResult').click(); + keyresultDetailPage.editKeyresult(); cy.getByTestId('actionInput').should('have.length', 3); }); it('Edit a KeyResult without type change', () => { - cy.createOrdinalKeyresult('We want not to change keyresult title', null); + op.addKeyresult() + .fillKeyresultTitle('We want not to change keyresult title') + .withOrdinalValues('My commit zone', 'My target zone', 'My stretch goal') + .checkForDialogTextOrdinal() + .fillKeyresultDescription('This is my description') + .submit(); + keyresultDetailPage.visit('We want not to change keyresult title').editKeyresult(); - cy.getByTestId('keyresult').contains('We want not to change keyresult title').last().click(); - cy.getByTestId('edit-keyResult').click(); cy.getByTestId('submit').should('not.be.disabled'); - cy.contains('Key Result bearbeiten'); - cy.getByTestId('titleInput').should('have.value', 'We want not to change keyresult title'); cy.getByTestId('commitZone').should('have.value', 'My commit zone'); cy.getByTestId('targetZone').should('have.value', 'My target zone'); @@ -136,18 +121,11 @@ describe('OKR Overview', () => { cy.getByTestId('ownerInput').should('have.value', 'Jaya Norris'); cy.getByTestId('descriptionInput').should('have.value', 'This is my description'); - cy.fillOutKeyResult( - 'This is the new title', - null, - null, - null, - 'New commit', - 'New target', - 'New stretch', - null, - 'This is my new description', - ); - cy.getByTestId('submit').click(); + KeyResultDialog.do() + .fillKeyresultTitle('This is the new title') + .withOrdinalValues('New commit', 'New target', 'New stretch') + .fillKeyresultDescription('This is my new description') + .submit(); cy.contains('This is the new title'); cy.contains('New commit'); @@ -158,14 +136,16 @@ describe('OKR Overview', () => { }); it('Edit a KeyResult with type change', () => { - cy.createOrdinalKeyresult('Here we want to change keyresult title', null); + op.addKeyresult() + .fillKeyresultTitle('Here we want to change keyresult title') + .withOrdinalValues('My commit zone', 'My target zone', 'My stretch goal') + .checkForDialogTextOrdinal() + .fillKeyresultDescription('This is my description') + .submit(); + keyresultDetailPage.visit('Here we want to change keyresult title').editKeyresult(); - cy.getByTestId('keyresult').contains('Here we want to change keyresult title').last().click(); - cy.getByTestId('edit-keyResult').click(); cy.getByTestId('submit').should('not.be.disabled'); - cy.contains('Key Result bearbeiten'); - cy.getByTestId('titleInput').should('have.value', 'Here we want to change keyresult title'); cy.getByTestId('commitZone').should('have.value', 'My commit zone'); cy.getByTestId('targetZone').should('have.value', 'My target zone'); @@ -173,21 +153,11 @@ describe('OKR Overview', () => { cy.getByTestId('ownerInput').should('have.value', 'Jaya Norris'); cy.getByTestId('descriptionInput').should('have.value', 'This is my description'); - cy.getByTestId('metricTab').click(); - - cy.fillOutKeyResult( - 'This is my new title for the new metric keyresult', - 'PERCENT', - '21', - '56', - null, - null, - null, - null, - 'This is my new description', - ); - - cy.getByTestId('submit').click(); + KeyResultDialog.do() + .fillKeyresultTitle('This is my new title for the new metric keyresult') + .withMetricValues(Unit.PERCENT, '21', '56') + .fillKeyresultDescription('This is my new description') + .submit(); cy.contains('This is my new title for the new metric keyresult'); cy.contains('21%'); @@ -195,56 +165,44 @@ describe('OKR Overview', () => { cy.contains('Metrisch'); cy.contains('Jaya Norris'); cy.contains('This is my new description'); - cy.checkForErrorToaster(0); }); it('Check validation in keyresult dialog', () => { - cy.getByTestId('objective').first().getByTestId('add-keyResult').first().click(); + op.addKeyresult().checkForDialogTextMetric(); cy.getByTestId('submit').should('be.disabled'); - cy.contains('Key Result erfassen'); - cy.checkForDialogText(); - - cy.fillOutKeyResult( - 'I am a metric keyresult', - 'PERCENT', - '21', - '52', - null, - null, - null, - null, - 'This is my description', - ); + KeyResultDialog.do() + .fillKeyresultTitle('I am a metric keyresult') + .withMetricValues(Unit.PERCENT, '21', '52') + .fillKeyresultDescription('This is my description'); + cy.getByTestId('submit').should('not.be.disabled'); cy.getByTestId('titleInput').clear(); cy.getByTestId('submit').should('be.disabled'); cy.contains('Titel muss folgende Länge haben: 2-250 Zeichen'); - cy.getByTestId('titleInput').type('My title'); + KeyResultDialog.do().fillKeyresultTitle('My title'); cy.getByTestId('submit').should('not.be.disabled'); cy.getByTestId('baseline').clear(); cy.getByTestId('submit').should('be.disabled'); cy.contains('Baseline muss eine Zahl sein'); - cy.getByTestId('baseline').type('abc'); + KeyResultDialog.do().withMetricValues(Unit.PERCENT, 'abc', '52'); cy.getByTestId('submit').should('be.disabled'); cy.contains('Baseline muss eine Zahl sein'); - cy.getByTestId('baseline').clear(); - cy.getByTestId('baseline').type('45'); + KeyResultDialog.do().withMetricValues(Unit.PERCENT, '45', '52'); cy.getByTestId('submit').should('not.be.disabled'); cy.getByTestId('stretchGoal').clear(); cy.getByTestId('submit').should('be.disabled'); cy.contains('Stretch Goal muss eine Zahl sein'); - cy.getByTestId('stretchGoal').type('abc'); + KeyResultDialog.do().withMetricValues(Unit.PERCENT, '45', 'abc'); cy.getByTestId('submit').should('be.disabled'); cy.contains('Stretch Goal muss eine Zahl sein'); - cy.getByTestId('stretchGoal').clear(); - cy.getByTestId('stretchGoal').type('83'); + KeyResultDialog.do().withMetricValues(Unit.PERCENT, '45', '83'); cy.getByTestId('submit').should('not.be.disabled'); cy.getByTestId('ownerInput').clear(); cy.getByTestId('submit').should('be.disabled'); @@ -254,47 +212,51 @@ describe('OKR Overview', () => { cy.getByTestId('submit').should('be.disabled'); cy.contains('Owner muss ausgewählt sein'); - cy.getByTestId('ownerInput').clear(); - cy.getByTestId('ownerInput').type('Pac').type('{downarrow}').type('{enter}'); + KeyResultDialog.do().fillOwner('Paco Eggimann'); cy.getByTestId('submit').should('not.be.disabled'); cy.getByTestId('ordinalTab').click(); cy.getByTestId('submit').should('be.disabled'); - cy.getByTestId('commitZone').clear().type('Commit'); - cy.getByTestId('targetZone').clear().type('Target'); - cy.getByTestId('stretchZone').clear().type('Stretch'); + KeyResultDialog.do().withOrdinalValues('Commit', 'Target', 'Stretch'); cy.getByTestId('submit').should('not.be.disabled'); cy.getByTestId('commitZone').clear(); cy.getByTestId('submit').should('be.disabled'); cy.contains('Commit Zone muss folgende Länge haben: 1-400 Zeichen'); - cy.getByTestId('commitZone').type('Commit'); + KeyResultDialog.do().withOrdinalValues('Commit', 'Target', 'Stretch'); cy.getByTestId('submit').should('not.be.disabled'); cy.getByTestId('targetZone').clear(); cy.getByTestId('submit').should('be.disabled'); cy.contains('Target Zone muss folgende Länge haben: 1-400 Zeichen'); - cy.getByTestId('targetZone').type('Target'); + KeyResultDialog.do().withOrdinalValues('Commit', 'Target', 'Stretch'); cy.getByTestId('submit').should('not.be.disabled'); cy.getByTestId('stretchZone').clear(); cy.getByTestId('submit').should('be.disabled'); cy.contains('Stretch Zone muss folgende Länge haben: 1-400 Zeichen'); - cy.getByTestId('stretchZone').type('Commit'); + KeyResultDialog.do().withOrdinalValues('Commit', 'Target', 'Stretch'); cy.getByTestId('submit').should('not.be.disabled'); }); it('Delete existing keyresult', () => { - cy.createOrdinalKeyresult('A keyresult to delete', null); - - cy.getByTestId('keyresult').contains('A keyresult to delete').last().click(); - - cy.getByTestId('edit-keyResult').click(); - - cy.getByTestId('delete-keyResult').click(); - cy.getByTestId('confirm-yes').click(); + op.addKeyresult() + .fillKeyresultTitle('A keyresult to delete') + .withOrdinalValues('My commit zone', 'My target zone', 'My stretch goal') + .checkForDialogTextOrdinal() + .fillKeyresultDescription('This is my description') + .submit(); + keyresultDetailPage + .visit('A keyresult to delete') + .editKeyresult() + .deleteKeyresult() + .checkTitle('Key Result löschen') + .checkDescription( + 'Möchtest du dieses Key Result wirklich löschen? Zugehörige Check-ins werden dadurch ebenfalls gelöscht!', + ) + .submit(); cy.contains('Puzzle ITC'); cy.get('A keyresult to delete').should('not.exist'); diff --git a/frontend/cypress/support/helper/pom-helper/dialogs/keyResultDialog.ts b/frontend/cypress/support/helper/pom-helper/dialogs/keyResultDialog.ts index 6e984a39e7..38bb0432c5 100644 --- a/frontend/cypress/support/helper/pom-helper/dialogs/keyResultDialog.ts +++ b/frontend/cypress/support/helper/pom-helper/dialogs/keyResultDialog.ts @@ -1,5 +1,6 @@ import Dialog from './dialog'; import { Unit } from '../../../../../src/app/shared/types/enums/Unit'; +import ConfirmDialog from './confirmDialog'; export default class KeyResultDialog extends Dialog { fillKeyresultTitle(title: string) { @@ -30,6 +31,7 @@ export default class KeyResultDialog extends Dialog { fillOwner(owner: string) { this.fillInputByTestId('ownerInput', owner); + cy.realPress('ArrowDown').realPress('Enter'); return this; } @@ -44,6 +46,41 @@ export default class KeyResultDialog extends Dialog { return this; } + deleteKeyresult() { + cy.getByTestId('delete-keyResult').click(); + return new ConfirmDialog(); + } + + checkForDialogTextMetric() { + cy.contains('Einheit'); + cy.contains('Baseline'); + cy.contains('Stretch Goal'); + this.checkForDialogText(); + return this; + } + + checkForDialogTextOrdinal() { + cy.contains('Commit Zone'); + cy.contains('Target Zone'); + cy.contains('Stretch Goal'); + this.checkForDialogText(); + return this; + } + + private checkForDialogText() { + cy.contains('Key Result erfassen'); + cy.contains('Titel'); + cy.contains('Metrisch'); + cy.contains('Ordinal'); + cy.contains('Owner'); + cy.contains('Beschreibung (optional)'); + cy.contains('Action Plan (optional)'); + cy.contains('Weitere Action hinzufügen'); + cy.contains('Speichern'); + cy.contains('Speichern & Neu'); + cy.contains('Abbrechen'); + } + override submit() { cy.getByTestId('submit').click(); }