Skip to content

Commit

Permalink
fix: disappearing de minimis aid rows and grantedAt datepicker
Browse files Browse the repository at this point in the history
* refactor: move date utils to benefit-shared

* fix: backend data to de minimis aid context and filter out unique rows

* chore: deminimis tests

* refactor: extract getBackendDomain to utils

* refactor: lint login file

* feat: ignore testcafe run videos

* fix: require collective agreement field

* fix: meet ts, lint and sonarcloud standards
  • Loading branch information
sirtawast committed Oct 3, 2023
1 parent 4d0321a commit 7cb55e2
Show file tree
Hide file tree
Showing 30 changed files with 545 additions and 191 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,6 @@ nohup.out

# media files
**/media/**

# do not include testcafe videos
1.mp4
28 changes: 24 additions & 4 deletions frontend/benefit/applicant/browser-tests/page-model/WizardStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class WizardStep extends ApplicantPageComponent {
protected nextButton = this.component.findByRole('button', {
name: this.translations.applications.actions.continue,
});

protected previousButton = this.component.findByRole('button', {
name: this.translations.applications.actions.back,
});

protected saveAndCloseButton = this.component.findByRole('button', {
name: this.translations.applications.actions.saveAndContinueLater,
});
Expand All @@ -28,16 +33,31 @@ class WizardStep extends ApplicantPageComponent {
name: this.translations.applications.actions.deleteApplication,
});

public clickSubmit() {
public clickSubmit(): Promise<void> {
return t.click(this.nextButton);
}
public clickSaveAndClose() {

public expectSaveAndClose(): Promise<void> {
return t.expect(this.nextButton).notOk();
}

public expectSubmitDisabled(): Promise<void> {
return t.expect(this.nextButton.hasAttribute('disabled')).ok();
}

public clickPrevious(): Promise<void> {
return t.click(this.previousButton);
}

public clickSaveAndClose(): Promise<void> {
return t.click(this.saveAndCloseButton);
}
public async clickDeleteApplication() {

public async clickDeleteApplication(): Promise<void> {
return t.click(this.deleteButton);
}
public confirmDeleteApplication() {

public confirmDeleteApplication(): Promise<void> {
return t.click(this.dialogConfirmDeleteButton);
}
}
Expand Down
159 changes: 159 additions & 0 deletions frontend/benefit/applicant/browser-tests/page-model/deminimis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import { Selector } from 'testcafe';

import MainIngress from './MainIngress';
import Step1 from './step1';
import Step2 from './step2';

export type DeMinimisRow = {
granter: string;
amount: string;
grantedAt: string;
};

export enum SAVE_ACTIONS {
CONTINUE = 'continue',
SAVE_AND_EXIT = 'saveAndExit',
}
class DeMinimisAid {
public step1: Step1;

public step2: Step2;

public t: TestController;

private deminimisRowSelector = '[data-testid="deminimis-row"]';

fillMandatoryFields = async (): Promise<void> => {
const mainIngress = new MainIngress();
await mainIngress.isLoaded();
await mainIngress.clickCreateNewApplicationButton();

await this.step1.isLoaded(30_000);

await this.step1.fillEmployerInfo('6051437344779954', false);
await this.step1.fillContactPerson(
'Tester',
'Example',
'050001234',
'[email protected]'
);
await this.step1.selectNocoOperationNegotiations();
};

public getRowCount = async (): Promise<number> =>
Selector(this.deminimisRowSelector).count;

private step1ToStep2 = async (): Promise<void> => {
await this.step1.clickSubmit();
await this.step2.isLoaded();
};

private step2ToStep1 = async (): Promise<void> => {
await this.step2.clickPrevious();
await this.step1.isLoaded();
};

public saveExitAndEdit = async (t: TestController): Promise<void> => {
await this.step1.clickSaveAndClose();
const mainIngress = new MainIngress();
await mainIngress.isLoaded();
await t.click(Selector('[data-testid="application-edit-button"]'));
await this.step1.isLoaded();
await t.scrollIntoView(Selector('button').withText('Jatka'));
};

public actions = {
saveStep1AndReturn: async (): Promise<void> => {
await this.step1ToStep2();
await this.step2ToStep1();
},
fillRows: async (
t: TestController,
rows: DeMinimisRow[],
action?: SAVE_ACTIONS
): Promise<void> => {
// eslint-disable-next-line no-restricted-syntax
for (const row of rows) {
// eslint-disable-next-line no-await-in-loop
await this.step1.fillDeminimisAid(
row.granter,
row.amount,
row.grantedAt
);
}
if (action === SAVE_ACTIONS.CONTINUE) {
await this.actions.saveStep1AndReturn();
await t.scrollIntoView(Selector('button').withText('Jatka'));
await t.expect(await this.getRowCount()).eql(rows.length);
}
if (action === SAVE_ACTIONS.SAVE_AND_EXIT) {
await this.saveExitAndEdit(t);
await t.expect(await this.getRowCount()).eql(rows.length);
}
},

removeRow: async (index: number): Promise<void> =>
this.step1.clickDeminimisRemove(index),

removeAllRows: async (rows: DeMinimisRow[]): Promise<void> => {
// eslint-disable-next-line no-restricted-syntax, @typescript-eslint/no-unused-vars
for (const _ of rows) {
// eslint-disable-next-line no-await-in-loop
await this.step1.clickDeminimisRemove(0);
}
},

fillTooBigAmounts: async (t: TestController): Promise<void> => {
const rows = [
{ granter: 'One', amount: '2', grantedAt: '1.1.2023' },
{ granter: 'Two', amount: '199999', grantedAt: '2.2.2023' },
];
await this.actions.fillRows(t, rows);

const deminimisMaxError = Selector(
'[data-testid="deminimis-maxed-notification"]'
);
await t.expect(await deminimisMaxError.exists).ok();
await this.step1.expectSubmitDisabled();

await this.actions.removeAllRows(rows);

await t.expect(await this.getRowCount()).eql(0);
},

fillAndLeaveUnfinished: async (t: TestController): Promise<void> => {
await this.step1.fillDeminimisAid('One', '1', '');
await this.step1.clickSubmit();
const toastError = Selector(
'.Toastify__toast-body[role="alert"]'
).withText('Puuttuvia de minimis-tuen tietoja');
await t.expect(await toastError.exists).ok();
await t.click(toastError.find('[title="Sulje ilmoitus"]'));
},

clearRowsWithSelectNo: async (
t: TestController,
action: SAVE_ACTIONS
): Promise<void> => {
await this.step1.selectNoDeMinimis();

if (action === SAVE_ACTIONS.CONTINUE) {
await this.actions.saveStep1AndReturn();
}
if (action === SAVE_ACTIONS.SAVE_AND_EXIT) {
await this.saveExitAndEdit(t);
}

await this.step1.selectYesDeMinimis();
await t.scrollIntoView(Selector('button').withText('Jatka'));
await t.expect(await this.getRowCount()).eql(0);
},
};

constructor(t: TestController, step1: Step1, step2: Step2) {
this.t = t;
this.step1 = step1;
this.step2 = step2;
}
}
export default DeMinimisAid;
12 changes: 9 additions & 3 deletions frontend/benefit/applicant/browser-tests/page-model/login.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import { t, Selector } from 'testcafe';
import { Selector, t } from 'testcafe';

class Login {
loginButton = Selector('button').withAttribute('data-testid', 'loginButton');

loginOptionButton = Selector('#valinta__vaihtoehto__vetupas2');

defaultSSN = Selector('#hetu_default');

authenticateButton = Selector('#tunnistaudu');

continueButton = Selector('#continue-button');

companyRadioButton = Selector('label').withText('YTM - Industrial Oy');

submitButton = Selector('button')
.withAttribute('type', 'submit')
.withText('Valitse ja siirry asiointipalveluun');

async clickSubmit() {
async clickSubmit(): Promise<void> {
await t.click(this.submitButton);
}

async typeName(name: string) {
async typeName(name: string): Promise<void> {
await t.typeText(this.loginButton, name);
}
}
Expand Down
65 changes: 65 additions & 0 deletions frontend/benefit/applicant/browser-tests/page-model/step1.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { t } from 'testcafe';

import WizardStep from './WizardStep';

class Step1 extends WizardStep {
Expand All @@ -19,6 +21,27 @@ class Step1 extends WizardStep {
),
});

private deminimisAmount = this.component.findByRole('textbox', {
name: this.regexp(
this.translations.applications.sections.company.fields.deMinimisAidAmount
.label
),
});

private deminimisGranter = this.component.findByRole('textbox', {
name: this.regexp(
this.translations.applications.sections.company.fields.deMinimisAidGranter
.label
),
});

private deminimisGrantedAt = this.component.findByRole('textbox', {
name: this.regexp(
this.translations.applications.sections.company.fields
.deMinimisAidGrantedAt.label
),
});

private lastName = this.component.findByRole('textbox', {
name: this.regexp(
this.translations.applications.sections.company.fields
Expand Down Expand Up @@ -64,6 +87,18 @@ class Step1 extends WizardStep {
.no,
});

private deMinimisAidTrue = this.within(
this.component.getByRole('group', {
name: this.regexp(
this.translations.applications.sections.company.fields.deMinimisAid
.label
),
})
).findByRole('radio', {
name: this.translations.applications.sections.company.fields.deMinimisAid
.yes,
});

hasImmediateManagerCheckbox = this.component.findByRole('checkbox', {
name: this.regexp(
this.translations.applications.sections.employee.fields
Expand Down Expand Up @@ -106,6 +141,32 @@ class Step1 extends WizardStep {
return this.fillInput(this.email, email);
}

public async fillDeminimisAid(
granter?: string,
amount?: string,
grantedAt?: string
): Promise<void> {
if (granter) await this.fillInput(this.deminimisGranter, granter);
if (amount) await this.fillInput(this.deminimisAmount, amount);
if (grantedAt) await this.fillInput(this.deminimisGrantedAt, grantedAt);
return this.clickDeminimisSave();
}

private deminimisSave = this.component.findByRole('button', {
name: this.translations.applications.sections.company.deMinimisAidsAdd,
});

private deminimisRemove = (index: number): SelectorPromise =>
this.component.findByTestId(`deminimis-remove-${index}`);

public clickDeminimisSave(): Promise<void> {
return t.click(this.deminimisSave);
}

public clickDeminimisRemove(index: number): Promise<void> {
return t.click(this.deminimisRemove(index));
}

public selectNoBusinessActivities(): Promise<void> {
return this.clickSelectRadioButton(this.businessActivitiesFalse);
}
Expand All @@ -114,6 +175,10 @@ class Step1 extends WizardStep {
return this.clickSelectRadioButton(this.deMinimisAidFalse);
}

public selectYesDeMinimis(): Promise<void> {
return this.clickSelectRadioButton(this.deMinimisAidTrue);
}

public selectNocoOperationNegotiations(): Promise<void> {
return this.clickSelectRadioButton(this.coOperationNegotiationsFalse);
}
Expand Down
26 changes: 15 additions & 11 deletions frontend/benefit/applicant/browser-tests/roles/company.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { Role } from 'testcafe';

import login from '../page-model/login';
import Login from '../page-model/login';
import TermsOfService from '../page-model/TermsOfService';
import { getFrontendUrl } from '../utils/url.utils';

const url = getFrontendUrl('/');

const company = Role(url, async (t) => {
await t.click(login.loginButton);
// .click(login.loginOptionButton)
// .click(login.defaultSSN)
// .click(login.authenticateButton)
// .click(login.continueButton)
// .click(login.companyRadioButton)
// .click(login.submitButton);
});
const applicantRole = Role(
url,
async (t: TestController) => {
await t.click(Login.loginButton);
const termsAndConditions = new TermsOfService();
await termsAndConditions.isLoaded();
await termsAndConditions.clickContinueButton();
},
{
preserveUrl: true,
}
);

export default company;
export default applicantRole;
Loading

0 comments on commit 7cb55e2

Please sign in to comment.