@@ -2,6 +2,7 @@ import { act, render, screen } from '@testing-library/react';
22import userEvent from '@testing-library/user-event' ;
33
44import { mockAuth , mockSettings } from '../../__mocks__/state-mocks' ;
5+ import { Constants } from '../../constants' ;
56import { AppContext } from '../../context/App' ;
67import * as comms from '../../utils/comms' ;
78import { NotificationSettings } from './NotificationSettings' ;
@@ -55,6 +56,161 @@ describe('renderer/components/settings/NotificationSettings.tsx', () => {
5556 expect ( updateSetting ) . toHaveBeenCalledWith ( 'fetchType' , 'INACTIVITY' ) ;
5657 } ) ;
5758
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+ } ) ;
125+ } ) ;
126+
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+ } ) ;
168+ } ) ;
169+
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+ } ) ;
211+ } ) ;
212+ } ) ;
213+
58214 it ( 'should toggle the fetchAllNotifications checkbox' , async ( ) => {
59215 await act ( async ( ) => {
60216 render (
0 commit comments