-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Place front end logic for saving manifest to server and e-Manifest in…
… a custom hook, useSaveManifest. This hook wraps around our RTK query endpoints/hooks. Depending on the manifest saved, it initiates the appropriate action to POST/PUT to the haztrak server or saving to e-Manifest
- Loading branch information
1 parent
bb8ae0b
commit 923c895
Showing
12 changed files
with
301 additions
and
118 deletions.
There are no files selected for viewing
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
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,2 +1,3 @@ | ||
export { useManifestStatus } from './useManifestStatus/useManifestStatus'; | ||
export { useReadOnly } from './useReadOnly/useReadOnly'; | ||
export { useSaveManifest } from './useSaveManifest/useSaveManifest'; |
69 changes: 69 additions & 0 deletions
69
client/src/hooks/manifest/useSaveManifest/useSaveManifest.spec.tsx
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,69 @@ | ||
import '@testing-library/jest-dom'; | ||
import { cleanup, waitFor } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { renderWithProviders, screen } from 'test-utils'; | ||
import { afterAll, afterEach, beforeAll, describe, expect, it } from 'vitest'; | ||
import { useSaveManifest } from './useSaveManifest'; | ||
import { Manifest } from 'components/Manifest'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { createMockManifest } from 'test-utils/fixtures'; | ||
import { setupServer } from 'msw/node'; | ||
import { manifestMocks } from 'test-utils/mock'; | ||
|
||
const TestComponent = ({ manifest }: { manifest?: Manifest }) => { | ||
const { data, isLoading, error, taskId, saveManifest } = useSaveManifest(); | ||
return ( | ||
<> | ||
<p>loading: {isLoading ? 'yes' : 'no'}</p> | ||
<p>error: {error ? 'yes' : 'no'}</p> | ||
<p>task: {taskId ? taskId : 'empty'}</p> | ||
<p>data: {data ? 'defined' : 'undefined'}</p> | ||
<p>mtn: {data?.manifestTrackingNumber ?? 'undefined'}</p> | ||
<button onClick={() => saveManifest(manifest)}>save</button> | ||
</> | ||
); | ||
}; | ||
|
||
const server = setupServer(...manifestMocks); | ||
beforeAll(() => server.listen()); | ||
afterAll(() => server.close()); | ||
afterEach(() => cleanup()); | ||
|
||
describe('useSaveManifest', () => { | ||
it('isLoading is false, error is null, and taskId is null by default ', () => { | ||
renderWithProviders(<TestComponent />); | ||
expect(screen.getByText(/^loading: no/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/^error: no/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/^task: empty/i)).toBeInTheDocument(); | ||
}); | ||
it('request are made to create a draft manifest', async () => { | ||
renderWithProviders( | ||
<TestComponent | ||
manifest={createMockManifest({ | ||
manifestTrackingNumber: undefined, | ||
status: 'NotAssigned', | ||
})} | ||
/> | ||
); | ||
await userEvent.click(screen.getByText(/^save$/i)); | ||
await waitFor(() => expect(screen.getByText(/^loading: no/i)).toBeInTheDocument()); | ||
expect(screen.getByText(/^data: defined/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/^mtn: [0-9]{9}DFT/i)).toBeInTheDocument(); | ||
}); | ||
it('request to update a draft manifest if MTN already exists', async () => { | ||
const existingMTN = '123456789DFT'; | ||
renderWithProviders( | ||
<TestComponent | ||
manifest={createMockManifest({ | ||
manifestTrackingNumber: existingMTN, | ||
status: 'NotAssigned', | ||
})} | ||
/> | ||
); | ||
expect(screen.getByText(/^loading: no/i)).toBeInTheDocument(); | ||
await userEvent.click(screen.getByText(/^save$/i)); | ||
await waitFor(() => expect(screen.getByText(/^loading: no/i)).toBeInTheDocument()); | ||
expect(screen.getByText(/^data: defined/i)).toBeInTheDocument(); | ||
expect(screen.getByText(`mtn: ${existingMTN}`)).toBeInTheDocument(); | ||
}); | ||
}); |
Oops, something went wrong.