Skip to content

Commit

Permalink
chore: Clear redux localStorage on logout (apache#29602)
Browse files Browse the repository at this point in the history
  • Loading branch information
geido authored Jul 17, 2024
1 parent b399525 commit 245e198
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
27 changes: 27 additions & 0 deletions superset-frontend/src/features/home/RightMenu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
).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();
});
});
6 changes: 5 additions & 1 deletion superset-frontend/src/features/home/RightMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ const RightMenu = ({

const handleDatabaseAdd = () => setQuery({ databaseAdded: true });

const handleLogout = () => {
localStorage.removeItem('redux');
};

const theme = useTheme();

return (
Expand Down Expand Up @@ -512,7 +516,7 @@ const RightMenu = ({
<a href={navbarRight.user_info_url}>{t('Info')}</a>
</Menu.Item>
)}
<Menu.Item key="logout">
<Menu.Item key="logout" onClick={handleLogout}>
<a href={navbarRight.user_logout_url}>{t('Logout')}</a>
</Menu.Item>
</Menu.ItemGroup>,
Expand Down

0 comments on commit 245e198

Please sign in to comment.