Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/renderer/components/Sidebar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jest.mock('react-router-dom', () => ({

describe('renderer/components/Sidebar.tsx', () => {
const fetchNotificationsMock = jest.fn();
const updateSettingMock = jest.fn();
const openExternalLinkSpy = jest
.spyOn(comms, 'openExternalLink')
.mockImplementation();
Expand Down Expand Up @@ -106,6 +107,55 @@ describe('renderer/components/Sidebar.tsx', () => {
});
});

describe('Focused mode toggle', () => {
it('renders the focused mode is off', () => {
renderWithAppContext(
<MemoryRouter>
<Sidebar />
</MemoryRouter>,
{
isLoggedIn: true,
settings: { ...mockSettings, participating: false },
},
);

expect(screen.getByTestId('sidebar-focused-mode')).toBeInTheDocument();
});

it('renders the focused mode is on', () => {
renderWithAppContext(
<MemoryRouter>
<Sidebar />
</MemoryRouter>,
{
isLoggedIn: true,
settings: { ...mockSettings, participating: true },
},
);

expect(screen.getByTestId('sidebar-focused-mode')).toBeInTheDocument();
});

it('toggles participating when clicked', async () => {
renderWithAppContext(
<MemoryRouter>
<Sidebar />
</MemoryRouter>,
{
isLoggedIn: true,
settings: { ...mockSettings, participating: false },
updateSetting: updateSettingMock,
fetchNotifications: fetchNotificationsMock,
},
);

await userEvent.click(screen.getByTestId('sidebar-focused-mode'));

expect(updateSettingMock).toHaveBeenCalledTimes(1);
expect(updateSettingMock).toHaveBeenCalledWith('participating', true);
});
});

describe('Filter notifications', () => {
it('go to the filters route', async () => {
renderWithAppContext(
Expand Down
42 changes: 32 additions & 10 deletions src/renderer/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { useLocation, useNavigate } from 'react-router-dom';

import {
BellIcon,
CrosshairsIcon,
EyeIcon,
FilterIcon,
GearIcon,
GitPullRequestIcon,
Expand Down Expand Up @@ -37,6 +39,7 @@ export const Sidebar: FC = () => {
auth,
unreadNotificationCount,
hasUnreadNotifications,
updateSetting,
} = useAppContext();

const primaryAccountHostname = getPrimaryAccountHostname(auth);
Expand Down Expand Up @@ -98,16 +101,35 @@ export const Sidebar: FC = () => {
/>

{isLoggedIn && (
<IconButton
aria-label="Filters"
data-testid="sidebar-filter-notifications"
description="Filter notifications"
icon={FilterIcon}
onClick={() => toggleFilters()}
size="small"
tooltipDirection="e"
variant={hasActiveFilters(settings) ? 'primary' : 'invisible'}
/>
<>
<IconButton
aria-label="Toggle focused mode"
data-testid="sidebar-focused-mode"
description={
settings.participating
? 'Focused (participating only)'
: 'Participating and watching'
}
icon={settings.participating ? CrosshairsIcon : EyeIcon}
onClick={() => {
updateSetting('participating', !settings.participating);
}}
size="small"
tooltipDirection="e"
variant={settings.participating ? 'primary' : 'invisible'}
/>

<IconButton
aria-label="Filters"
data-testid="sidebar-filter-notifications"
description="Filter notifications"
icon={FilterIcon}
onClick={() => toggleFilters()}
size="small"
tooltipDirection="e"
variant={hasActiveFilters(settings) ? 'primary' : 'invisible'}
/>
</>
)}

<IconButton
Expand Down
Loading