Skip to content

Commit

Permalink
fix first three objective tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kcinay055679 committed Nov 7, 2024
1 parent a9a64e0 commit 42aeb9c
Showing 1 changed file with 44 additions and 48 deletions.
92 changes: 44 additions & 48 deletions frontend/cypress/e2e/objective.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,24 @@ describe('OKR Objective e2e tests', () => {
cy.getByTestId('add-objective').first().click();
cy.fillOutObjective('A objective in state draft', 'safe-draft', undefined, '', false);

cy.getByTestId('objective')
.filter(':contains(A objective in state draft)')
.last()
.findByTestId('objective-state')
.should('have.attr', 'src', `assets/icons/draft-icon.svg`);
getObjectiveByNameAndState('A objective in state draft', 'draft').findByTestId('three-dot-menu').click();
selectFromThreeDotMenu('Objective veröffentlichen');

cy.getByTestId('objective')
.filter(':contains(A objective in state draft)')
.last()
.findByTestId('three-dot-menu')
.click()
.wait(500)
.get('.objective-menu-option')
.contains('Objective veröffentlichen')
.click();
cy.contains('Objective veröffentlichen');
cy.contains('Soll dieses Objective veröffentlicht werden?');
cy.getByTestId('confirm-yes').click();
cy.getByTestId('objective')
.filter(':contains(A objective in state draft)')
.last()
.findByTestId('objective-state')
.should('have.attr', 'src', `assets/icons/ongoing-icon.svg`);

getObjectiveByNameAndState('A objective in state draft', 'ongoing').should('exist');
});

it(`Complete Objective with Successful`, () => {
cy.getByTestId('add-objective').first().click();
cy.fillOutObjective('We want to complete this successful', 'safe', undefined, '', false);

cy.getByTestId('objective')
.filter(':contains("We want to complete this successful")')
.last()
.getByTestId('three-dot-menu')
.click()
.wait(500)
.get('.objective-menu-option')
.contains('Objective abschliessen')
getObjectiveByNameAndState('We want to complete this successful', 'ongoing')
.findByTestId('three-dot-menu')
.click();
selectFromThreeDotMenu('Objective abschliessen');

cy.contains('Bewertung');
cy.contains('Objective erreicht');
Expand All @@ -62,26 +42,14 @@ describe('OKR Objective e2e tests', () => {
cy.getByTestId('successful').click();
cy.getByTestId('submit').click();

cy.getByTestId('objective')
.filter(':contains("We want to complete this successful")')
.last()
.getByTestId('objective-state')
.should('have.attr', 'src', `assets/icons/successful-icon.svg`);
getObjectiveByNameAndState('We want to complete this successful', 'successful');
});

it(`Complete Objective with Not-Successful`, () => {
cy.getByTestId('add-objective').first().click();
cy.fillOutObjective('A not successful objective', 'safe', undefined, '', false);

cy.getByTestId('objective')
.filter(':contains("A not successful objective")')
.last()
.getByTestId('three-dot-menu')
.click()
.wait(500)
.get('.objective-menu-option')
.contains('Objective abschliessen')
.click();
getObjectiveByNameAndState('A not successful objective', 'ongoing').findByTestId('three-dot-menu').click();
selectFromThreeDotMenu('Objective abschliessen');

cy.contains('Bewertung');
cy.contains('Objective erreicht');
Expand All @@ -93,14 +61,10 @@ describe('OKR Objective e2e tests', () => {
cy.getByTestId('not-successful').click();
cy.getByTestId('submit').click();

cy.getByTestId('objective')
.filter(':contains("A not successful objective")')
.last()
.getByTestId('objective-state')
.should('have.attr', 'src', `assets/icons/not-successful-icon.svg`);
getObjectiveByNameAndState('A not successful objective', 'not-successful');
});

it(`Reopen Successful Objective`, () => {
it.only(`Reopen Successful Objective`, () => {
cy.getByTestId('add-objective').first().click();
cy.fillOutObjective('This objective will be reopened after', 'safe', undefined, '', false);

Expand Down Expand Up @@ -248,3 +212,35 @@ describe('tests via keyboard', () => {
cy.url().should('include', 'objective');
});
});

function getObjectiveByNameAndState(objectiveName: string, state: string) {
return getObjectivesByNameAndState(objectiveName, state).first().should('exist');
}

function selectFromThreeDotMenu(optionName: string) {
cy.get('.objective-three-dot-menu').contains(optionName).should('have.class', 'objective-menu-option').click();
}

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

function getObjectiveByState(
iconName: string,
objectives: Cypress.Chainable<JQuery<HTMLElement>> = getObjectiveColumns(),
) {
return objectives.filter((index, element) => filterByState(element, iconName));
}

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

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

0 comments on commit 42aeb9c

Please sign in to comment.