Skip to content

Commit

Permalink
Allow closing settings menu from three dots button (kubewarden#483)
Browse files Browse the repository at this point in the history
Signed-off-by: Cintia Sanchez Garcia <[email protected]>
  • Loading branch information
cynthia-sg authored Jul 28, 2022
1 parent e992e2b commit f714492
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions web/src/layout/navigation/MobileSettings.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const mockCtx = {
theme: { effective: 'light' },
},
};

const mockDispatch = jest.fn();

describe('MobileSettings', () => {
Expand Down Expand Up @@ -67,6 +68,35 @@ describe('MobileSettings', () => {
expect(screen.getAllByRole('link')).toHaveLength(2);
});

it('opens dropdown and closes it using Settings button', async () => {
render(
<AppContext.Provider value={{ ctx: mockCtx, dispatch: jest.fn() }}>
<Router>
<MobileSettings />
</Router>
</AppContext.Provider>
);

const dropdown = screen.getByRole('menu');
expect(dropdown).toBeInTheDocument();
expect(dropdown).not.toHaveClass('show');

const btn = screen.getByRole('button', { name: 'Mobile settings button' });
await userEvent.click(btn);

expect(dropdown).toHaveClass('show');
expect(screen.getByRole('radio', { name: 'Light' })).toBeInTheDocument();
expect(screen.getByRole('radio', { name: 'Light' })).toBeChecked();
expect(screen.getByRole('radio', { name: 'Dark' })).toBeInTheDocument();
expect(screen.getByRole('radio', { name: 'Dark' })).not.toBeChecked();
expect(screen.getByText('Statistics')).toBeInTheDocument();
expect(screen.getAllByRole('link')).toHaveLength(2);

await userEvent.click(btn);

expect(dropdown).not.toHaveClass('show');
});

it('calls updateTheme event', async () => {
render(
<AppContext.Provider value={{ ctx: mockCtx, dispatch: mockDispatch }}>
Expand Down
2 changes: 1 addition & 1 deletion web/src/layout/navigation/MobileSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const MobileSettings = () => {
<button
className={`btn btn-sm btn-primary text-white rounded-0 lh-1 ms-3 ${styles.btn}`}
type="button"
onClick={() => setVisibleDropdown(true)}
onClick={() => setVisibleDropdown(!visibleDropdown)}
aria-label="Mobile settings button"
aria-expanded={visibleDropdown}
>
Expand Down

0 comments on commit f714492

Please sign in to comment.