-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
329 additions
and
4 deletions.
There are no files selected for viewing
233 changes: 233 additions & 0 deletions
233
frontend/benefit/applicant/browser-tests/newApplication/deminimis.testcafe.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,233 @@ | ||
import { HttpRequestHook } from '@frontend/shared/browser-tests/http-utils/http-request-hook'; | ||
import requestLogger from '@frontend/shared/browser-tests/utils/request-logger'; | ||
import { clearDataToPrintOnFailure } from '@frontend/shared/browser-tests/utils/testcafe.utils'; | ||
import { Role, Selector } from 'testcafe'; | ||
|
||
import Login from '../page-model/login'; | ||
import MainIngress from '../page-model/MainIngress'; | ||
import Step1 from '../page-model/step1'; | ||
import Step2 from '../page-model/step2'; | ||
import TermsOfService from '../page-model/TermsOfService'; | ||
import { getFrontendUrl } from '../utils/url.utils'; | ||
|
||
const getBackendDomain = (): string => | ||
process.env.NEXT_PUBLIC_BACKEND_URL || 'https://localhost:8000'; | ||
|
||
const url = getFrontendUrl('/'); | ||
|
||
type DeMinimisRow = { | ||
granter: string; | ||
amount: string; | ||
grantedAt: string; | ||
}; | ||
|
||
const applicantRole = Role( | ||
url, | ||
async (t: TestController) => { | ||
await t.click(Login.loginButton); | ||
const termsAndConditions = new TermsOfService(); | ||
await termsAndConditions.isLoaded(); | ||
await termsAndConditions.clickContinueButton(); | ||
}, | ||
{ | ||
preserveUrl: true, | ||
} | ||
); | ||
|
||
enum SAVE_ACTIONS { | ||
CONTINUE = 'continue', | ||
SAVE_AND_EXIT = 'saveAndExit', | ||
} | ||
|
||
let step1: Step1; | ||
let step2: Step2; | ||
const deminimisRowSelector = '[data-testid="deminimis-row"]'; | ||
|
||
const fillMandatoryFields = async () => { | ||
const mainIngress = new MainIngress(); | ||
await mainIngress.isLoaded(); | ||
await mainIngress.clickCreateNewApplicationButton(); | ||
|
||
await step1.isLoaded(30_000); | ||
|
||
await step1.fillEmployerInfo('6051437344779954', false); | ||
await step1.fillContactPerson( | ||
'Tester', | ||
'Example', | ||
'050001234', | ||
'[email protected]' | ||
); | ||
await step1.selectNocoOperationNegotiations(); | ||
}; | ||
|
||
const getRowCount = async () => Selector(deminimisRowSelector).count; | ||
|
||
const step1ToStep2 = async () => { | ||
await step1.clickSubmit(); | ||
await step2.isLoaded(); | ||
}; | ||
|
||
const step2ToStep1 = async () => { | ||
await step2.clickPrevious(); | ||
await step1.isLoaded(); | ||
}; | ||
const saveStep1AndReturn = async () => { | ||
await step1ToStep2(); | ||
await step2ToStep1(); | ||
}; | ||
|
||
const saveExitAndEdit = async (t: TestController) => { | ||
await step1.clickSaveAndClose(); | ||
const mainIngress = new MainIngress(); | ||
await mainIngress.isLoaded(); | ||
await t.click(Selector('[data-testid="application-edit-button"]')); | ||
await step1.isLoaded(); | ||
}; | ||
|
||
const fillRows = async ( | ||
t: TestController, | ||
rows: DeMinimisRow[], | ||
action?: SAVE_ACTIONS | ||
) => { | ||
for (const row of rows) { | ||
await step1.fillDeminimisAid(row.granter, row.amount, row.grantedAt); | ||
} | ||
if (action === SAVE_ACTIONS.CONTINUE) { | ||
await saveStep1AndReturn(); | ||
await t.scrollIntoView(Selector('button').withText('Jatka')); | ||
await t.expect(await getRowCount()).eql(rows.length); | ||
} | ||
if (action === SAVE_ACTIONS.SAVE_AND_EXIT) { | ||
await saveExitAndEdit(t); | ||
await t.expect(await getRowCount()).eql(rows.length); | ||
} | ||
}; | ||
|
||
const removeRow = async (index: number) => { | ||
await step1.clickDeminimisRemove(index); | ||
}; | ||
|
||
const removeAllRows = async (rows: DeMinimisRow[]) => { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
for (const _ of rows) { | ||
await step1.clickDeminimisRemove(0); | ||
} | ||
}; | ||
|
||
const fillTooBigAmounts = async (t: TestController) => { | ||
const rows = [ | ||
{ granter: 'One', amount: '2', grantedAt: '1.1.2023' }, | ||
{ granter: 'Two', amount: '199999', grantedAt: '2.2.2023' }, | ||
]; | ||
await fillRows(t, rows); | ||
|
||
const deminimisMaxError = Selector( | ||
'[data-testid="deminimis-maxed-notification"]' | ||
); | ||
await t.expect(await deminimisMaxError.exists).ok(); | ||
await step1.expectSubmitDisabled(); | ||
|
||
await removeAllRows(rows); | ||
|
||
await t.expect(await getRowCount()).eql(0); | ||
}; | ||
|
||
const fillAndLeaveUnfinished = async (t: TestController) => { | ||
await step1.fillDeminimisAid('One', '1', ''); | ||
await 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"]')); | ||
}; | ||
|
||
const clearRowsWithSelectNo = async ( | ||
t: TestController, | ||
action: SAVE_ACTIONS | ||
) => { | ||
await step1.selectNoDeMinimis(); | ||
|
||
if (action === SAVE_ACTIONS.CONTINUE) { | ||
await saveStep1AndReturn(); | ||
} | ||
if (action === SAVE_ACTIONS.SAVE_AND_EXIT) { | ||
await saveExitAndEdit(t); | ||
} | ||
|
||
await step1.selectYesDeMinimis(); | ||
await t.scrollIntoView(Selector('button').withText('Jatka')); | ||
|
||
await t.expect(await getRowCount()).eql(0); | ||
}; | ||
|
||
fixture('Deminimis') | ||
.page(url) | ||
.requestHooks(requestLogger, new HttpRequestHook(url, getBackendDomain())) | ||
.beforeEach(async (t: TestController) => { | ||
clearDataToPrintOnFailure(t); | ||
step1 = new Step1(); | ||
step2 = new Step2(); | ||
await t.useRole(applicantRole); | ||
await fillMandatoryFields(); | ||
await step1.selectYesDeMinimis(); | ||
}) | ||
.afterEach( | ||
async () => | ||
// eslint-disable-next-line no-console | ||
console.log('#####################################') | ||
// console.log(filterLoggedRequests(requestLogger)) | ||
); | ||
|
||
test('De Minimis aid form (errors)', async (t: TestController) => { | ||
await fillAndLeaveUnfinished(t); | ||
await fillTooBigAmounts(t); | ||
}); | ||
|
||
test('De Minimis aid form (using continue)', async (t: TestController) => { | ||
await fillRows( | ||
t, | ||
[{ granter: 'One', amount: '1', grantedAt: '1.1.2023' }], | ||
SAVE_ACTIONS.CONTINUE | ||
); | ||
|
||
await clearRowsWithSelectNo(t, SAVE_ACTIONS.CONTINUE); | ||
|
||
await fillRows( | ||
t, | ||
[ | ||
{ granter: 'One', amount: '1', grantedAt: '1.1.2023' }, | ||
{ granter: 'Two', amount: '2', grantedAt: '2.2.2023' }, | ||
{ granter: 'Three', amount: '3', grantedAt: '3.3.2023' }, | ||
], | ||
SAVE_ACTIONS.CONTINUE | ||
); | ||
|
||
await removeRow(1); | ||
await saveStep1AndReturn(); | ||
await t.expect(await getRowCount()).eql(2); | ||
}); | ||
|
||
test('De Minimis aid form (save and exit)', async (t: TestController) => { | ||
await fillRows( | ||
t, | ||
[{ granter: 'One', amount: '1', grantedAt: '1.1.2023' }], | ||
SAVE_ACTIONS.SAVE_AND_EXIT | ||
); | ||
|
||
await clearRowsWithSelectNo(t, SAVE_ACTIONS.SAVE_AND_EXIT); | ||
|
||
await fillRows( | ||
t, | ||
[ | ||
{ granter: 'One', amount: '1', grantedAt: '1.1.2023' }, | ||
{ granter: 'Two', amount: '2', grantedAt: '2.2.2023' }, | ||
{ granter: 'Three', amount: '3', grantedAt: '3.3.2023' }, | ||
], | ||
SAVE_ACTIONS.SAVE_AND_EXIT | ||
); | ||
|
||
await removeRow(1); | ||
await saveExitAndEdit(t); | ||
await t.expect(await getRowCount()).eql(2); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
import { getUrl } from '@frontend/shared/browser-tests/utils/url.utils'; | ||
import { ClientFunction } from 'testcafe'; | ||
|
||
export const getFrontendUrl = (path = ''): string => | ||
getUrl(process.env.APPLICANT_URL ?? 'https://localhost:3000', path); | ||
|
||
const goBack = ClientFunction(() => window.history.back()); | ||
|
||
export const clickBrowserBackButton = async (): Promise<void> => { | ||
await goBack(); | ||
}; |