Skip to content

Commit

Permalink
Remove now unused cypress commands from commands.ts and component.ts,…
Browse files Browse the repository at this point in the history
… remove unnecessary check for error toaster, refactor scoring tests to use new methods
  • Loading branch information
RandomTannenbaum committed Nov 15, 2024
1 parent d10e2b6 commit 0918c65
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 274 deletions.
1 change: 0 additions & 1 deletion frontend/cypress/e2e/keyresult.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ 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', () => {
Expand Down
73 changes: 44 additions & 29 deletions frontend/cypress/e2e/scoring.cy.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import * as users from '../fixtures/users.json';
import { getPercentageMetric, getPercentageOrdinal } from 'cypress/support/helper/scoringSupport';
import { onlyOn } from '@cypress/skip-test';
import CyOverviewPage from '../support/helper/pom-helper/pages/overviewPage';
import { Unit } from '../../src/app/shared/types/enums/Unit';
import KeyresultDetailPage from '../support/helper/pom-helper/pages/keyresultDetailPage';

describe('Scoring component e2e tests', () => {
let op = new CyOverviewPage();
let keyresultDetailPage = new KeyresultDetailPage();

beforeEach(() => {
op = new CyOverviewPage();
keyresultDetailPage = new KeyresultDetailPage();
cy.loginAsUser(users.gl);
onlyOn('chrome');
cy.visit('/?quarter=2');
Expand All @@ -16,7 +24,7 @@ describe('Scoring component e2e tests', () => {
[0, 100, 100],
].forEach(([baseline, stretchgoal, value]) => {
it('Create metric checkin and validate value of scoring component', () => {
setupMetricKR(baseline, stretchgoal, value);
setupMetricKR(`Metric kr with check-in value ${value}`, baseline, stretchgoal, value);
const percentage = getPercentageMetric(baseline, stretchgoal, value);
cy.validateScoring(false, percentage);
cy.get('.keyResult-detail-attribute-show')
Expand All @@ -26,13 +34,10 @@ describe('Scoring component e2e tests', () => {
.should('have.css', 'border-color')
.and('not.equal', 'rgb(186, 56, 56)');

cy.getByTestId('close-drawer').click({ force: true });
keyresultDetailPage.close();
cy.validateScoring(true, percentage);

cy.getByTestId('keyresult')
.get(':contains("Metric scoring keyresult")')
.last()
.not(':contains(*[class="scoring-error-badge"])');
op.getKeyresultByName(`Metric kr with check-in value ${value}`).not(':contains(*[class="scoring-error-badge"])');
});
});

Expand All @@ -41,7 +46,7 @@ describe('Scoring component e2e tests', () => {
[200, 100, 250],
].forEach(([baseline, stretchgoal, value]) => {
it('show indicator that value is negative', () => {
setupMetricKR(baseline, stretchgoal, value);
setupMetricKR(`Check indicator with value ${value}`, baseline, stretchgoal, value);
cy.validateScoring(false, 0);
cy.get('.keyResult-detail-attribute-show')
.contains('Aktuell')
Expand All @@ -50,40 +55,50 @@ describe('Scoring component e2e tests', () => {
.should('have.css', 'border-color')
.and('equal', 'rgb(186, 56, 56)');

cy.getByTestId('close-drawer').click({ force: true });
keyresultDetailPage.close();
cy.validateScoring(true, 0);

cy.getByTestId('keyresult').get(':contains("Metric scoring keyresult")').last().get('.scoring-error-badge');
op.getKeyresultByName(`Check indicator with value ${value}`).get('.scoring-error-badge');
});
});

[['fail'], ['commit'], ['target'], ['stretch']].forEach(([zoneName]) => {
it('Create ordinal checkin and validate value of scoring component', () => {
cy.createOrdinalKeyresult('Ordinal scoring keyresult', null);
cy.getByTestId('keyresult').get(':contains("Ordinal scoring keyresult")').last().click();
cy.getByTestId('add-check-in').click();
cy.getByTestId(`${zoneName}-radio`).click();
cy.getByTestId('confidence-slider').click();
cy.realPress('{rightarrow}').realPress('{rightarrow}').realPress('{rightarrow}');
cy.getByTestId('changeInfo').click().type('Testveränderungen');
cy.getByTestId('initiatives').click().type('Testmassnahmen');
cy.getByTestId('submit-check-in').click();
op.addKeyresult()
.fillKeyresultTitle('Ordinal scoring keyresult')
.withOrdinalValues('My commit zone', 'My target zone', 'My stretch goal')
.checkForDialogTextOrdinal()
.fillKeyresultDescription('This is my description')
.submit();

keyresultDetailPage
.visit('Ordinal scoring keyresult')
.createCheckIn()
.selectOrdinalCheckInZone(zoneName as 'fail' | 'commit' | 'target' | 'stretch')
.setCheckInConfidence(8)
.fillCheckInCommentary('Testveränderungen')
.fillCheckInInitiatives('Testmassnahmen')
.submit();
const percentage = getPercentageOrdinal(zoneName);
cy.validateScoring(false, percentage);
cy.getByTestId('close-drawer').click({ force: true });
keyresultDetailPage.close();
cy.validateScoring(true, percentage);
});
});
});

function setupMetricKR(baseline: number, stretchgoal: number, value: number) {
cy.createMetricKeyresult('Metric scoring keyresult', String(baseline), String(stretchgoal));
cy.getByTestId('keyresult').get(':contains("Metric scoring keyresult")').last().click();
cy.getByTestId('add-check-in').click();
cy.getByTestId('check-in-metric-value').clear().type(String(value));
cy.getByTestId('confidence-slider').click();
cy.realPress('{rightarrow}').realPress('{rightarrow}').realPress('{rightarrow}');
cy.getByTestId('changeInfo').click().type('Testveränderungen');
cy.getByTestId('initiatives').click().type('Testmassnahmen');
cy.getByTestId('submit-check-in').click();
function setupMetricKR(name: string, baseline: number, stretchgoal: number, value: number) {
CyOverviewPage.do()
.addKeyresult()
.fillKeyresultTitle(name)
.withMetricValues(Unit.PERCENT, baseline.toString(), stretchgoal.toString())
.submit();
KeyresultDetailPage.do()
.visit(name)
.createCheckIn()
.fillMetricCheckInValue(value.toString())
.fillCheckInCommentary('Testveränderungen')
.fillCheckInInitiatives('Testmassnahmen')
.setCheckInConfidence(8)
.submit();
}
208 changes: 0 additions & 208 deletions frontend/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,204 +58,6 @@ Cypress.Commands.add('validateScoring', (isOverview: boolean, percentage: number
validateScoring(isOverview, percentage);
});

Cypress.Commands.add('checkForErrorToaster', (amount: number, errorMessages?: string[]) => {
checkForToaster('toast-error', amount, errorMessages);
});

Cypress.Commands.add('checkForWarnToaster', (amount: number, errorMessages?: string[]) => {
checkForToaster('toast-warn', amount, errorMessages);
});

Cypress.Commands.add('checkForSuccessToaster', (amount: number, errorMessages?: string[]) => {
checkForToaster('toast-success', amount, errorMessages);
});

Cypress.Commands.add(
'fillOutObjective',
(
objectiveTitle: string,
button: string,
quarter?: string,
description?: string,
createKeyResults: boolean = false,
) => {
cy.intercept('**/overview**').as('loadObjective');
cy.contains('Objective');
cy.getByTestId('title').first().clear().type(objectiveTitle);
cy.getByTestId('description')
.first()
.clear()
.type(description || 'This is the description of the new Objective');
if (quarter) {
cy.get('select#quarter').select(quarter);
}
if (createKeyResults) {
cy.getByTestId('keyResult-checkbox').find("[type='checkbox']").check();
}
cy.getByTestId(button).click();
cy.wait('@loadObjective');
},
);

Cypress.Commands.add(
'fillOutCheckInMetric',
(currentValue: number, shouldChangeConfidence: number, changeInfo: string | null, initiatives: string | null) => {
cy.getByTestId('check-in-metric-value').clear().type(currentValue.toString());
setConfidence(shouldChangeConfidence);
if (changeInfo) {
cy.getByTestId('changeInfo').clear().type(changeInfo!);
}
if (initiatives) {
cy.getByTestId('initiatives').clear().type(initiatives!);
}
cy.getByTestId('submit-check-in').click();
},
);

Cypress.Commands.add(
'fillOutCheckInOrdinal',
(currentZoneIndex: number, confidence: number, changeInfo: string | null, initiatives: string | null) => {
switch (currentZoneIndex) {
case 0:
cy.getByTestId('fail-radio').click();
break;
case 1:
cy.getByTestId('commit-radio').click();
break;
case 2:
cy.getByTestId('target-radio').click();
break;
case 3:
cy.getByTestId('stretch-radio').click();
break;
}
setConfidence(confidence);
if (changeInfo) {
cy.getByTestId('changeInfo').clear().type(changeInfo!);
}
if (initiatives) {
cy.getByTestId('initiatives').clear().type(initiatives!);
}
cy.getByTestId('submit-check-in').click();
},
);

Cypress.Commands.add('createOrdinalKeyresult', (title: string | null = null, owner: string | null = null) => {
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.contains('Titel');
cy.getByTestId('titleInput').type('Title');
cy.getByTestId('ordinalTab').click();
cy.contains('Metrisch');
cy.contains('Ordinal');
cy.contains('Commit Zone');
cy.contains('Target Zone');
cy.contains('Stretch Goal');
cy.contains('Owner');
cy.contains('Beschreibung (optional)');
cy.contains('Action Plan (optional)');
cy.contains('Weitere Action hinzufügen');
cy.contains('Speichern');
cy.contains('Abbrechen');

cy.fillOutKeyResult(
title == null ? 'I am a ordinal keyresult' : title,
null,
null,
null,
'My commit zone',
'My target zone',
'My stretch goal',
owner,
'This is my description',
);

cy.getByTestId('submit').should('not.be.disabled');
cy.getByTestId('submit').click();
});

Cypress.Commands.add(
'createMetricKeyresult',
(title: string | null, baseline: string | null, stretchGoal: string | null) => {
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(
title == null ? 'I am a metric keyresult' : title,
'PERCENT',
baseline === null ? '21' : baseline,
stretchGoal === null ? '52' : stretchGoal,
null,
null,
null,
'Pac',
'This is my description',
);
cy.getByTestId('submit').should('not.be.disabled');
cy.getByTestId('submit').click();
},
);

Cypress.Commands.add('checkForDialogText', () => {
cy.contains('Titel');
cy.contains('Metrisch');
cy.contains('Ordinal');
cy.contains('Einheit');
cy.contains('Baseline');
cy.contains('Stretch Goal');
cy.contains('Owner');
cy.contains('Beschreibung (optional)');
cy.contains('Action Plan (optional)');
cy.contains('Weitere Action hinzufügen');
cy.contains('Speichern');
cy.contains('Abbrechen');
});

Cypress.Commands.add(
'fillOutKeyResult',
(
title: string,
unit: string | null,
baseline: string | null,
stretchGoal: string | null,
commitZone: string | null,
targetZone: string | null,
stretchZone: string | null,
owner: string | null,
description: string,
) => {
cy.getByTestId('titleInput').clear().type(title);
if (commitZone == null) {
cy.getByTestId('unit').select(unit!);
cy.getByTestId('baseline').clear().type(baseline!);
cy.getByTestId('stretchGoal').clear().type(stretchGoal!);
} else {
cy.getByTestId('commitZone').clear().type(commitZone!);
cy.getByTestId('targetZone').clear().type(targetZone!);
cy.getByTestId('stretchZone').clear().type(stretchZone!);
}
if (owner != null) {
cy.getByTestId('ownerInput').clear().type(owner).type('{downarrow}').type('{enter}');
}
cy.getByTestId('descriptionInput').clear().type(description);
},
);

function setConfidence(confidence: number) {
cy.getByTestId('confidence-slider').find('input').focus();
for (let i = 0; i < 10; i++) {
cy.realPress('ArrowLeft');
}
for (let i = 0; i < confidence; i++) {
cy.realPress('ArrowRight');
}
}

function loginWithCredentials(username: string, password: string) {
cy.visit('/');
cy.intercept('GET', '**/users/current').as('getCurrentUser');
Expand All @@ -272,16 +74,6 @@ function loginWithCredentials(username: string, password: string) {
});
}

function checkForToaster(selector: string, amount: number, messages: string[] = []) {
const toaster = cy.get('.ngx-toastr.' + selector);
toaster.should('have.length', amount);
if (amount == 0) return;
toaster
.find('.toast-message')
.invoke('text')
.then((e) => messages.forEach((m) => expect(e).contains(m)));
}

const overviewIsLoaded = () => cy.get('mat-chip').should('have.length.at.least', 2);

// -- This is a parent command --
Expand Down
Loading

0 comments on commit 0918c65

Please sign in to comment.