|
| 1 | +import { render, screen, act } from '@testing-library/react'; |
| 2 | +import '@testing-library/jest-dom'; |
| 3 | +import { Provider } from 'react-redux'; |
| 4 | +import { configureStore } from '@reduxjs/toolkit'; |
| 5 | +import { ScheduleOverview } from '@/components/home'; |
| 6 | +import { RootState } from '@/types'; |
| 7 | +import { assetsReducer, assetModalReducer } from '@/store/assets'; |
| 8 | +import settingsReducer from '@/store/settings'; |
| 9 | + |
| 10 | +const initialState: RootState = { |
| 11 | + assets: { |
| 12 | + items: [ |
| 13 | + { |
| 14 | + asset_id: 'ff18e72b5a2447fab372f5effa0797b1', |
| 15 | + name: 'https://react.dev/', |
| 16 | + uri: 'https://react.dev/', |
| 17 | + start_date: '2025-07-07T22:51:55.640000Z', |
| 18 | + end_date: '2025-08-06T22:51:55.640000Z', |
| 19 | + duration: 10, |
| 20 | + mimetype: 'webpage', |
| 21 | + is_enabled: 1, |
| 22 | + nocache: false, |
| 23 | + play_order: 0, |
| 24 | + skip_asset_check: false, |
| 25 | + is_active: true, |
| 26 | + is_processing: false, |
| 27 | + }, |
| 28 | + { |
| 29 | + asset_id: '5bbf68491a0d4461bfe860911265b8be', |
| 30 | + name: 'https://angular.dev/', |
| 31 | + uri: 'https://angular.dev/', |
| 32 | + start_date: '2025-07-07T22:52:47.421000Z', |
| 33 | + end_date: '2025-08-06T22:52:47.421000Z', |
| 34 | + duration: 10, |
| 35 | + mimetype: 'webpage', |
| 36 | + is_enabled: 1, |
| 37 | + nocache: false, |
| 38 | + play_order: 1, |
| 39 | + skip_asset_check: false, |
| 40 | + is_active: true, |
| 41 | + is_processing: false, |
| 42 | + }, |
| 43 | + { |
| 44 | + asset_id: '6eb86ce9d5c14597ae68017d4dd93900', |
| 45 | + name: 'https://vuejs.org/', |
| 46 | + uri: 'https://vuejs.org/', |
| 47 | + start_date: '2025-07-07T22:52:58.934000Z', |
| 48 | + end_date: '2025-08-06T22:52:58.934000Z', |
| 49 | + duration: 10, |
| 50 | + mimetype: 'webpage', |
| 51 | + is_enabled: 1, |
| 52 | + nocache: false, |
| 53 | + play_order: 2, |
| 54 | + skip_asset_check: false, |
| 55 | + is_active: true, |
| 56 | + is_processing: false, |
| 57 | + }, |
| 58 | + ], |
| 59 | + status: 'succeeded', |
| 60 | + error: null, |
| 61 | + }, |
| 62 | + assetModal: { |
| 63 | + activeTab: 'uri', |
| 64 | + formData: { |
| 65 | + uri: '', |
| 66 | + skipAssetCheck: false, |
| 67 | + }, |
| 68 | + isValid: true, |
| 69 | + errorMessage: '', |
| 70 | + statusMessage: '', |
| 71 | + isSubmitting: false, |
| 72 | + uploadProgress: 0, |
| 73 | + }, |
| 74 | + settings: { |
| 75 | + settings: { |
| 76 | + playerName: '', |
| 77 | + defaultDuration: 10, |
| 78 | + defaultStreamingDuration: 300, |
| 79 | + audioOutput: 'hdmi', |
| 80 | + dateFormat: 'mm/dd/yyyy', |
| 81 | + authBackend: '', |
| 82 | + currentPassword: '', |
| 83 | + user: '', |
| 84 | + password: '', |
| 85 | + confirmPassword: '', |
| 86 | + showSplash: true, |
| 87 | + defaultAssets: false, |
| 88 | + shufflePlaylist: false, |
| 89 | + use24HourClock: false, |
| 90 | + debugLogging: false, |
| 91 | + }, |
| 92 | + deviceModel: '', |
| 93 | + prevAuthBackend: '', |
| 94 | + hasSavedBasicAuth: false, |
| 95 | + isLoading: false, |
| 96 | + isUploading: false, |
| 97 | + uploadProgress: 0, |
| 98 | + error: null, |
| 99 | + }, |
| 100 | +}; |
| 101 | + |
| 102 | +const createTestStore = (preloadedState = {}) => { |
| 103 | + return configureStore({ |
| 104 | + reducer: { |
| 105 | + assets: assetsReducer, |
| 106 | + assetModal: assetModalReducer, |
| 107 | + settings: settingsReducer, |
| 108 | + }, |
| 109 | + preloadedState, |
| 110 | + }); |
| 111 | +}; |
| 112 | + |
| 113 | +const renderWithRedux = ( |
| 114 | + component: React.ReactElement, |
| 115 | + state: RootState = initialState, |
| 116 | +) => { |
| 117 | + const store = createTestStore(state); |
| 118 | + return { |
| 119 | + ...render(<Provider store={store}>{component}</Provider>), |
| 120 | + store, |
| 121 | + }; |
| 122 | +}; |
| 123 | + |
| 124 | +describe('ScheduleOverview', () => { |
| 125 | + it('renders the home page', async () => { |
| 126 | + await act(async () => { |
| 127 | + renderWithRedux(<ScheduleOverview />); |
| 128 | + }); |
| 129 | + |
| 130 | + expect(screen.getByText('Schedule Overview')).toBeInTheDocument(); |
| 131 | + |
| 132 | + expect(screen.getByText('https://react.dev/')).toBeInTheDocument(); |
| 133 | + expect(screen.getByText('https://angular.dev/')).toBeInTheDocument(); |
| 134 | + expect(screen.getByText('https://vuejs.org/')).toBeInTheDocument(); |
| 135 | + }); |
| 136 | +}); |
0 commit comments