Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,8 @@ export const fillEmploymentDetails = async (

const {
employee_ssn,
target_group,
employee_home_city,
employee_postcode,
employee_phone_number,
employment_postcode,
employee_school,
employment_start_date,
employment_end_date,
employment_work_hours,
Expand All @@ -86,15 +82,10 @@ export const fillEmploymentDetails = async (
if (!expectedPreFill?.employee_ssn) {
await step1Form.actions.fillSsn(employee_ssn ?? '');
}
const targetGroupKey = target_group ?? 'secondary_target_group';
await step1Form.actions.selectTargetGroup(targetGroupKey);
await step1Form.actions.fillHomeCity(employee_home_city ?? '');
await step1Form.actions.fillPostcode(String(employee_postcode ?? ''));
await step1Form.actions.fillPhoneNumber(employee_phone_number ?? '');
await step1Form.actions.fillEmploymentPostcode(
String(employment_postcode ?? '')
);
await step1Form.actions.fillSchool(employee_school ?? '');

await step1Form.actions.addEmploymentContractAttachment([
'sample1.pdf',
Expand Down Expand Up @@ -144,8 +135,6 @@ export const loginAndfillApplication = async (
expectedPreFill?: {
employee_ssn?: string;
employee_phone_number?: string;
employee_postcode?: string | number;
employee_school?: string;
}
): Promise<UserAndApplicationData> => {
const urlUtils = getUrlUtils(t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ export const MOCKED_EMPLOYEE_DATA = {
employee_phone_number: '040 1234567',
employee_home_city: 'Helsinki',
employee_postcode: '00100',
employee_school: 'Testikoulu',
target_group: 'secondary_target_group',
employee_school: 'Test School',
};

/**
Expand All @@ -18,12 +17,10 @@ export const MOCKED_EMPLOYEE_DATA = {
* from requests and restore them in responses to make tests work.
*/
const serialNumberFixes = new Map<string, string>();
const targetGroupFixes = new Map<string, string>();

interface VoucherData {
id: string;
summer_voucher_serial_number?: string;
target_group?: string;
}

/**
Expand Down Expand Up @@ -74,9 +71,6 @@ const cacheVoucherFixes = (vouchers?: VoucherData[]): void => {
if (v.id && v.summer_voucher_serial_number) {
serialNumberFixes.set(v.id, v.summer_voucher_serial_number);
}
if (v.id && v.target_group) {
targetGroupFixes.set(v.id, v.target_group);
}
});
};

Expand All @@ -88,22 +82,14 @@ const restoreVoucherData = (
v.summer_voucher_serial_number ||
requestVoucher?.summer_voucher_serial_number ||
serialNumberFixes.get(v.id);
const restoredTargetGroup =
v.target_group ||
requestVoucher?.target_group ||
targetGroupFixes.get(v.id);

if (v.id && restoredSerialNumber) {
serialNumberFixes.set(v.id, restoredSerialNumber);
}
if (v.id && restoredTargetGroup) {
targetGroupFixes.set(v.id, restoredTargetGroup);
}

return {
...v,
summer_voucher_serial_number: restoredSerialNumber || '',
target_group: restoredTargetGroup || '',
};
};

Expand Down Expand Up @@ -198,38 +184,6 @@ export const fetchEmployeeDataMock = RequestMock()
})
.respond(handleEmployerApplicationsGet);

// Proxy target_groups requests to the real backend
export const targetGroupsMock = RequestMock()
.onRequestTo({
url: /target_groups/,
method: 'GET',
})
.respond(
async (req: MockRequest, res: MockResponse) => {
// eslint-disable-next-line no-console
console.log('MOCK GET target_groups hit:', req.url);
try {
const response = await axios.get(req.url, {
headers: req.headers,
});
res.headers = getTestCafeHeaders(response.headers);
res.statusCode = response.status;
res.setBody(response.data as object);
} catch (error: unknown) {
if (axios.isAxiosError(error)) {
// eslint-disable-next-line no-console
console.error('Proxy GET target_groups failed', error);
res.statusCode = error.response?.status || 500;
res.setBody((error.response?.data as object) || {});
} else {
res.statusCode = 500;
}
}
},
200,
{ 'access-control-allow-origin': '*' }
);

export const attachmentsMock = RequestMock()
.onRequestTo({
url: /attachments/,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
attachmentsMock,
fetchEmployeeDataMock,
MOCKED_EMPLOYEE_DATA,
targetGroupsMock,
} from './application.mocks';
import { getStep1Components } from './step1.components';
import { getStep2Components } from './step2.components';
Expand All @@ -34,7 +33,6 @@ fixture('Application')
requestLogger,
new HttpRequestHook(url, getBackendDomain()),
fetchEmployeeDataMock,
targetGroupsMock,
attachmentsMock
)
.beforeEach(async (t) => {
Expand Down Expand Up @@ -118,7 +116,6 @@ test('Fills up employer form and preserves data when navigating back and forth',
application.summer_vouchers[0]
);
await step1Form.expectations.isEmploymentSupplementFulfilledWith({
target_group: application.summer_vouchers[0].target_group,
employment_start_date: convertToUIDateFormat(
application.summer_vouchers[0].employment_start_date
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,6 @@ export const getStep1Components = (t: TestController) => {
name: /^henkilötunnus/i,
});
},
targetGroupInput(value: string) {
// Target the label instead of the input to avoid overlap issues
return Selector(`label[for="summer_vouchers.0.target_group-${value}"]`);
},
homeCityInput() {
return withinForm().findByRole('textbox', {
name: /^kotipaikka/i,
});
},
postcodeInput() {
return withinForm().findByRole('spinbutton', {
name: /^postinumero/i,
});
},
phoneNumberInput() {
return withinForm().findByRole('textbox', {
name: /^puhelinnumero/i,
Expand All @@ -131,11 +117,6 @@ export const getStep1Components = (t: TestController) => {
name: /^työn suorituspaikan postinumero/i,
});
},
schoolInput() {
return withinForm().findByRole('textbox', {
name: /^koulun nimi/i,
});
},
employmentContractAttachmentInput: () =>
withinForm().findByTestId('summer_vouchers.0.employment_contract'),
payslipAttachmentInput: () =>
Expand Down Expand Up @@ -188,10 +169,6 @@ export const getStep1Components = (t: TestController) => {
await t
.expect(selectors.ssnInput().hasAttribute('disabled'))
.notOk(await getErrorMessage(t));
// Wait for at least one target group to appear to ensure dynamic content is loaded
await t
.expect(Selector('[data-testid*="target_group-"]').exists)
.ok('Target groups did not load in time', { timeout: 10_000 });
},
async isSsnFieldReadOnly() {
await t
Expand Down Expand Up @@ -228,13 +205,9 @@ export const getStep1Components = (t: TestController) => {
async isEmploymentFulfilledWith({
employee_ssn,
employee_phone_number,
employee_postcode,
employee_school,
}: {
employee_ssn?: string;
employee_phone_number?: string;
employee_postcode?: string | number;
employee_school?: string;
}) {
await t.expect(formSelector().exists).ok(await getErrorMessage(t));
if (employee_ssn) {
Expand All @@ -247,36 +220,16 @@ export const getStep1Components = (t: TestController) => {
.expect(selectors.phoneNumberInput().value)
.eql(employee_phone_number, await getErrorMessage(t));
}
if (employee_postcode) {
await t
.expect(selectors.postcodeInput().value)
.eql(String(employee_postcode), await getErrorMessage(t));
}
if (employee_school) {
await t
.expect(selectors.schoolInput().value)
.eql(employee_school, await getErrorMessage(t));
}
},
async isEmploymentSupplementFulfilledWith({
target_group,
employment_start_date,
employment_end_date,
hired_without_voucher_assessment,
}: {
target_group?: string;
employment_start_date?: string;
employment_end_date?: string;
hired_without_voucher_assessment?: string;
}) {
if (target_group) {
await t
.expect(
Selector(`input#summer_vouchers\\.0\\.target_group-${target_group}`)
.checked
)
.ok(await getErrorMessage(t));
}
if (employment_start_date) {
await t
.expect(selectors.startDateInput().value)
Expand Down Expand Up @@ -386,29 +339,6 @@ export const getStep1Components = (t: TestController) => {
ssn
);
},
async selectTargetGroup(name: string) {
const selector = selectors.targetGroupInput(name);
await t
.expect(selector.exists)
.ok(await getErrorMessage(t), { timeout: 10_000 });
await t.click(selector);
},
fillHomeCity(city: string) {
return fillInput(
t,
'summer_vouchers.0.employee_home_city',
selectors.homeCityInput(),
city
);
},
fillPostcode(postcode: string) {
return fillInput(
t,
'summer_vouchers.0.employee_postcode',
selectors.postcodeInput(),
postcode
);
},
fillPhoneNumber(phone: string) {
return fillInput(
t,
Expand All @@ -425,14 +355,6 @@ export const getStep1Components = (t: TestController) => {
postcode
);
},
fillSchool(school: string) {
return fillInput(
t,
'summer_vouchers.0.employee_school',
selectors.schoolInput(),
school
);
},
addEmploymentContractAttachment,
addPayslipAttachments,
fillStartDate(date: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const getSummaryComponents = async (t: TestController) => {
);

const expectTargetGroupHasValue = (
field: 'target_group' | 'hired_without_voucher_assessment'
field: 'hired_without_voucher_assessment'
) => {
const value = employment[field];
if (!value) {
Expand Down Expand Up @@ -159,15 +159,10 @@ export const getSummaryComponents = async (t: TestController) => {
.contains(employment.employee_name ?? '', await getErrorMessage(t))
.expect(header.textContent)
.contains(employment.employee_ssn ?? '', await getErrorMessage(t));
await expectTargetGroupHasValue('target_group');
await expectEmploymentFieldhasValue('employee_postcode');
await expectEmploymentFieldhasValue('employee_home_city');
await expectEmploymentFieldhasValue('employee_phone_number');
await expectEmploymentFieldhasValue('employment_postcode');
await expectEmploymentFieldhasValue('employee_school');
await expectAttachments('employment_contract');
await expectAttachments('payslip');
await expectEmploymentFieldhasValue('employee_school');
const { employment_start_date, employment_end_date } = employment;
const dateRange = [employment_start_date, employment_end_date]
.map((date) => convertToUIDateFormat(date))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import get from 'lodash/get';
import translations from '../../public/locales/fi/common.json';

export const getSelectionGroupTranslation = (
type: 'target_group' | 'hired_without_voucher_assessment',
type: 'hired_without_voucher_assessment',
value: EmploymentExceptionReason | EmployeeHiredWithoutVoucherAssessment
): string =>
get(
Expand Down
Loading