Skip to content

Commit

Permalink
chore: add test suite for handler alteration views (#3098) (HL-1355)
Browse files Browse the repository at this point in the history
  • Loading branch information
EmiliaMakelaVincit committed Jun 25, 2024
1 parent 226ad18 commit b8c0dc5
Show file tree
Hide file tree
Showing 14 changed files with 2,029 additions and 27 deletions.
1,114 changes: 1,114 additions & 0 deletions backend/benefit/applications/fixtures/test_applications.json

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions frontend/benefit/handler/browser-tests/constants/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,22 @@ export const EDIT_FORM_DATA = {
grantedAt: `3.3.${new Date().getFullYear() - 1}`,
},
};

export const NEW_TERMINATION_ALTERATION_DATA = {
endDate: '23.8.2024',
contactPersonName: 'Yhteys Henkilö',
einvoiceAddress: '012345012345',
einvoiceProviderIdentifier: 'LILAFI11',
einvoiceProviderName: 'Liiba Laaba Oy',
reason: 'Ei soveltunut työhön',
};

export const NEW_SUSPENSION_ALTERATION_DATA = {
endDate: '24.6.2024',
resumeDate: '12.8.2024',
contactPersonName: 'Sauli Säätäjä',
einvoiceAddress: '678678678',
einvoiceProviderIdentifier: 'ELKLFI99',
einvoiceProviderName: 'Eelin Keelin Oy',
reason: 'Omaehtoinen loma',
};
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,17 @@ test('Handler processes favorable decision to Ahjo / Talpa', async (t: TestContr
// Navigate to batches
await t.click(Selector('a').withText(fi.header.navigation.batches));

// Click "Mark as ready for Ahjo" button
// Visit the completed tab and read the current number of listed applications
await t.click(Selector('li').withText(fi.batches.tabs.completion));
await t
.expect(Selector('h2').withText(fi.batches.tabs.completion).exists)
.ok();
const currentCompletedBatchesCount = await Selector('h2')
.withText(fi.batches.tabs.completion)
.textContent.then((text) => text.match(/\((\d+)\)/)?.[1]);

// Return to pending tab and click "Mark as ready for Ahjo" button
await t.click(Selector('li').withText(fi.batches.tabs.pending));
await t.click(
Selector('button').withText(fi.batches.actions.markAsReadyForAhjo)
);
Expand Down Expand Up @@ -131,5 +141,12 @@ test('Handler processes favorable decision to Ahjo / Talpa', async (t: TestContr

// See if the last tab is populated with the batch
await t.click(Selector('li').withText(fi.batches.tabs.completion));
await t.expect(Selector('h2').withText('(1)').exists).ok();
await t.wait(1000);

await t
.expect(
Selector('h2').withText(`(${Number(currentCompletedBatchesCount) + 1})`)
.exists
)
.ok();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
// The eslint rule erroneously assumes that Selector.find() works like Array.find().
/* eslint-disable unicorn/no-array-callback-reference */
import { clearDataToPrintOnFailure } from '@frontend/shared/browser-tests/utils/testcafe.utils';
import { Selector } from 'testcafe';

import fi from '../../public/locales/fi/common.json';
import { NEW_TERMINATION_ALTERATION_DATA as terminationForm } from '../constants/forms';
import { navigateToAlterationTestApplication } from '../utils/alteration';
import handlerUserAhjo from '../utils/handlerUserAhjo';
import { clearAndFill } from '../utils/input';
import { getFrontendUrl } from '../utils/url.utils';

const url = getFrontendUrl(`/`);

fixture('New alteration reported by handler')
.page(url)
.beforeEach(async (t) => {
clearDataToPrintOnFailure(t);
await t.useRole(handlerUserAhjo);
await t.navigateTo('/');
});

const alterationList = Selector('div[data-testid="alteration-list"]');
const submitButton = Selector('button').withText(
fi.applications.alterations.new.actions.submit
);
const accordionItemTitle = 'div[role="heading"]';

test('Handler creates a new alteration', async (t: TestController) => {
// Note: on local development, any existing alterations should be deleted before
// running test files six through nine:
// delete from applications_applicationalteration where application_id = '3544c528-73cc-4a08-8240-09f713a14990';
// Any test assertions regarding the alteration list fail if old cancelled alterations
// from previous test runs still linger in the UI, and the test controller is unable
// to clear them itself before the tests.

await navigateToAlterationTestApplication(t);

// Find the decision box
await t
.expect(
Selector('h2').withText(fi.applications.decision.headings.mainHeading)
.visible
)
.ok();

// Find the alteration list, confirm it's empty
await t.expect(alterationList.childNodeCount).eql(0);

// Click the new alteration button
await t.click(
Selector('button').withText(
fi.applications.decision.actions.reportAlteration
)
);
await t
.expect(
Selector('h1').withText(fi.applications.alterations.new.title).visible
)
.ok();

// Fill in the data
await t.click(Selector('[for=alteration-alteration-type-termination]'));
await t.typeText('#alteration-end-date', terminationForm.endDate);

await t.click(Selector('[for=alteration-use-einvoice-yes]'));
await t.typeText('#alteration-reason', terminationForm.reason);
await clearAndFill(
t,
'#alteration-contact-person-name',
terminationForm.contactPersonName
);
await t.typeText(
'#alteration-einvoice-provider-name',
terminationForm.einvoiceProviderName
);
await t.typeText(
'#alteration-einvoice-provider-identifier',
terminationForm.einvoiceProviderIdentifier
);
await t.typeText(
'#alteration-einvoice-address',
terminationForm.einvoiceAddress
);

// Validate and submit
await t.click(submitButton);
await t
.expect(
Selector('h2').withText(fi.applications.decision.headings.mainHeading)
.visible
)
.ok();
await t.expect(alterationList.childNodeCount).eql(1);

const item = alterationList.child(0);
await t
.expect(
item.find(accordionItemTitle).withText(/päättynyt 23\.8\.2024/).exists
)
.ok();
await t
.expect(
item
.find('div')
.withText(fi.applications.decision.alterationList.item.state.received)
.exists
)
.ok();
await t.click(item.find(accordionItemTitle));
await t
.expect(
item.find('dl dd').withText(terminationForm.contactPersonName).exists
)
.ok();
});

test('Handler deletes the pending alteration', async (t: TestController) => {
await navigateToAlterationTestApplication(t);

// Find the alteration created in the previous test
await t.expect(alterationList.childNodeCount).eql(1);
const item = alterationList.child(0);

// Open the list item and click the delete button
await t.click(item.find(accordionItemTitle));
await t.click(
item
.find('button')
.withText(fi.applications.decision.alterationList.item.actions.delete)
);

// Click the confirm button in the modal
await t
.expect(
Selector('div[role="dialog"] h2').withText(
fi.applications.decision.alterationList.deleteModal.title
).visible
)
.ok();
await t.click(
Selector('div[role="dialog"] button').withText(
fi.applications.decision.alterationList.deleteModal.delete
)
);

// Verify that the alteration was deleted and no longer shown in the list in any form
await t
.expect(
Selector('h2').withText(fi.applications.decision.headings.mainHeading)
.visible
)
.ok();
await t.expect(alterationList.childNodeCount).eql(0);
});

/* eslint-enable unicorn/no-array-callback-reference */
Loading

0 comments on commit b8c0dc5

Please sign in to comment.