-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MCR-3793: state routing for unlocked rates (#2190)
* added edit rate route and constants * placeholder and routing setup * setup rerouting for :id * setup redirect * setup placeholder and some testing * renamed feature flag * updated routes * components tweaked to redirect in a manner more inline with established patterns * updated tests * adjusted for launchdarkly update * remove unused param * removed unnecessary spacing
- Loading branch information
1 parent
c1c7cb0
commit e645afa
Showing
7 changed files
with
159 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { screen, waitFor } from '@testing-library/react' | ||
import { renderWithProviders } from "../../testHelpers" | ||
import { RateEdit } from "./RateEdit" | ||
import { fetchCurrentUserMock, fetchRateMockSuccess, mockValidStateUser } from "../../testHelpers/apolloMocks" | ||
import { RoutesRecord } from '../../constants' | ||
import { Route, Routes } from 'react-router-dom' | ||
|
||
// Wrap test component in some top level routes to allow getParams to be tested | ||
const wrapInRoutes = (children: React.ReactNode) => { | ||
return ( | ||
<Routes> | ||
<Route path={RoutesRecord.RATE_EDIT} element={children} /> | ||
</Routes> | ||
) | ||
} | ||
|
||
describe('RateEdit', () => { | ||
afterAll(() => jest.clearAllMocks()) | ||
|
||
describe('Viewing RateEdit as a state user', () => { | ||
|
||
it('renders without errors', async () => { | ||
renderWithProviders(wrapInRoutes(<RateEdit />), { | ||
apolloProvider: { | ||
mocks: [ | ||
fetchCurrentUserMock({ | ||
user: mockValidStateUser(), | ||
statusCode: 200, | ||
}), | ||
fetchRateMockSuccess({ rate: { id: '1337', status: 'UNLOCKED' } }), | ||
], | ||
}, | ||
routerProvider: { | ||
route: '/rates/1337/edit' | ||
}, | ||
featureFlags: { | ||
'rate-edit-unlock': true | ||
} | ||
}) | ||
|
||
await waitFor(() => { | ||
expect(screen.queryByTestId('rate-edit')).toBeInTheDocument() | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
|
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,52 @@ | ||
import React from "react"; | ||
import { useNavigate, useParams } from "react-router-dom"; | ||
import { useFetchRateQuery } from "../../gen/gqlClient"; | ||
import { GridContainer } from "@trussworks/react-uswds"; | ||
import { Loading } from "../../components"; | ||
import { GenericErrorPage } from "../Errors/GenericErrorPage"; | ||
|
||
type RouteParams = { | ||
id: string | ||
} | ||
|
||
export const RateEdit = (): React.ReactElement => { | ||
const navigate = useNavigate() | ||
const { id } = useParams<keyof RouteParams>() | ||
if (!id) { | ||
throw new Error( | ||
'PROGRAMMING ERROR: id param not set in state submission form.' | ||
) | ||
} | ||
|
||
const { data, loading, error } = useFetchRateQuery({ | ||
variables: { | ||
input: { | ||
rateID: id, | ||
}, | ||
}, | ||
}) | ||
|
||
const rate = data?.fetchRate.rate | ||
|
||
if (loading) { | ||
return ( | ||
<GridContainer> | ||
<Loading /> | ||
</GridContainer> | ||
) | ||
} else if (error || !rate ) { | ||
return <GenericErrorPage /> | ||
} | ||
|
||
if (rate.status !== 'UNLOCKED') { | ||
navigate(`/rates/${id}`) | ||
} | ||
|
||
return ( | ||
<h1 data-testid="rate-edit"> | ||
You've reached the '/rates/:id/edit' url placeholder for the incoming standalone edit rate form | ||
<br/> | ||
Ticket: <a href="https://qmacbis.atlassian.net/browse/MCR-3771">MCR-3771</a> | ||
</h1> | ||
) | ||
} |
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