-
Notifications
You must be signed in to change notification settings - Fork 10
HFI Calc Admin tweak #5576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
HFI Calc Admin tweak #5576
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
aed40f4
init
brettedw 262671c
test fix
brettedw 3b91a35
getError
brettedw d45aa94
Merge branch 'main' into task/hfi-calc-admin
brettedw 1c4cf48
await before close
brettedw 15d8328
FastApiValidationError
brettedw 823491a
Merge branch 'main' into task/hfi-calc-admin
brettedw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
354 changes: 231 additions & 123 deletions
354
backend/packages/wps-api/src/app/tests/hfi/test_hfi_admin.py
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
121 changes: 121 additions & 0 deletions
121
...apps/wps-web/src/features/hfiCalculator/components/stationAdmin/stationListAdmin.test.tsx
This file contains hidden or 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,121 @@ | ||
| import { render, waitFor } from '@testing-library/react' | ||
| import userEvent from '@testing-library/user-event' | ||
| import { type PlanningArea, updateStations } from '@wps/api/hfiCalculatorAPI' | ||
| import StationListAdmin from 'features/hfiCalculator/components/stationAdmin/StationListAdmin' | ||
| import { Provider } from 'react-redux' | ||
| import { vi } from 'vitest' | ||
| import { createTestStore } from '@/test/testUtils' | ||
|
|
||
| vi.mock('@wps/api/hfiCalculatorAPI', async importOriginal => { | ||
| const actual = await importOriginal<typeof import('@wps/api/hfiCalculatorAPI')>() | ||
| return { | ||
| ...actual, | ||
| updateStations: vi.fn() | ||
| } | ||
| }) | ||
|
|
||
| const updateStationsMock = vi.mocked(updateStations) | ||
|
|
||
| describe('StationListAdmin', () => { | ||
| beforeEach(() => { | ||
| updateStationsMock.mockReset() | ||
| }) | ||
|
|
||
| const planningAreas = [ | ||
| { | ||
| id: 1, | ||
| name: 'Empty Planning Area', | ||
| fire_centre_id: 1, | ||
| order_of_appearance_in_list: 1, | ||
| stations: [] | ||
| } | ||
| ] as PlanningArea[] | ||
|
|
||
| it('can add a station row to a planning area with no existing stations', async () => { | ||
| const user = userEvent.setup() | ||
|
|
||
| const { getByTestId } = render( | ||
| <Provider store={createTestStore()}> | ||
| <StationListAdmin | ||
| fireCentreId={1} | ||
| planningAreas={planningAreas} | ||
| fuelTypes={[]} | ||
| existingPlanningAreaStations={{}} | ||
| handleClose={vi.fn()} | ||
| /> | ||
| </Provider> | ||
| ) | ||
|
|
||
| await user.click(getByTestId('admin-add-station-button')) | ||
|
|
||
| expect(getByTestId('new-pa-admin-station-1-1')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('renders station update errors locally', () => { | ||
| const { getByTestId } = render( | ||
| <Provider store={createTestStore()}> | ||
| <StationListAdmin | ||
| fireCentreId={1} | ||
| planningAreas={planningAreas} | ||
| fuelTypes={[]} | ||
| existingPlanningAreaStations={{}} | ||
| stationUpdateError="station update failed" | ||
| handleClose={vi.fn()} | ||
| /> | ||
| </Provider> | ||
| ) | ||
|
|
||
| expect(getByTestId('station-update-error')).toHaveTextContent('station update failed') | ||
| }) | ||
|
|
||
| it('keeps the modal open when station updates fail', async () => { | ||
| const user = userEvent.setup() | ||
| const handleClose = vi.fn() | ||
| updateStationsMock.mockRejectedValue(new Error('station update failed')) | ||
|
|
||
| const { getByTestId } = render( | ||
| <Provider store={createTestStore()}> | ||
| <StationListAdmin | ||
| fireCentreId={1} | ||
| planningAreas={planningAreas} | ||
| fuelTypes={[]} | ||
| existingPlanningAreaStations={{ | ||
| 1: [{ planningAreaId: 1, rowId: 1, station: { code: 1, name: 'Station 1' } }] | ||
| }} | ||
| handleClose={handleClose} | ||
| /> | ||
| </Provider> | ||
| ) | ||
|
|
||
| await user.click(getByTestId('admin-remove-button')) | ||
| await user.click(getByTestId('save-new-station-button')) | ||
|
|
||
| await waitFor(() => expect(updateStationsMock).toHaveBeenCalledTimes(1)) | ||
| expect(handleClose).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('closes the modal when station updates succeed', async () => { | ||
| const user = userEvent.setup() | ||
| const handleClose = vi.fn() | ||
| updateStationsMock.mockResolvedValue(200) | ||
|
|
||
| const { getByTestId } = render( | ||
| <Provider store={createTestStore()}> | ||
| <StationListAdmin | ||
| fireCentreId={1} | ||
| planningAreas={planningAreas} | ||
| fuelTypes={[]} | ||
| existingPlanningAreaStations={{ | ||
| 1: [{ planningAreaId: 1, rowId: 1, station: { code: 1, name: 'Station 1' } }] | ||
| }} | ||
| handleClose={handleClose} | ||
| /> | ||
| </Provider> | ||
| ) | ||
|
|
||
| await user.click(getByTestId('admin-remove-button')) | ||
| await user.click(getByTestId('save-new-station-button')) | ||
|
|
||
| await waitFor(() => expect(handleClose).toHaveBeenCalledTimes(1)) | ||
| }) | ||
| }) |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.