Skip to content

Commit

Permalink
fix objective-helper tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kcinay055679 committed Nov 8, 2024
1 parent d098429 commit fba300f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 36 deletions.
35 changes: 11 additions & 24 deletions frontend/cypress/e2e/duplicated-scoring.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as users from '../fixtures/users.json';
import { onlyOn } from '@cypress/skip-test';
import { filterByObjectiveName, getObjectiveColumns, selectFromThreeDotMenu } from '../support/objective-helper';

describe('e2e test for scoring adjustment on objective duplicate', () => {
beforeEach(() => {
Expand All @@ -13,7 +14,7 @@ describe('e2e test for scoring adjustment on objective duplicate', () => {
cy.createOrdinalKeyresult('stretch keyresult for testing', null);
cy.wait('@createKeyresult');
cy.contains('stretch keyresult for testing');
cy.getByTestId('keyresult').get(':contains("stretch keyresult for testing")').last().click();
cy.getByTestId('keyresult').contains('stretch keyresult for testing').last().click();
cy.getByTestId('add-check-in').click();
cy.getByTestId(`stretch-radio`).click();
cy.getByTestId('confidence-slider').click();
Expand All @@ -23,35 +24,21 @@ describe('e2e test for scoring adjustment on objective duplicate', () => {
cy.getByTestId('submit-check-in').click();
cy.getByTestId('close-drawer').click({ force: true });

cy.get('.objective').first().findByTestId('three-dot-menu').click();
cy.get('.mat-mdc-menu-content').contains('Objective duplizieren').click();
getObjectiveColumns().first().findByTestId('three-dot-menu').click();
selectFromThreeDotMenu('Objective duplizieren');
cy.fillOutObjective('A duplicated Objective for this tool', 'safe', '3');
cy.visit('/?quarter=3');

let scoringBlock1 = cy
.get('.objective:contains("A duplicated Objective for this tool")')
.first()
.findByTestId('key-result')
.first()
.findByTestId('scoring-component')
const objective = getObjectiveColumns()
.filter(filterByObjectiveName('A duplicated Objective for this tool'))
.first();
const keyResults = objective.findByTestId('key-result');

scoringBlock1.findByTestId('fail').first().should('not.have.css', 'score-red');
scoringBlock1.findByTestId('fail').first().should('not.have.css', 'score-yellow');
scoringBlock1.findByTestId('fail').first().should('not.have.css', 'score-green');
scoringBlock1.findByTestId('fail').first().should('not.have.css', 'score-stretch');
const scoringBlock1 = keyResults.findByTestId('scoring-component');

let scoringBlock2 = cy
.getByTestId('objective')
.first()
.findByTestId('key-result')
.last()
.findByTestId('scoring-component')
.last();
let failArea = scoringBlock1.findByTestId('fail');

scoringBlock2.findByTestId('fail').first().should('not.have.css', 'score-red');
scoringBlock2.findByTestId('fail').first().should('not.have.css', 'score-yellow');
scoringBlock2.findByTestId('fail').first().should('not.have.css', 'score-green');
scoringBlock2.findByTestId('fail').first().should('not.have.css', 'score-stretch');
failArea.should('not.have.css', 'score-red', 'score-yellow');
failArea.should('not.have.css', 'score-green', 'score-stretch');
});
});
12 changes: 6 additions & 6 deletions frontend/cypress/e2e/objective.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('OKR Objective e2e tests', () => {
cy.getByTestId('objectiveSearch').first().type('Search after').wait(350);

cy.contains('Search after this objective');
cy.get('We dont want to search for this').should('not.exist');
cy.contains('We dont want to search for this').should('not.exist');

cy.getByTestId('objectiveSearch').first().clear().type('this').wait(350);

Expand All @@ -131,19 +131,19 @@ describe('OKR Objective e2e tests', () => {
cy.getByTestId('objectiveSearch').first().clear().type('dont want to').wait(350);

cy.contains('We dont want to search for this');
cy.get('Search after this objective').should('not.exist');
cy.contains('Search after this objective').should('not.exist');

cy.getByTestId('objectiveSearch').first().clear().type('there is no objective').wait(350);

cy.get('We dont want to search for this').should('not.exist');
cy.get('Search after this objective').should('not.exist');
cy.contains('We dont want to search for this').should('not.exist');
cy.contains('Search after this objective').should('not.exist');
});

it(`Create Objective in other quarter`, () => {
cy.getByTestId('add-objective').first().click();
cy.fillOutObjective('Objective in quarter 2', 'safe', '2', '', false);

cy.get('Objective in quarter 2').should('not.exist');
cy.contains('Objective in quarter 2').should('not.exist');

cy.visit('/?quarter=2');

Expand All @@ -159,7 +159,7 @@ describe('OKR Objective e2e tests', () => {

cy.fillOutObjective('Move to another quarter on edit', 'safe', '3', '', false);

cy.get('Move to another quarter on edit').should('not.exist');
cy.contains('Move to another quarter on edit').should('not.exist');

cy.visit('/?quarter=3');

Expand Down
19 changes: 13 additions & 6 deletions frontend/cypress/support/objective-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,25 @@ export function selectFromThreeDotMenu(optionName: string) {
}

function getObjectivesByNameAndState(objectiveName: string, state: string) {
return getObjectiveColumns()
.filter((index, element) => filterByObjectiveName(element, objectiveName))
.filter((index, element) => filterByState(element, state));
return getObjectiveColumns().filter(filterByObjectiveName(objectiveName)).filter(filterByObjectiveState(state));
}

const filterByState = (element: HTMLElement, icon: string) => {
export function filterByObjectiveName(objectiveName: string) {
return (index: number, element: HTMLElement) => byObjectiveName(element, objectiveName);
}

export function filterByObjectiveState(icon: string) {
return (index: number, element: HTMLElement) => byObjectiveState(element, icon);
}

const byObjectiveState = (element: HTMLElement, icon: string) => {
return Cypress.$(element).find(`[src='assets/icons/${icon}-icon.svg']`).length > 0;
};
const filterByObjectiveName = (element: HTMLElement, objectiveName: string) => {

const byObjectiveName = (element: HTMLElement, objectiveName: string) => {
return Cypress.$(element).find(`:contains("${objectiveName}")`).length > 0;
};

function getObjectiveColumns() {
export function getObjectiveColumns() {
return cy.get('.objective');
}

0 comments on commit fba300f

Please sign in to comment.