Skip to content

Commit

Permalink
refactor page base and introduce new base class for dialog and page
Browse files Browse the repository at this point in the history
  • Loading branch information
kcinay055679 committed Nov 11, 2024
1 parent 908d384 commit 3390e66
Show file tree
Hide file tree
Showing 10 changed files with 190 additions and 63 deletions.
12 changes: 6 additions & 6 deletions frontend/cypress/e2e/objective-backlog.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('OKR Objective Backlog e2e tests', () => {
op.getObjectiveByNameAndState('Move to another quarter on edit', 'draft').findByTestId('three-dot-menu').click();
op.selectFromThreeDotMenu('Objective bearbeiten');

ObjectiveDialog.with().fillObjectiveTitle('This goes now to backlog').selectQuarter('Backlog').submit();
ObjectiveDialog.do().fillObjectiveTitle('This goes now to backlog').selectQuarter('Backlog').submit();

cy.contains('This goes now to backlog').should('not.exist');

Expand Down Expand Up @@ -79,7 +79,7 @@ describe('OKR Objective Backlog e2e tests', () => {
op.getObjectiveByNameAndState('This is possible for edit', 'draft').findByTestId('three-dot-menu').click();
op.selectFromThreeDotMenu('Objective bearbeiten');

ObjectiveDialog.with().fillObjectiveTitle('My new title').submit();
ObjectiveDialog.do().fillObjectiveTitle('My new title').submit();

op.getObjectiveByNameAndState('My new title', 'draft');
});
Expand All @@ -91,7 +91,7 @@ describe('OKR Objective Backlog e2e tests', () => {
op.getObjectiveByNameAndState('This goes to other quarter later', 'draft').findByTestId('three-dot-menu').click();
op.selectFromThreeDotMenu('Objective bearbeiten');

ObjectiveDialog.with().selectQuarter('GJ ForTests').submit();
ObjectiveDialog.do().selectQuarter('GJ ForTests').submit();

op.visitGJForTests();
op.getObjectiveByNameAndState('This goes to other quarter later', 'draft');
Expand All @@ -104,7 +104,7 @@ describe('OKR Objective Backlog e2e tests', () => {
op.getObjectiveByNameAndState('Ready for duplicate in backlog', 'draft').findByTestId('three-dot-menu').click();
op.selectFromThreeDotMenu('Objective duplizieren');

ObjectiveDialog.with().fillObjectiveTitle('This is a new duplication in backlog').submit();
ObjectiveDialog.do().fillObjectiveTitle('This is a new duplication in backlog').submit();

op.getObjectiveByNameAndState('Ready for duplicate in backlog', 'draft');
op.getObjectiveByNameAndState('This is a new duplication in backlog', 'draft');
Expand All @@ -118,7 +118,7 @@ describe('OKR Objective Backlog e2e tests', () => {
.click();
op.selectFromThreeDotMenu('Objective duplizieren');

ObjectiveDialog.with().fillObjectiveTitle('New duplication from backlog').selectQuarter('GJ ForTests').submit();
ObjectiveDialog.do().fillObjectiveTitle('New duplication from backlog').selectQuarter('GJ ForTests').submit();

op.getObjectiveByNameAndState('Ready for duplicate to another quarter', 'draft').should('exist');
cy.contains('New duplication from backlog').should('not.exist');
Expand All @@ -134,7 +134,7 @@ describe('OKR Objective Backlog e2e tests', () => {
.click();
op.selectFromThreeDotMenu('Objective duplizieren');

ObjectiveDialog.with().selectQuarter('Backlog').submit();
ObjectiveDialog.do().selectQuarter('Backlog').submit();

op.visitBacklogQuarter();
cy.contains('Possible to duplicate into backlog');
Expand Down
8 changes: 4 additions & 4 deletions frontend/cypress/e2e/objective.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('OKR Objective e2e tests', () => {
op.getObjectiveByNameAndState('A objective in state draft', 'draft').findByTestId('three-dot-menu').click();
op.selectFromThreeDotMenu('Objective veröffentlichen');

ConfirmDialog.with()
ConfirmDialog.do()
.checkTitle('Objective veröffentlichen')
.checkDescription('Soll dieses Objective veröffentlicht werden?')
.submit();
Expand Down Expand Up @@ -88,7 +88,7 @@ describe('OKR Objective e2e tests', () => {

op.selectFromThreeDotMenu('Objective wiedereröffnen');

ConfirmDialog.with()
ConfirmDialog.do()
.checkTitle('Objective wiedereröffnen')
.checkDescription('Soll dieses Objective wiedereröffnet werden?')
.submit();
Expand All @@ -105,7 +105,7 @@ describe('OKR Objective e2e tests', () => {
.click();
op.selectFromThreeDotMenu('Objective als Draft speichern');

ConfirmDialog.with()
ConfirmDialog.do()
.checkTitle('Objective als Draft speichern')
.checkDescription('Soll dieses Objective als Draft gespeichert werden?')
.submit();
Expand Down Expand Up @@ -164,7 +164,7 @@ describe('OKR Objective e2e tests', () => {
.click();

op.selectFromThreeDotMenu('Objective bearbeiten');
ObjectiveDialog.with().selectQuarter('3').submit();
ObjectiveDialog.do().selectQuarter('3').submit();

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

Expand Down
34 changes: 34 additions & 0 deletions frontend/cypress/e2e/routing.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as users from '../fixtures/users.json';
import CyOverviewPage from '../support/helper/pom-helper/pages/overviewPage';
import TeammanagementPage from '../support/helper/pom-helper/pages/teammanagementPage';

describe('Routing', () => {
beforeEach(() => {
cy.loginAsUser(users.gl);
cy.visit('');
});

describe('Route via url', () => {
it('should route to overview', () => {
// Visit autocalls the validatePage method
CyOverviewPage.do().visitViaURL();
});

it('should route to teammanagement', () => {
// Visit autocalls the validatePage method
TeammanagementPage.do().visitViaURL();
});

it('should route from overview to team management ', () => {
CyOverviewPage.do().visitViaURL().visitTeammanagement();
});

it('should route from team management to Overview via back button', () => {
TeammanagementPage.do().visitViaURL().backToOverview();
});

it('should route from team management to Overview via logo', () => {
TeammanagementPage.do().visitViaURL().visitOverview();
});
});
});
46 changes: 16 additions & 30 deletions frontend/cypress/e2e/teammanagement.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as users from '../fixtures/users.json';
import { uniqueSuffix } from '../support/helper/utils';
import ConfirmDialog from '../support/helper/pom-helper/dialogs/confirmDialog';
import TeammanagementPage from '../support/helper/pom-helper/pages/teammanagementPage';
import CyOverviewPage from '../support/helper/pom-helper/pages/overviewPage';

describe('Team management tests', () => {
const teamName = uniqueSuffix('New Team');
Expand All @@ -10,26 +12,18 @@ describe('Team management tests', () => {
beforeEach(() => {
cy.loginAsUser(users.gl);
});
it('should navigate to overview when clicking logo', () => {
cy.getByTestId('team-management').click();
cy.getByTestId('logo').click();
cy.url().should('not.include', 'team-management');
});
it('should navigate to overview when pressing back to overview', () => {
cy.getByTestId('team-management').click();
cy.getByTestId('routerLink-to-overview').click();
cy.url().should('not.include', 'team-management');
});

it('should preserve team filter', () => {
CyOverviewPage.do().visitViaURL();
cy.get('mat-chip:visible:contains("/BBT")').click();
cy.get('mat-chip:visible:contains("Puzzle ITC")').click();
checkTeamsSelected();
cy.getByTestId('team-management').click();
CyOverviewPage.do().visitTeammanagement();
checkTeamsSelected();
cy.getByTestId('routerLink-to-overview').click();
TeammanagementPage.do().backToOverview();
checkTeamsSelected();
cy.getByTestId('team-management').click();
cy.getByTestId('logo').click();
CyOverviewPage.do().visitTeammanagement();
TeammanagementPage.do().visitOverview();
checkTeamsSelected();
});

Expand All @@ -50,14 +44,7 @@ describe('Team management tests', () => {

beforeEach(() => {
cy.loginAsUser(users.gl);
cy.getByTestId('team-management').click();
});

it('Opens teammanagement dialog', () => {
//Check if overview contains correct titles of teammanagement
cy.contains('Teamverwaltung');
cy.contains('Team erfassen');
cy.contains('Alle Teams');
TeammanagementPage.do().visitViaURL();
});

it('Create team', () => {
Expand All @@ -78,8 +65,7 @@ describe('Team management tests', () => {
cy.getByTestId('member-list-more').click();
cy.getByTestId('remove-from-member-list').click();

// dialog
ConfirmDialog.with()
ConfirmDialog.do()
.checkTitle('Mitglied entfernen')
.checkDescription(`Möchtest du Jaya Norris wirklich aus dem Team '${teamName}' entfernen?`)
.submit();
Expand All @@ -97,7 +83,7 @@ describe('Team management tests', () => {
cy.getByTestId('remove-from-member-list').click();

// cancel dialog
ConfirmDialog.with()
ConfirmDialog.do()
.checkTitle('Mitglied entfernen')
.checkDescription(`Möchtest du Jaya Norris wirklich aus dem Team '${teamName}' entfernen?`)
.cancel();
Expand Down Expand Up @@ -136,7 +122,7 @@ describe('Team management tests', () => {

// cancel dialog => cancel

ConfirmDialog.with()
ConfirmDialog.do()
.checkTitle('Team löschen')
.checkDescription(
`Möchtest du das Team '${teamName}' wirklich löschen? Zugehörige Objectives werden dadurch in allen Quartalen ebenfalls gelöscht!`,
Expand All @@ -147,7 +133,7 @@ describe('Team management tests', () => {
cy.getByTestId('teamMoreButton').click();
cy.getByTestId('teamDeleteButton').click();

ConfirmDialog.with()
ConfirmDialog.do()
.checkTitle('Team löschen')
.checkDescription(
`Möchtest du das Team '${teamName}' wirklich löschen? Zugehörige Objectives werden dadurch in allen Quartalen ebenfalls gelöscht!`,
Expand Down Expand Up @@ -412,7 +398,7 @@ describe('Team management tests', () => {
navigateToUser('Findus Peterson');
cy.getByTestId('delete-team-member').click();

ConfirmDialog.with()
ConfirmDialog.do()
.checkTitle('Mitglied entfernen')
.checkDescription(`Möchtest du Findus Peterson wirklich aus dem Team '/BBT' entfernen?`)
.submit();
Expand All @@ -426,7 +412,7 @@ describe('Team management tests', () => {
navigateToUser(nameEsha);
cy.getByTestId('delete-team-member').eq(0).click();

ConfirmDialog.with()
ConfirmDialog.do()
.checkTitle('Mitglied entfernen')
.checkDescription(`Möchtest du ${nameEsha} wirklich aus dem Team '/BBT' entfernen?`)
.submit();
Expand All @@ -435,7 +421,7 @@ describe('Team management tests', () => {

cy.getByTestId('delete-team-member').eq(0).click();

ConfirmDialog.with()
ConfirmDialog.do()
.checkTitle('Mitglied entfernen')
.checkDescription(`Möchtest du ${nameEsha} wirklich aus dem Team 'LoremIpsum' entfernen?`)
.submit();
Expand Down
17 changes: 6 additions & 11 deletions frontend/cypress/support/helper/pom-helper/dialogs/dialog.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
export default abstract class Dialog {
import { PageObjectMapperBase } from '../pageObjectMapperBase';

export default abstract class Dialog extends PageObjectMapperBase {
constructor() {
this.init();
super();
this.validatePage();
}

init() {
override validatePage() {
this.getPage().should('exist');
}

Expand All @@ -24,13 +27,5 @@ export default abstract class Dialog {
cy.getByTestId(testId).type(value);
}

check(arg: any) {
return this;
}

abstract getPage(): Cypress.Chainable<JQuery<HTMLElement>>;

static with<T extends Dialog>(this: new () => T): T {
return new this();
}
}
20 changes: 20 additions & 0 deletions frontend/cypress/support/helper/pom-helper/objectivePO.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { state } from '@angular/animations';

export class ObjectivePO {
title: string;
state: string;

constructor(title: string, state: string) {
this.title = title;
this.state = state;
}

selectFromMenu(option: string) {
this.openMenu();
cy.get('.objective-three-dot-menu').contains(option).click();
}

private openMenu() {
cy.get('.objective-three-dot-menu').click();
}
}
11 changes: 11 additions & 0 deletions frontend/cypress/support/helper/pom-helper/pageObjectMapperBase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export abstract class PageObjectMapperBase {
abstract validatePage(): void;

static do<T extends PageObjectMapperBase>(this: new () => T): T {
return new this();
}

check(arg: any) {
return this;
}
}
40 changes: 28 additions & 12 deletions frontend/cypress/support/helper/pom-helper/pages/overviewPage.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
import { getObjectivesByNameAndState } from '../../objective-helper';
import ObjectiveDialog from '../dialogs/objectiveDialog';
import { Page } from './page';

export default class CyOverviewPage {
visit() {
cy.visit('');
}

visitWithQuarter(quarter: number) {
cy.visit(`/?quarter=${quarter}`);
}
export default class CyOverviewPage extends Page {
elements = {
logo: () => cy.getByTestId('logo'),
teammanagement: () => cy.getByTestId('team-management'),
};

visitGJForTests() {
cy.visit('/?quarter=998');
this.visitQuarter(998);
}

visitBacklogQuarter() {
cy.visit(`/?quarter=999`);
this.visitQuarter(999);
}

visitCurrentQuarter() {
cy.visit(`/?quarter=2`);
this.visitQuarter(2);
}

visitNextQuarter() {
cy.visit(`/?quarter=3`);
this.visitQuarter(3);
}

private visitQuarter(quarter: number) {
cy.visit(`/?quarter=${quarter}`);
}

addObjective(teamName?: string) {
Expand Down Expand Up @@ -53,4 +55,18 @@ export default class CyOverviewPage {
chainable.should('have.class', 'objective-menu-option');
chainable.click();
}

visitTeammanagement(): void {
this.elements.teammanagement().click();
}

getURL(): string {
return '';
}

validatePage(): void {}

doVisit(): void {
this.elements.logo().click();
}
}
23 changes: 23 additions & 0 deletions frontend/cypress/support/helper/pom-helper/pages/page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { PageObjectMapperBase } from '../pageObjectMapperBase';

export abstract class Page extends PageObjectMapperBase {
visit(): this {
this.doVisit();
return this.afterVisit();
}

visitViaURL(): this {
cy.visit(this.getURL());
return this.afterVisit();
}

protected abstract doVisit(): void;

private afterVisit(): this {
cy.url().should('include', this.getURL());
this.validatePage();
return this;
}

abstract getURL(): string;
}
Loading

0 comments on commit 3390e66

Please sign in to comment.