-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PRMDR-646 403_logout Status UI should be specific rather than stating…
… its an unknown issue (#336) * [PRMDR-646] Add a page to handle session expiry * [PRMDR-646] Route 403 errors to new error page * [PRMDR-646] Fix unit test * [PRMDR-646] Fix unit tests related to route change * [PRMDR-646] add unit test * [PRMDR-646] bug fix * [PRMDR-646] Amend the page to meet the design in mural * [PRMDR-646] remove unused imports
- Loading branch information
1 parent
73f536e
commit 9452dea
Showing
16 changed files
with
154 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -254,11 +254,41 @@ describe('<FeedbackForm />', () => { | |
); | ||
expect(mockSetStage).toBeCalledWith(SUBMISSION_STAGE.Submitting); | ||
|
||
await waitFor(() => { | ||
expect(mockedUseNavigate).toHaveBeenCalledWith( | ||
routes.SERVER_ERROR + '?encodedError=WyJTUF8xMDAxIiwiMTU3NzgzNjgwMCJd', | ||
); | ||
expect(mockedUseNavigate).toHaveBeenCalledWith( | ||
routes.SERVER_ERROR + '?encodedError=WyJTUF8xMDAxIiwiMTU3NzgzNjgwMCJd', | ||
); | ||
}); | ||
|
||
it('navigates to Session Expire page when call to feedback endpoint return 403', async () => { | ||
const errorResponse = { | ||
response: { | ||
status: 403, | ||
data: { message: 'Unauthorized' }, | ||
}, | ||
}; | ||
mockedAxios.post.mockImplementation(() => Promise.reject(errorResponse)); | ||
|
||
const mockInputData = { | ||
feedbackContent: 'Mock feedback content', | ||
howSatisfied: SATISFACTION_CHOICES.VerySatisfied, | ||
respondentName: 'Jane Smith', | ||
respondentEmail: '[email protected]', | ||
}; | ||
|
||
renderComponent(); | ||
|
||
act(() => { | ||
fillInForm(mockInputData); | ||
clickSubmitButton(); | ||
}); | ||
|
||
await waitFor(() => | ||
expect(mockedAxios.post).toBeCalledWith(baseURL + '/Feedback', mockInputData, { | ||
headers: {}, | ||
}), | ||
); | ||
expect(mockSetStage).toBeCalledWith(SUBMISSION_STAGE.Submitting); | ||
expect(mockedUseNavigate).toHaveBeenCalledWith(routes.SESSION_EXPIRED); | ||
}); | ||
}); | ||
}); |
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
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
59 changes: 59 additions & 0 deletions
59
app/src/pages/sessionExpiredErrorPage/SessionExpiredErrorPage.test.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,59 @@ | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import { act } from 'react-dom/test-utils'; | ||
import SessionExpiredErrorPage from './SessionExpiredErrorPage'; | ||
import useBaseAPIUrl from '../../helpers/hooks/useBaseAPIUrl'; | ||
import { endpoints } from '../../types/generic/endpoints'; | ||
|
||
jest.mock('../../helpers/hooks/useBaseAPIUrl'); | ||
|
||
const originalWindowLocation = window.location; | ||
const mockLocationReplace = jest.fn(); | ||
const mockUseBaseUrl = useBaseAPIUrl as jest.Mock; | ||
|
||
describe('SessionExpiredErrorPage', () => { | ||
afterAll(() => { | ||
Object.defineProperty(window, 'location', { | ||
value: originalWindowLocation, | ||
}); | ||
}); | ||
|
||
it('render a page with a user friendly message to state that their session expired', () => { | ||
render(<SessionExpiredErrorPage />); | ||
|
||
expect( | ||
screen.getByRole('heading', { name: 'We signed you out due to inactivity' }), | ||
).toBeInTheDocument(); | ||
|
||
expect( | ||
screen.getByText( | ||
"This is to protect your information. You'll need to enter any information you submitted again.", | ||
), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('move to login endpoint when user click the button', async () => { | ||
const mockBackendUrl = 'http://localhost/mock_url/'; | ||
mockUseBaseUrl.mockReturnValue(mockBackendUrl); | ||
|
||
Object.defineProperty(window, 'location', { | ||
value: { | ||
replace: mockLocationReplace, | ||
}, | ||
}); | ||
|
||
render(<SessionExpiredErrorPage />); | ||
|
||
const signBackInButton = screen.getByRole('button', { | ||
name: 'Sign back in', | ||
}); | ||
expect(signBackInButton).toBeInTheDocument(); | ||
|
||
act(() => { | ||
signBackInButton.click(); | ||
}); | ||
|
||
await waitFor(() => | ||
expect(mockLocationReplace).toBeCalledWith(mockBackendUrl + endpoints.LOGIN), | ||
); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
app/src/pages/sessionExpiredErrorPage/SessionExpiredErrorPage.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,32 @@ | ||
import { ButtonLink } from 'nhsuk-react-components'; | ||
import React, { MouseEvent, useState } from 'react'; | ||
import { endpoints } from '../../types/generic/endpoints'; | ||
import Spinner from '../../components/generic/spinner/Spinner'; | ||
import useBaseAPIUrl from '../../helpers/hooks/useBaseAPIUrl'; | ||
|
||
const SessionExpiredErrorPage = () => { | ||
const baseAPIUrl = useBaseAPIUrl(); | ||
const [isLoading, setIsLoading] = useState(false); | ||
|
||
const handleLogin = (e: MouseEvent<HTMLAnchorElement>) => { | ||
setIsLoading(true); | ||
e.preventDefault(); | ||
window.location.replace(`${baseAPIUrl}${endpoints.LOGIN}`); | ||
}; | ||
|
||
return !isLoading ? ( | ||
<> | ||
<h1>We signed you out due to inactivity</h1> | ||
<p> | ||
This is to protect your information. You'll need to enter any information you | ||
submitted again. | ||
</p> | ||
<ButtonLink href="#" onClick={handleLogin}> | ||
Sign back in | ||
</ButtonLink> | ||
</> | ||
) : ( | ||
<Spinner status="Logging in..." /> | ||
); | ||
}; | ||
export default SessionExpiredErrorPage; |
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