Skip to content

Commit 85fb7ae

Browse files
committed
More Tests for the Sidebar
1 parent c99a3b7 commit 85fb7ae

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

src/js/components/sidebar.test.tsx

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,20 @@ import { MemoryRouter } from 'react-router-dom';
66
const { shell, ipcRenderer } = require('electron');
77

88
import { Sidebar, mapStateToProps } from './sidebar';
9-
import {
10-
mockedEnterpriseAccounts,
11-
mockedNotificationsRecuderData,
12-
} from '../__mocks__/mockedData';
13-
import { AuthState, AppState, SettingsState } from '../../types/reducers';
9+
import { mockedEnterpriseAccounts } from '../__mocks__/mockedData';
10+
import { AuthState, AppState } from '../../types/reducers';
1411

1512
describe('components/Sidebar.tsx', () => {
1613
let clock;
1714

1815
const props = {
19-
isFetching: false,
20-
isGitHubLoggedIn: true,
2116
isEitherLoggedIn: true,
2217
connectedAccounts: 2,
2318
notificationsCount: 4,
2419
fetchNotifications: jest.fn(),
2520
history: {
26-
goBack: () => {},
27-
push: () => {},
21+
goBack: jest.fn(),
22+
push: jest.fn(),
2823
},
2924
location: {
3025
pathname: '/',
@@ -39,6 +34,8 @@ describe('components/Sidebar.tsx', () => {
3934
spyOn(window, 'clearInterval');
4035

4136
props.fetchNotifications.mockReset();
37+
props.history.goBack.mockReset();
38+
props.history.push.mockReset();
4239
});
4340

4441
afterEach(() => {
@@ -143,6 +140,32 @@ describe('components/Sidebar.tsx', () => {
143140
expect(props.fetchNotifications).toHaveBeenCalledTimes(1);
144141
});
145142

143+
it('go to the settings route', () => {
144+
const { getByLabelText } = render(
145+
<MemoryRouter>
146+
<Sidebar {...props} />
147+
</MemoryRouter>
148+
);
149+
fireEvent.click(getByLabelText('Settings'));
150+
expect(props.history.push).toHaveBeenCalledTimes(1);
151+
});
152+
153+
it('go to back to home from the settings route', () => {
154+
const caseProps = {
155+
...props,
156+
location: {
157+
pathname: '/settings',
158+
},
159+
};
160+
const { getByLabelText } = render(
161+
<MemoryRouter>
162+
<Sidebar {...caseProps} />
163+
</MemoryRouter>
164+
);
165+
fireEvent.click(getByLabelText('Settings'));
166+
expect(props.history.goBack).toHaveBeenCalledTimes(1);
167+
});
168+
146169
it('open the gitify repo in browser', () => {
147170
const { getByLabelText } = render(
148171
<MemoryRouter>

0 commit comments

Comments
 (0)