1- import { act , fireEvent , screen } from '@testing-library/react' ;
1+ import { act , screen } from '@testing-library/react' ;
22import userEvent from '@testing-library/user-event' ;
33
44import { renderWithAppContext } from '../../__helpers__/test-utils' ;
55import { mockGitHubAppAccount } from '../../__mocks__/account-mocks' ;
6+ import * as zoom from '../../utils/zoom' ;
67import { AppearanceSettings } from './AppearanceSettings' ;
78
89describe ( 'renderer/components/settings/AppearanceSettings.tsx' , ( ) => {
910 const updateSettingMock = jest . fn ( ) ;
10- const zoomTimeout = ( ) => new Promise ( ( r ) => setTimeout ( r , 300 ) ) ;
1111
1212 afterEach ( ( ) => {
1313 jest . clearAllMocks ( ) ;
@@ -45,28 +45,12 @@ describe('renderer/components/settings/AppearanceSettings.tsx', () => {
4545 expect ( updateSettingMock ) . toHaveBeenCalledWith ( 'increaseContrast' , true ) ;
4646 } ) ;
4747
48- it ( 'should update the zoom value when using CMD + and CMD -' , async ( ) => {
49- window . gitify . zoom . getLevel = jest . fn ( ) . mockReturnValue ( - 1 ) ;
50-
51- await act ( async ( ) => {
52- renderWithAppContext ( < AppearanceSettings /> , {
53- updateSetting : updateSettingMock ,
54- } ) ;
55- } ) ;
56-
57- fireEvent ( window , new Event ( 'resize' ) ) ;
58- await zoomTimeout ( ) ;
59-
60- expect ( updateSettingMock ) . toHaveBeenCalledTimes ( 1 ) ;
61- expect ( updateSettingMock ) . toHaveBeenCalledWith ( 'zoomPercentage' , 50 ) ;
62- } ) ;
63-
6448 it ( 'should update the zoom values when using the zoom buttons' , async ( ) => {
65- window . gitify . zoom . getLevel = jest . fn ( ) . mockReturnValue ( 0 ) ;
66- window . gitify . zoom . setLevel = jest . fn ( ) . mockImplementation ( ( level ) => {
67- window . gitify . zoom . getLevel = jest . fn ( ) . mockReturnValue ( level ) ;
68- fireEvent ( window , new Event ( 'resize' ) ) ;
69- } ) ;
49+ const zoomOutSpy = jest . spyOn ( zoom , 'decreaseZoom' ) . mockImplementation ( ) ;
50+ const zoomInSpy = jest . spyOn ( zoom , 'increaseZoom' ) . mockImplementation ( ) ;
51+ const zoomResetSpy = jest
52+ . spyOn ( zoom , 'resetZoomLevel' )
53+ . mockImplementation ( ) ;
7054
7155 await act ( async ( ) => {
7256 renderWithAppContext ( < AppearanceSettings /> , {
@@ -75,55 +59,19 @@ describe('renderer/components/settings/AppearanceSettings.tsx', () => {
7559 } ) ;
7660
7761 // Zoom Out
78- await act ( async ( ) => {
79- await userEvent . click ( screen . getByTestId ( 'settings-zoom-out' ) ) ;
80- await zoomTimeout ( ) ;
81-
82- expect ( updateSettingMock ) . toHaveBeenCalledTimes ( 1 ) ;
83- expect ( updateSettingMock ) . toHaveBeenNthCalledWith (
84- 1 ,
85- 'zoomPercentage' ,
86- 90 ,
87- ) ;
88- } ) ;
62+ await userEvent . click ( screen . getByTestId ( 'settings-zoom-out' ) ) ;
63+ expect ( zoomOutSpy ) . toHaveBeenCalledTimes ( 1 ) ;
8964
90- await act ( async ( ) => {
91- await userEvent . click ( screen . getByTestId ( 'settings-zoom-out' ) ) ;
92- await zoomTimeout ( ) ;
93-
94- expect ( updateSettingMock ) . toHaveBeenCalledTimes ( 2 ) ;
95- expect ( updateSettingMock ) . toHaveBeenNthCalledWith (
96- 2 ,
97- 'zoomPercentage' ,
98- 80 ,
99- ) ;
100- } ) ;
65+ await userEvent . click ( screen . getByTestId ( 'settings-zoom-out' ) ) ;
66+ expect ( zoomOutSpy ) . toHaveBeenCalledTimes ( 2 ) ;
10167
10268 // Zoom In
103- await act ( async ( ) => {
104- await userEvent . click ( screen . getByTestId ( 'settings-zoom-in' ) ) ;
105- await zoomTimeout ( ) ;
106-
107- expect ( updateSettingMock ) . toHaveBeenCalledTimes ( 3 ) ;
108- expect ( updateSettingMock ) . toHaveBeenNthCalledWith (
109- 3 ,
110- 'zoomPercentage' ,
111- 90 ,
112- ) ;
113- } ) ;
69+ await userEvent . click ( screen . getByTestId ( 'settings-zoom-in' ) ) ;
70+ expect ( zoomInSpy ) . toHaveBeenCalledTimes ( 1 ) ;
11471
11572 // Zoom Reset
116- await act ( async ( ) => {
117- await userEvent . click ( screen . getByTestId ( 'settings-zoom-reset' ) ) ;
118- await zoomTimeout ( ) ;
119-
120- expect ( updateSettingMock ) . toHaveBeenCalledTimes ( 4 ) ;
121- expect ( updateSettingMock ) . toHaveBeenNthCalledWith (
122- 4 ,
123- 'zoomPercentage' ,
124- 100 ,
125- ) ;
126- } ) ;
73+ await userEvent . click ( screen . getByTestId ( 'settings-zoom-reset' ) ) ;
74+ expect ( zoomResetSpy ) . toHaveBeenCalledTimes ( 1 ) ;
12775 } ) ;
12876
12977 it ( 'should toggle account header checkbox' , async ( ) => {
0 commit comments