Skip to content

Commit

Permalink
Refactor keyresult tests with new outsourced methods
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomTannenbaum committed Nov 13, 2024
1 parent 4971fa4 commit 6a842f3
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 138 deletions.
238 changes: 100 additions & 138 deletions frontend/cypress/e2e/keyresult.cy.ts
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -115,39 +98,34 @@ 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');
cy.getByTestId('stretchZone').should('have.value', 'My stretch goal');
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');
Expand All @@ -158,93 +136,73 @@ 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');
cy.getByTestId('stretchZone').should('have.value', 'My stretch goal');
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%');
cy.contains('56%');
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');
Expand All @@ -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');
Expand Down
Loading

0 comments on commit 6a842f3

Please sign in to comment.