-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handle password change return value HP-2501 (#376)
* feat: handle password change return value * feat: add playwright test
- Loading branch information
Showing
12 changed files
with
222 additions
and
53 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.wrapper { | ||
display: flex; | ||
flex-direction: column; | ||
max-width: 300px; | ||
margin: var(--spacing-l) auto; | ||
align-items: center; | ||
} | ||
|
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,36 @@ | ||
import React, { useEffect, useContext } from 'react'; | ||
import { RouteChildrenProps, useLocation } from 'react-router'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { LoadingSpinner } from 'hds-react'; | ||
|
||
import styles from './PasswordChangeCallback.module.css'; | ||
import { getLinkRedirectState } from '../profile/hooks/useHistoryListener'; | ||
import { ProfileContext } from '../profile/context/ProfileContext'; | ||
|
||
function PasswordChangeCallback({ | ||
history, | ||
}: RouteChildrenProps): React.ReactElement | null { | ||
const { t } = useTranslation(); | ||
|
||
const { setPasswordUpdateState } = useContext(ProfileContext); | ||
const location = useLocation(); | ||
|
||
useEffect(() => { | ||
const params = new URLSearchParams(location.search); | ||
const stat = params.get('kc_action_status'); | ||
|
||
if (stat === 'success') { | ||
setPasswordUpdateState(true); | ||
} | ||
|
||
history.replace('/', getLinkRedirectState()); | ||
}, [history, location, setPasswordUpdateState]); | ||
|
||
return ( | ||
<div className={styles.wrapper}> | ||
<LoadingSpinner small /> | ||
<p>{t('loading')}</p> | ||
</div> | ||
); | ||
} | ||
export default PasswordChangeCallback; |
56 changes: 56 additions & 0 deletions
56
src/passwordChange/__tests__/PasswordChangeCallback.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,56 @@ | ||
import React from 'react'; | ||
import { BrowserRouter, RouteChildrenProps } from 'react-router-dom'; | ||
import { act, render } from '@testing-library/react'; | ||
|
||
import PasswordChangeCallback from '../PasswordChangeCallback'; | ||
|
||
const mockedDefaultProps = { | ||
history: { | ||
replace: vi.fn(), | ||
}, | ||
}; | ||
|
||
const renderComponent = () => | ||
render( | ||
<BrowserRouter> | ||
<PasswordChangeCallback | ||
{...((mockedDefaultProps as unknown) as RouteChildrenProps)} | ||
/> | ||
</BrowserRouter> | ||
); | ||
|
||
const getHistoryReplaceCallArgument = () => | ||
mockedDefaultProps.history.replace.mock.calls[0][0]; | ||
|
||
vi.mock('react-router-dom', async () => { | ||
const module = await vi.importActual('react-router-dom'); | ||
|
||
return { | ||
...module, | ||
useHistory: vi.fn().mockImplementation(() => mockedDefaultProps.history), | ||
}; | ||
}); | ||
|
||
describe('<PasswordChangeCallback />', () => { | ||
afterEach(() => { | ||
mockedDefaultProps.history.replace.mockReset(); | ||
}); | ||
|
||
it('render without error', async () => { | ||
renderComponent(); | ||
|
||
await act(async () => { | ||
await new Promise(resolve => setTimeout(resolve, 0)); | ||
}); | ||
}); | ||
|
||
it('should redirect user', async () => { | ||
renderComponent(); | ||
|
||
await act(async () => { | ||
await new Promise(resolve => setTimeout(resolve, 0)); | ||
}); | ||
|
||
expect(getHistoryReplaceCallArgument()).toBe('/'); | ||
}); | ||
}); |
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
Oops, something went wrong.