|
1 | 1 | import { act, fireEvent, render, screen } from '@testing-library/react'; |
| 2 | +import { webFrame } from 'electron'; |
2 | 3 | import { MemoryRouter } from 'react-router-dom'; |
3 | 4 | import { mockAuth, mockSettings } from '../../__mocks__/state-mocks'; |
4 | 5 | import { AppContext } from '../../context/App'; |
5 | 6 | import { AppearanceSettings } from './AppearanceSettings'; |
6 | 7 |
|
| 8 | +global.ResizeObserver = require('resize-observer-polyfill'); |
| 9 | + |
7 | 10 | describe('routes/components/settings/AppearanceSettings.tsx', () => { |
8 | 11 | const updateSetting = jest.fn(); |
| 12 | + const zoomTimeout = () => new Promise((r) => setTimeout(r, 300)); |
9 | 13 |
|
10 | 14 | afterEach(() => { |
11 | 15 | jest.clearAllMocks(); |
@@ -34,6 +38,88 @@ describe('routes/components/settings/AppearanceSettings.tsx', () => { |
34 | 38 | expect(updateSetting).toHaveBeenCalledWith('theme', 'LIGHT'); |
35 | 39 | }); |
36 | 40 |
|
| 41 | + it('should update the zoom value when using CMD + and CMD -', async () => { |
| 42 | + webFrame.getZoomLevel = jest.fn().mockReturnValue(-1); |
| 43 | + |
| 44 | + await act(async () => { |
| 45 | + render( |
| 46 | + <AppContext.Provider |
| 47 | + value={{ |
| 48 | + auth: mockAuth, |
| 49 | + settings: mockSettings, |
| 50 | + updateSetting, |
| 51 | + }} |
| 52 | + > |
| 53 | + <MemoryRouter> |
| 54 | + <AppearanceSettings /> |
| 55 | + </MemoryRouter> |
| 56 | + </AppContext.Provider>, |
| 57 | + ); |
| 58 | + }); |
| 59 | + |
| 60 | + fireEvent(window, new Event('resize')); |
| 61 | + await zoomTimeout(); |
| 62 | + |
| 63 | + expect(updateSetting).toHaveBeenCalledTimes(1); |
| 64 | + expect(updateSetting).toHaveBeenCalledWith('zoomPercentage', 50); |
| 65 | + }); |
| 66 | + |
| 67 | + it('should update the zoom values when using the zoom buttons', async () => { |
| 68 | + webFrame.getZoomLevel = jest.fn().mockReturnValue(0); |
| 69 | + webFrame.setZoomLevel = jest.fn().mockImplementation((level) => { |
| 70 | + webFrame.getZoomLevel = jest.fn().mockReturnValue(level); |
| 71 | + fireEvent(window, new Event('resize')); |
| 72 | + }); |
| 73 | + |
| 74 | + await act(async () => { |
| 75 | + render( |
| 76 | + <AppContext.Provider |
| 77 | + value={{ |
| 78 | + auth: mockAuth, |
| 79 | + settings: mockSettings, |
| 80 | + updateSetting, |
| 81 | + }} |
| 82 | + > |
| 83 | + <MemoryRouter> |
| 84 | + <AppearanceSettings /> |
| 85 | + </MemoryRouter> |
| 86 | + </AppContext.Provider>, |
| 87 | + ); |
| 88 | + }); |
| 89 | + |
| 90 | + await act(async () => { |
| 91 | + fireEvent.click(screen.getByLabelText('Zoom Out')); |
| 92 | + await zoomTimeout(); |
| 93 | + }); |
| 94 | + |
| 95 | + expect(updateSetting).toHaveBeenCalledTimes(1); |
| 96 | + expect(updateSetting).toHaveBeenCalledWith('zoomPercentage', 90); |
| 97 | + |
| 98 | + await act(async () => { |
| 99 | + fireEvent.click(screen.getByLabelText('Zoom Out')); |
| 100 | + await zoomTimeout(); |
| 101 | + |
| 102 | + expect(updateSetting).toHaveBeenCalledTimes(2); |
| 103 | + expect(updateSetting).toHaveBeenNthCalledWith(2, 'zoomPercentage', 80); |
| 104 | + }); |
| 105 | + |
| 106 | + await act(async () => { |
| 107 | + fireEvent.click(screen.getByLabelText('Zoom In')); |
| 108 | + await zoomTimeout(); |
| 109 | + |
| 110 | + expect(updateSetting).toHaveBeenCalledTimes(3); |
| 111 | + expect(updateSetting).toHaveBeenNthCalledWith(3, 'zoomPercentage', 90); |
| 112 | + }); |
| 113 | + |
| 114 | + await act(async () => { |
| 115 | + fireEvent.click(screen.getByLabelText('Reset Zoom')); |
| 116 | + await zoomTimeout(); |
| 117 | + |
| 118 | + expect(updateSetting).toHaveBeenCalledTimes(4); |
| 119 | + expect(updateSetting).toHaveBeenNthCalledWith(4, 'zoomPercentage', 100); |
| 120 | + }); |
| 121 | + }); |
| 122 | + |
37 | 123 | it('should toggle detailed notifications checkbox', async () => { |
38 | 124 | await act(async () => { |
39 | 125 | render( |
|
0 commit comments