From e7cc87f3e4f51b439af0b89f4575ed757ffacc29 Mon Sep 17 00:00:00 2001 From: Yanick Minder Date: Fri, 8 Nov 2024 13:04:35 +0100 Subject: [PATCH] fix objective tests --- frontend/cypress/e2e/objective.cy.ts | 49 ++++++++++++++----- frontend/cypress/support/OverviewPage.ts | 2 +- frontend/cypress/support/objectiveFormPage.ts | 45 +++++++++++++++++ 3 files changed, 82 insertions(+), 14 deletions(-) create mode 100644 frontend/cypress/support/objectiveFormPage.ts diff --git a/frontend/cypress/e2e/objective.cy.ts b/frontend/cypress/e2e/objective.cy.ts index 99ce0652e2..f1f7299b4f 100644 --- a/frontend/cypress/e2e/objective.cy.ts +++ b/frontend/cypress/e2e/objective.cy.ts @@ -1,20 +1,23 @@ import * as users from '../fixtures/users.json'; import { onlyOn } from '@cypress/skip-test'; import CyOverviewPage from '../support/OverviewPage'; +import CyObjectiveFormPage from '../support/objectiveFormPage'; describe('OKR Objective e2e tests', () => { - const op = new CyOverviewPage(); - + let op = new CyOverviewPage(); describe('tests via click', () => { describe('Functionality', () => { beforeEach(() => { + op = new CyOverviewPage(); cy.loginAsUser(users.gl); op.visitCurrentQuarter(); }); it(`Release Objective from Draft to Ongoing`, () => { op.addObjective(); - cy.fillOutObjective('A objective in state draft', 'safe-draft', undefined, '', false); + const ofp = new CyObjectiveFormPage(); + ofp.fillObjectiveTitle('A objective in state draft'); + ofp.submitDraftObjective(); op.getObjectiveByNameAndState('A objective in state draft', 'draft').findByTestId('three-dot-menu').click(); op.selectFromThreeDotMenu('Objective veröffentlichen'); @@ -28,7 +31,9 @@ describe('OKR Objective e2e tests', () => { it(`Complete Objective with Successful`, () => { op.addObjective(); - cy.fillOutObjective('We want to complete this successful', 'safe', undefined, '', false); + const ofp = new CyObjectiveFormPage(); + ofp.fillObjectiveTitle('We want to complete this successful'); + ofp.submitObjective(); op.getObjectiveByNameAndState('We want to complete this successful', 'ongoing') .findByTestId('three-dot-menu') @@ -50,7 +55,11 @@ describe('OKR Objective e2e tests', () => { it(`Complete Objective with Not-Successful`, () => { op.addObjective(); - cy.fillOutObjective('A not successful objective', 'safe', undefined, '', false); + + const ofp = new CyObjectiveFormPage(); + ofp.fillObjectiveTitle('A not successful objective'); + ofp.submitObjective(); + op.getObjectiveByNameAndState('A not successful objective', 'ongoing').findByTestId('three-dot-menu').click(); op.selectFromThreeDotMenu('Objective abschliessen'); @@ -69,7 +78,9 @@ describe('OKR Objective e2e tests', () => { it(`Reopen Successful Objective`, () => { op.addObjective(); - cy.fillOutObjective('This objective will be reopened after', 'safe', undefined, '', false); + const ofp = new CyObjectiveFormPage(); + ofp.fillObjectiveTitle('This objective will be reopened after'); + ofp.submitObjective(); op.getObjectiveByNameAndState('This objective will be reopened after', 'ongoing') .findByTestId('three-dot-menu') @@ -94,7 +105,9 @@ describe('OKR Objective e2e tests', () => { it('Ongoing objective back to draft state', () => { onlyOn('chrome'); op.addObjective(); - cy.fillOutObjective('This objective will be returned to draft state', 'safe', undefined, '', false); + const ofp = new CyObjectiveFormPage(); + ofp.fillObjectiveTitle('This objective will be returned to draft state'); + ofp.submitObjective(); op.getObjectiveByNameAndState('This objective will be returned to draft state', 'ongoing') .findByTestId('three-dot-menu') @@ -110,10 +123,13 @@ describe('OKR Objective e2e tests', () => { it(`Search for Objective`, () => { op.addObjective(); - cy.fillOutObjective('Search after this objective', 'safe', undefined, '', false); + const ofp = new CyObjectiveFormPage(); + ofp.fillObjectiveTitle('Search after this objective'); + ofp.submitObjective(); - cy.getByTestId('add-objective').first().click(); - cy.fillOutObjective('We dont want to search for this', 'safe', undefined, '', false); + op.addObjective(); + ofp.fillObjectiveTitle('We dont want to search for this'); + ofp.submitObjective(); cy.contains('Search after this objective'); cy.contains('We dont want to search for this'); @@ -145,7 +161,10 @@ describe('OKR Objective e2e tests', () => { it(`Create Objective in other quarter`, () => { op.addObjective(); - cy.fillOutObjective('Objective in quarter 3', 'safe', '3', '', false); + const ofp = new CyObjectiveFormPage(); + ofp.fillObjectiveTitle('Objective in quarter 3'); + ofp.selectQuarter('3'); + ofp.submitObjective(); cy.contains('Objective in quarter 3').should('not.exist'); @@ -156,14 +175,18 @@ describe('OKR Objective e2e tests', () => { it(`Edit Objective and move to other quarter`, () => { op.addObjective(); - cy.fillOutObjective('Move to another quarter on edit', 'safe', undefined, '', false); + const ofp = new CyObjectiveFormPage(); + ofp.fillObjectiveTitle('Move to another quarter on edit'); + ofp.submitObjective(); op.getObjectiveByNameAndState('Move to another quarter on edit', 'ongoing') .findByTestId('three-dot-menu') .click(); + op.selectFromThreeDotMenu('Objective bearbeiten'); - cy.fillOutObjective('Move to another quarter on edit', 'safe', '3', '', false); + ofp.selectQuarter('3'); + ofp.submitObjective(); cy.contains('Move to another quarter on edit').should('not.exist'); diff --git a/frontend/cypress/support/OverviewPage.ts b/frontend/cypress/support/OverviewPage.ts index 4898f2b62f..b3b8d6a690 100644 --- a/frontend/cypress/support/OverviewPage.ts +++ b/frontend/cypress/support/OverviewPage.ts @@ -30,7 +30,7 @@ export default class CyOverviewPage { } getObjectiveByNameAndState(objectiveName: string, state: string) { - return getObjectivesByNameAndState(objectiveName, state).first().should('exist'); + return getObjectivesByNameAndState(objectiveName, state).first().scrollIntoView().should('exist'); } selectFromThreeDotMenu(optionName: string) { diff --git a/frontend/cypress/support/objectiveFormPage.ts b/frontend/cypress/support/objectiveFormPage.ts new file mode 100644 index 0000000000..ca2b1d10fc --- /dev/null +++ b/frontend/cypress/support/objectiveFormPage.ts @@ -0,0 +1,45 @@ +import {quarter} from "../../src/app/shared/testData"; + +export default class CyObjectiveFormPage { + + + // init() { + // cy.get("app-objective-form").should('exist'); + // } + + visit() { + cy.visit('/objective-form'); + } + + fillObjectiveTitle(title: string) { + this.fillInput('title', title); + } + + fillObjectiveDescription(description: string) { + this.fillInput('description', description); + } + + selectQuarter(quarter: string) { + cy.get('select#quarter').select(quarter); + } + + toggleCreateKeyResults() { + cy.getByTestId('keyResult-checkbox').find("[type='checkbox']").check(); + } + + submitObjective() { + cy.getByTestId('safe').click(); + } + submitDraftObjective() { + cy.getByTestId('safe-draft').click(); + } + + cancelObjective() { + cy.getByTestId('cancel').click(); + } + + private fillInput(testId:string, value: string) { + cy.getByTestId(testId).clear(); + cy.getByTestId(testId).type(value); + } +} \ No newline at end of file