Skip to content

Commit a3f0cf0

Browse files
committed
feat(settings): make fetch interval user configurable
Signed-off-by: Adam Setch <[email protected]>
1 parent 989dccc commit a3f0cf0

File tree

1 file changed

+149
-58
lines changed

1 file changed

+149
-58
lines changed

src/renderer/components/settings/NotificationSettings.test.tsx

Lines changed: 149 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { act, render, screen } from '@testing-library/react';
22
import userEvent from '@testing-library/user-event';
33

44
import { mockAuth, mockSettings } from '../../__mocks__/state-mocks';
5+
import { Constants } from '../../constants';
56
import { AppContext } from '../../context/App';
67
import * as comms from '../../utils/comms';
78
import { NotificationSettings } from './NotificationSettings';
@@ -55,68 +56,158 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => {
5556
expect(updateSetting).toHaveBeenCalledWith('fetchType', 'INACTIVITY');
5657
});
5758

58-
it('should update the fetch interval values when using the buttons', async () => {
59-
await act(async () => {
60-
render(
61-
<AppContext.Provider
62-
value={{
63-
auth: mockAuth,
64-
settings: mockSettings,
65-
updateSetting,
66-
}}
67-
>
68-
<NotificationSettings />
69-
</AppContext.Provider>,
70-
);
59+
describe('fetch interval settings', () => {
60+
it('should update the fetch interval values when using the buttons', async () => {
61+
await act(async () => {
62+
render(
63+
<AppContext.Provider
64+
value={{
65+
auth: mockAuth,
66+
settings: mockSettings,
67+
updateSetting,
68+
}}
69+
>
70+
<NotificationSettings />
71+
</AppContext.Provider>,
72+
);
73+
});
74+
75+
// Increase fetch interval
76+
await act(async () => {
77+
await userEvent.click(
78+
screen.getByTestId('settings-fetch-interval-increase'),
79+
);
80+
81+
expect(updateSetting).toHaveBeenCalledTimes(1);
82+
expect(updateSetting).toHaveBeenCalledWith('fetchInterval', 120000);
83+
});
84+
85+
await act(async () => {
86+
await userEvent.click(
87+
screen.getByTestId('settings-fetch-interval-increase'),
88+
);
89+
90+
expect(updateSetting).toHaveBeenCalledTimes(2);
91+
expect(updateSetting).toHaveBeenNthCalledWith(
92+
2,
93+
'fetchInterval',
94+
180000,
95+
);
96+
});
97+
98+
// Decrease fetch interval
99+
await act(async () => {
100+
await userEvent.click(
101+
screen.getByTestId('settings-fetch-interval-decrease'),
102+
);
103+
104+
expect(updateSetting).toHaveBeenCalledTimes(3);
105+
expect(updateSetting).toHaveBeenNthCalledWith(
106+
3,
107+
'fetchInterval',
108+
120000,
109+
);
110+
});
111+
112+
// Fetch interval reset
113+
await act(async () => {
114+
await userEvent.click(
115+
screen.getByTestId('settings-fetch-interval-reset'),
116+
);
117+
118+
expect(updateSetting).toHaveBeenCalledTimes(4);
119+
expect(updateSetting).toHaveBeenNthCalledWith(
120+
4,
121+
'fetchInterval',
122+
60000,
123+
);
124+
});
71125
});
72126

73-
// Increase fetch interval
74-
await act(async () => {
75-
await userEvent.click(
76-
screen.getByTestId('settings-fetch-interval-increase'),
77-
);
78-
79-
expect(updateSetting).toHaveBeenCalledTimes(1);
80-
expect(updateSetting).toHaveBeenCalledWith('fetchInterval', 120000);
127+
it('should prevent going lower than minimum interval', async () => {
128+
await act(async () => {
129+
render(
130+
<AppContext.Provider
131+
value={{
132+
auth: mockAuth,
133+
settings: {
134+
...mockSettings,
135+
fetchInterval:
136+
Constants.MIN_FETCH_NOTIFICATIONS_INTERVAL_MS +
137+
Constants.FETCH_NOTIFICATIONS_INTERVAL_STEP_MS,
138+
},
139+
updateSetting,
140+
}}
141+
>
142+
<NotificationSettings />
143+
</AppContext.Provider>,
144+
);
145+
});
146+
147+
await act(async () => {
148+
await userEvent.click(
149+
screen.getByTestId('settings-fetch-interval-decrease'),
150+
);
151+
152+
expect(updateSetting).toHaveBeenCalledTimes(1);
153+
expect(updateSetting).toHaveBeenNthCalledWith(
154+
1,
155+
'fetchInterval',
156+
60000,
157+
);
158+
});
159+
160+
// Attempt to go below the minimum interval, update settings should not be called
161+
await act(async () => {
162+
await userEvent.click(
163+
screen.getByTestId('settings-fetch-interval-decrease'),
164+
);
165+
166+
expect(updateSetting).toHaveBeenCalledTimes(1);
167+
});
81168
});
82169

83-
await act(async () => {
84-
await userEvent.click(
85-
screen.getByTestId('settings-fetch-interval-increase'),
86-
);
87-
88-
expect(updateSetting).toHaveBeenCalledTimes(2);
89-
expect(updateSetting).toHaveBeenNthCalledWith(2, 'fetchInterval', 180000);
90-
});
91-
92-
// Decrease fetch interval
93-
await act(async () => {
94-
await userEvent.click(
95-
screen.getByTestId('settings-fetch-interval-decrease'),
96-
);
97-
98-
expect(updateSetting).toHaveBeenCalledTimes(3);
99-
expect(updateSetting).toHaveBeenNthCalledWith(3, 'fetchInterval', 120000);
100-
});
101-
102-
// Fetch interval reset
103-
await act(async () => {
104-
await userEvent.click(
105-
screen.getByTestId('settings-fetch-interval-reset'),
106-
);
107-
108-
expect(updateSetting).toHaveBeenCalledTimes(4);
109-
expect(updateSetting).toHaveBeenNthCalledWith(4, 'fetchInterval', 60000);
110-
});
111-
112-
// Prevent going lower than minimum interval
113-
await act(async () => {
114-
await userEvent.click(
115-
screen.getByTestId('settings-fetch-interval-decrease'),
116-
);
117-
118-
expect(updateSetting).toHaveBeenCalledTimes(4);
119-
expect(updateSetting).toHaveBeenNthCalledWith(4, 'fetchInterval', 60000);
170+
it('should prevent going above maximum interval', async () => {
171+
await act(async () => {
172+
render(
173+
<AppContext.Provider
174+
value={{
175+
auth: mockAuth,
176+
settings: {
177+
...mockSettings,
178+
fetchInterval:
179+
Constants.MAX_FETCH_NOTIFICATIONS_INTERVAL_MS -
180+
Constants.FETCH_NOTIFICATIONS_INTERVAL_STEP_MS,
181+
},
182+
updateSetting,
183+
}}
184+
>
185+
<NotificationSettings />
186+
</AppContext.Provider>,
187+
);
188+
});
189+
190+
await act(async () => {
191+
await userEvent.click(
192+
screen.getByTestId('settings-fetch-interval-increase'),
193+
);
194+
195+
expect(updateSetting).toHaveBeenCalledTimes(1);
196+
expect(updateSetting).toHaveBeenNthCalledWith(
197+
1,
198+
'fetchInterval',
199+
3600000,
200+
);
201+
});
202+
203+
// Attempt to go above the maximum interval, update settings should not be called
204+
await act(async () => {
205+
await userEvent.click(
206+
screen.getByTestId('settings-fetch-interval-increase'),
207+
);
208+
209+
expect(updateSetting).toHaveBeenCalledTimes(1);
210+
});
120211
});
121212
});
122213

0 commit comments

Comments
 (0)