@@ -9,6 +9,8 @@ import fundraiserData from './data/fundraiser.json';
9
9
import footerData from './data/footer.json' ;
10
10
import oxmenuData from './data/osmenu.json' ;
11
11
import giveTodayData from './data/give-today.json' ;
12
+ import giveBannerData from './data/givebanner.json' ;
13
+ import * as CF from '~/helpers/cms-fetch' ;
12
14
import '@testing-library/jest-dom' ;
13
15
14
16
// Mock external dependencies
@@ -33,10 +35,6 @@ let mockPathname = {pathname: '/test-path'};
33
35
jest . mock ( 'react-router-dom' , ( ) => ( {
34
36
useLocation : ( ) => mockPathname
35
37
} ) ) ;
36
- // jest.mock('~/layouts/default/microsurvey-popup/microsurvey-popup', () => ({
37
- // __esModule: true,
38
- // default: () => <></>
39
- // }));
40
38
41
39
const mockUseSharedDataContext = jest . fn ( ) . mockReturnValue ( { stickyFooterState : [ false , ( ) => undefined ] } ) ;
42
40
@@ -62,6 +60,22 @@ Reflect.defineProperty(window, 'localStorage', {
62
60
} ) ;
63
61
64
62
const user = userEvent . setup ( ) ;
63
+ const basicImplementation = ( path : string ) => {
64
+ if ( path === 'sticky/' ) {
65
+ return Promise . resolve ( {
66
+ ...stickyData
67
+ } ) ;
68
+ }
69
+ if ( path === 'snippets/givebanner' ) {
70
+ return Promise . resolve ( giveBannerData ) ;
71
+ }
72
+ if ( path === 'give-today' ) {
73
+ return Promise . resolve ( giveTodayData ) ;
74
+ }
75
+ console . info ( '**** Whoops' , path ) ;
76
+ return Promise . resolve ( [ ] ) ;
77
+ } ;
78
+ const mockCmsFetch = jest . spyOn ( CF , 'default' ) . mockImplementation ( basicImplementation ) ;
65
79
66
80
describe ( 'Layouts Default TypeScript Conversions' , ( ) => {
67
81
beforeEach ( ( ) => {
@@ -126,6 +140,88 @@ describe('Layouts Default TypeScript Conversions', () => {
126
140
render ( < TestComponent /> ) ;
127
141
expect ( screen . getByTestId ( 'sticky-data' ) ) . toHaveTextContent ( 'no data' ) ;
128
142
} ) ;
143
+ test ( 'useStickyData hook handles emergency mode' , async ( ) => {
144
+ mockCmsFetch . mockImplementation (
145
+ ( path : string ) => {
146
+ if ( path === 'sticky/' ) {
147
+ /* eslint-disable camelcase */
148
+ return Promise . resolve ( {
149
+ ...stickyData ,
150
+ emergency_expires : '2044-05-31T23:00:00Z'
151
+ } ) ;
152
+ /* eslint-enable camelcase */
153
+ }
154
+ return basicImplementation ( path ) ;
155
+ }
156
+ ) ;
157
+ const TestComponent = ( ) => {
158
+ const data = useStickyData ( ) ;
159
+
160
+ return (
161
+ < div data-testid = "sticky-data" >
162
+ { data ? data . mode : 'no data' }
163
+ </ div >
164
+ ) ;
165
+ } ;
166
+
167
+ render ( < TestComponent /> ) ;
168
+ expect ( await screen . findByTestId ( 'sticky-data' ) ) . toHaveTextContent ( 'emergency' ) ;
169
+ mockCmsFetch . mockImplementation ( basicImplementation ) ;
170
+ } ) ;
171
+ test ( 'useStickyData hook handles microdonation not active' , async ( ) => {
172
+ mockCmsFetch . mockImplementation (
173
+ ( path : string ) => {
174
+ if ( path === 'sticky/' ) {
175
+ return Promise . resolve ( {
176
+ ...stickyData ,
177
+ expires : '2024-05-31T23:00:00Z'
178
+ } ) ;
179
+ }
180
+ return basicImplementation ( path ) ;
181
+ }
182
+ ) ;
183
+ const TestComponent = ( ) => {
184
+ const data = useStickyData ( ) ;
185
+
186
+ return (
187
+ < div data-testid = "sticky-data" >
188
+ { data && data . mode === null ? 'mode is null' : 'no data' }
189
+ </ div >
190
+ ) ;
191
+ } ;
192
+
193
+ render ( < TestComponent /> ) ;
194
+ expect ( await screen . findByTestId ( 'sticky-data' ) ) . toHaveTextContent ( 'mode is null' ) ;
195
+ mockCmsFetch . mockImplementation ( basicImplementation ) ;
196
+ } ) ;
197
+ test ( 'useStickyData hook handles show_popup' , async ( ) => {
198
+ mockCmsFetch . mockImplementation (
199
+ ( path : string ) => {
200
+ if ( path === 'sticky/' ) {
201
+ /* eslint-disable camelcase */
202
+ return Promise . resolve ( {
203
+ ...stickyData ,
204
+ show_popup : true
205
+ } ) ;
206
+ /* eslint-enable camelcase */
207
+ }
208
+ return basicImplementation ( path ) ;
209
+ }
210
+ ) ;
211
+ const TestComponent = ( ) => {
212
+ const data = useStickyData ( ) ;
213
+
214
+ return (
215
+ < div data-testid = "sticky-data" >
216
+ { data && data . mode === 'popup' ? 'mode is popup' : 'no data' }
217
+ </ div >
218
+ ) ;
219
+ } ;
220
+
221
+ render ( < TestComponent /> ) ;
222
+ expect ( await screen . findByTestId ( 'sticky-data' ) ) . toHaveTextContent ( 'mode is popup' ) ;
223
+ mockCmsFetch . mockImplementation ( basicImplementation ) ;
224
+ } ) ;
129
225
} ) ;
130
226
131
227
// describe('MenuItem component TypeScript props', () => {
@@ -321,55 +417,3 @@ describe('default layout', () => {
321
417
expect ( toggle . getAttribute ( 'aria-expanded' ) ) . toBe ( 'false' ) ;
322
418
} ) ;
323
419
} ) ;
324
-
325
- // Integration tests for complex TypeScript interactions
326
- // describe('TypeScript Integration Tests', () => {
327
- // test('Complex type interactions work correctly', async () => {
328
- // // Test that complex types work together without compilation errors
329
- // type ComplexData = {
330
- // id: number;
331
- // metadata: {
332
- // created: string;
333
- // modified?: string;
334
- // };
335
- // items: Array<{
336
- // name: string;
337
- // value: number;
338
- // }>;
339
- // };
340
-
341
- // const testData: ComplexData = {
342
- // id: 1,
343
- // metadata: {
344
- // created: '2024-01-01'
345
- // },
346
- // items: [
347
- // {name: 'item1', value: 100},
348
- // {name: 'item2', value: 200}
349
- // ]
350
- // };
351
-
352
- // expect(testData.id).toBe(1);
353
- // expect(testData.items).toHaveLength(2);
354
- // expect(testData.metadata.modified).toBeUndefined();
355
- // });
356
-
357
- // test('Event handler types are properly defined', () => {
358
- // type EventHandlerProps = {
359
- // onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;
360
- // onKeyDown: (event: React.KeyboardEvent<HTMLButtonElement>) => void;
361
- // };
362
-
363
- // const TestComponent = ({onClick, onKeyDown}: EventHandlerProps) => (
364
- // <button onClick={onClick} onKeyDown={onKeyDown}>
365
- // Test Button
366
- // </button>
367
- // );
368
-
369
- // const mockClick = jest.fn();
370
- // const mockKeyDown = jest.fn();
371
-
372
- // render(<TestComponent onClick={mockClick} onKeyDown={mockKeyDown} />);
373
- // expect(screen.getByRole('button')).toBeInTheDocument();
374
- // });
375
- // });
0 commit comments