Skip to content

Commit

Permalink
fix: rfi analyst upload tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RRanath committed Feb 12, 2025
1 parent d1897c2 commit b095b32
Showing 1 changed file with 306 additions and 0 deletions.
306 changes: 306 additions & 0 deletions app/tests/components/Analyst/RFI/RFIAnalystUpload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const mockQueryPayload = {
detailedBudgetRfi: true,
eligibilityAndImpactsCalculatorRfi: true,
geographicCoverageMapRfi: true,
geographicNamesRfi: true,
geographicCoverageMap: [
{
uuid: 1,
Expand Down Expand Up @@ -109,6 +110,12 @@ describe('The RFIAnalystUpload component', () => {
name: 'Template 2 - Detailed Budget',
})
).toBeInTheDocument();

expect(
screen.getByRole('heading', {
name: 'Template 9 - Backbone and Geographic Names',
})
).toBeInTheDocument();
});

it('should render upload indication for template 1 and 2', () => {
Expand Down Expand Up @@ -240,6 +247,7 @@ describe('The RFIAnalystUpload component', () => {
eligibilityAndImpactsCalculatorRfi: true,
eligibilityAndImpactsCalculator: expect.anything(),
geographicCoverageMapRfi: true,
geographicNamesRfi: true,
geographicCoverageMap: [
{
uuid: 1,
Expand Down Expand Up @@ -275,6 +283,7 @@ describe('The RFIAnalystUpload component', () => {
eligibilityAndImpactsCalculatorRfi: true,
eligibilityAndImpactsCalculator: expect.anything(),
geographicCoverageMapRfi: true,
geographicNamesRfi: true,
geographicCoverageMap: [
{
uuid: 1,
Expand Down Expand Up @@ -453,6 +462,7 @@ describe('The RFIAnalystUpload component', () => {
detailedBudgetRfi: true,
eligibilityAndImpactsCalculatorRfi: true,
detailedBudget: expect.anything(),
geographicNamesRfi: true,
geographicCoverageMapRfi: true,
geographicCoverageMap: expect.anything(),
},
Expand All @@ -472,6 +482,7 @@ describe('The RFIAnalystUpload component', () => {
rfiAdditionalFiles: {
detailedBudgetRfi: true,
eligibilityAndImpactsCalculatorRfi: true,
geographicNamesRfi: true,
detailedBudget: expect.anything(),
geographicCoverageMapRfi: true,
geographicCoverageMap: expect.anything(),
Expand Down Expand Up @@ -515,4 +526,299 @@ describe('The RFIAnalystUpload component', () => {
screen.getByText(/Template 2 data changed successfully/)
).toBeVisible();
});

it('should save template nine data and render success toast for template nine when upload successful', async () => {
componentTestingHelper.loadQuery();
componentTestingHelper.renderComponent();

// @ts-ignore
global.fetch = jest.fn(() =>
Promise.resolve({
ok: true,
status: 200,
json: () =>
Promise.resolve({
communitiesToBeServed: 3,
indigenousCommunitiesToBeServed: 1,
totalNumberOfHouseholds: 39,
totalNumberOfIndigenousHouseholds: 2,
geoNames: [
{
projectZone: 9,
geoName: 'Cranbrook',
type: 'City',
mapLink: 'https://apps.gov.bc.ca/pub/bcgnws/names/4786.html',
isIndigenous: 'N',
geoNameId: 4786,
regionalDistrict: 'Regional District of East Kootenay',
economicRegion: 'Kootenay',
pointOfPresenceId: 'Mission Road Site',
proposedSolution: 'Fibre-Optic',
households: 18,
},
{
projectZone: 9,
geoName: 'Kimberley',
type: 'City',
mapLink: 'https://apps.gov.bc.ca/pub/bcgnws/names/3865.html',
isIndigenous: 'N',
geoNameId: 3865,
regionalDistrict: 'Regional District of East Kootenay',
economicRegion: 'Kootenay',
pointOfPresenceId: 'Mission Road Site',
proposedSolution: 'Fibre-Optic',
households: 19,
},
{
projectZone: 9,
geoName: "Saint Mary's 1A",
type: 'Indian Reserve',
mapLink: 'https://apps.gov.bc.ca/pub/bcgnws/names/65172.html',
isIndigenous: 'Y',
geoNameId: 65172,
regionalDistrict: 'Regional District of East Kootenay',
economicRegion: 'Kootenay',
pointOfPresenceId: 'Mission Road Site',
proposedSolution: 'Fibre-Optic',
households: 2,
},
],
originalFileName: 'template_nine.xlsx',
}),
})
);

const dateInput = screen.getAllByPlaceholderText('YYYY-MM-DD')[0];

await act(async () => {
fireEvent.change(dateInput, {
target: {
value: '2025-07-01',
},
});
});

const file = new File([new ArrayBuffer(1)], 'template_nine.xlsx', {
type: 'application/excel',
});

const inputFile = screen.getAllByTestId('file-test')[2];

await act(async () => {
fireEvent.change(inputFile, { target: { files: [file] } });
});

componentTestingHelper.expectMutationToBeCalled(
'createAttachmentMutation',
{
input: {
attachment: {
file: expect.anything(),
fileName: 'template_nine.xlsx',
fileSize: '1 Bytes',
fileType: 'application/excel',
applicationId: expect.anything(),
},
},
}
);

await act(async () => {
componentTestingHelper.environment.mock.resolveMostRecentOperation({
data: {
createAttachment: {
attachment: {
rowId: 1,
file: 'string',
},
},
},
});
});

expect(screen.getByText('template_nine.xlsx')).toBeInTheDocument();

expect(screen.getByText(/Template 9 processing successful/)).toBeVisible();

const saveButton = screen.getByRole('button', {
name: 'Save',
});

await act(async () => {
fireEvent.click(saveButton);
});

componentTestingHelper.expectMutationToBeCalled(
'updateWithTrackingRfiMutation',
{
input: {
jsonData: {
rfiType: [],
rfiAdditionalFiles: {
detailedBudgetRfi: true,
eligibilityAndImpactsCalculatorRfi: true,
geographicCoverageMapRfi: true,
geographicNamesRfi: true,
geographicCoverageMap: expect.anything(),
geographicNames: expect.anything(),
},
},
rfiRowId: 1,
},
}
);

act(() => {
componentTestingHelper.environment.mock.resolveMostRecentOperation({
data: {
updateWithTrackingRfi: {
rfiData: {
rowId: 1,
jsonData: {
rfiAdditionalFiles: {
detailedBudgetRfi: true,
eligibilityAndImpactsCalculatorRfi: true,
geographicCoverageMapRfi: true,
geographicNamesRfi: true,
geographicCoverageMap: expect.anything(),
geographicNames: expect.anything(),
},
},
},
},
},
});
});

componentTestingHelper.expectMutationToBeCalled(
'updateTemplateNineDataMutation',
{
input: {
rowId: 42,
applicationFormTemplate9DataPatch: {
jsonData: {
communitiesToBeServed: 3,
indigenousCommunitiesToBeServed: 1,
totalNumberOfHouseholds: 39,
totalNumberOfIndigenousHouseholds: 2,
geoNames: [
{
projectZone: 9,
geoName: 'Cranbrook',
type: 'City',
mapLink: 'https://apps.gov.bc.ca/pub/bcgnws/names/4786.html',
isIndigenous: 'N',
geoNameId: 4786,
regionalDistrict: 'Regional District of East Kootenay',
economicRegion: 'Kootenay',
pointOfPresenceId: 'Mission Road Site',
proposedSolution: 'Fibre-Optic',
households: 18,
},
{
projectZone: 9,
geoName: 'Kimberley',
type: 'City',
mapLink: 'https://apps.gov.bc.ca/pub/bcgnws/names/3865.html',
isIndigenous: 'N',
geoNameId: 3865,
regionalDistrict: 'Regional District of East Kootenay',
economicRegion: 'Kootenay',
pointOfPresenceId: 'Mission Road Site',
proposedSolution: 'Fibre-Optic',
households: 19,
},
{
projectZone: 9,
geoName: "Saint Mary's 1A",
type: 'Indian Reserve',
mapLink: 'https://apps.gov.bc.ca/pub/bcgnws/names/65172.html',
isIndigenous: 'Y',
geoNameId: 65172,
regionalDistrict: 'Regional District of East Kootenay',
economicRegion: 'Kootenay',
pointOfPresenceId: 'Mission Road Site',
proposedSolution: 'Fibre-Optic',
households: 2,
},
],
originalFileName: 'template_nine.xlsx',
},
errors: null,
source: expect.anything(),
applicationId: 1,
},
},
}
);
});

it('should show error when template nine when upload fails', async () => {
componentTestingHelper.loadQuery();
componentTestingHelper.renderComponent();

// @ts-ignore
global.fetch = jest.fn(() =>
Promise.resolve({
ok: false,
status: 400,
json: () =>
Promise.resolve({
error: 'failed to process template upload',
}),
})
);

const dateInput = screen.getAllByPlaceholderText('YYYY-MM-DD')[0];

await act(async () => {
fireEvent.change(dateInput, {
target: {
value: '2025-07-01',
},
});
});

const file = new File([new ArrayBuffer(1)], 'template_nine.xlsx', {
type: 'application/excel',
});

const inputFile = screen.getAllByTestId('file-test')[2];

await act(async () => {
fireEvent.change(inputFile, { target: { files: [file] } });
});

componentTestingHelper.expectMutationToBeCalled(
'createAttachmentMutation',
{
input: {
attachment: {
file: expect.anything(),
fileName: 'template_nine.xlsx',
fileSize: '1 Bytes',
fileType: 'application/excel',
applicationId: expect.anything(),
},
},
}
);

await act(async () => {
componentTestingHelper.environment.mock.resolveMostRecentOperation({
data: {
createAttachment: {
attachment: {
rowId: 1,
file: 'string',
},
},
},
});
});

expect(screen.getByText('template_nine.xlsx')).toBeInTheDocument();

expect(screen.getByText(/Template 9 validation failed/)).toBeVisible();
});
});

0 comments on commit b095b32

Please sign in to comment.