chore: Clear redux localStorage on logout (#29602)
This commit is contained in:
parent
b39952549f
commit
245e1986c1
|
|
@ -346,3 +346,30 @@ test('If there is NOT a DB with allow_file_upload set as True the option should
|
||||||
(await screen.findByText('Upload CSV to database')).closest('a'),
|
(await screen.findByText('Upload CSV to database')).closest('a'),
|
||||||
).not.toBeInTheDocument();
|
).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Logs out and clears local storage item redux', async () => {
|
||||||
|
const mockedProps = createProps();
|
||||||
|
resetUseSelectorMock();
|
||||||
|
render(<RightMenu {...mockedProps} />, {
|
||||||
|
useRedux: true,
|
||||||
|
useQueryParams: true,
|
||||||
|
useRouter: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Set an item in local storage to test if it gets cleared
|
||||||
|
localStorage.setItem('redux', JSON.stringify({ test: 'test' }));
|
||||||
|
expect(localStorage.getItem('redux')).not.toBeNull();
|
||||||
|
|
||||||
|
userEvent.hover(await screen.findByText(/Settings/i));
|
||||||
|
|
||||||
|
// Simulate user clicking the logout button
|
||||||
|
await waitFor(() => {
|
||||||
|
const logoutButton = screen.getByText('Logout');
|
||||||
|
userEvent.click(logoutButton);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Wait for local storage to be cleared
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(localStorage.getItem('redux')).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -348,6 +348,10 @@ const RightMenu = ({
|
||||||
|
|
||||||
const handleDatabaseAdd = () => setQuery({ databaseAdded: true });
|
const handleDatabaseAdd = () => setQuery({ databaseAdded: true });
|
||||||
|
|
||||||
|
const handleLogout = () => {
|
||||||
|
localStorage.removeItem('redux');
|
||||||
|
};
|
||||||
|
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -512,7 +516,7 @@ const RightMenu = ({
|
||||||
<a href={navbarRight.user_info_url}>{t('Info')}</a>
|
<a href={navbarRight.user_info_url}>{t('Info')}</a>
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
)}
|
)}
|
||||||
<Menu.Item key="logout">
|
<Menu.Item key="logout" onClick={handleLogout}>
|
||||||
<a href={navbarRight.user_logout_url}>{t('Logout')}</a>
|
<a href={navbarRight.user_logout_url}>{t('Logout')}</a>
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
</Menu.ItemGroup>,
|
</Menu.ItemGroup>,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue