@@ -28,95 +28,95 @@ jest.mock('react-redux', () => ({
2828const render = ( component ) => rtlRender ( < Provider store = { store } > { component } </ Provider > ) ;
2929
3030// RouteDescription Component Tests
31- // describe('RouteDescription Component', () => {
32- // // Create a mock store with initial state that matches your mainSlice structure
33- // const mockStore = configureStore({
34- // reducer: {
35- // main: mainSlice.reducer,
36- // },
37- // preloadedState: {
38- // main: {
39- // port: null,
40- // currentTab: 0,
41- // currentTitle: 'No Target',
42- // tabs: {
43- // 0: {
44- // currLocation: {
45- // index: 0,
46- // stateSnapshot: {},
47- // },
48- // hierarchy: {},
49- // sliderIndex: 0,
50- // viewIndex: 0,
51- // snapshots: [],
52- // playing: false,
53- // intervalId: null,
54- // mode: { paused: false },
55- // status: {
56- // reactDevToolsInstalled: true,
57- // targetPageisaReactApp: true,
58- // },
59- // },
60- // },
61- // currentTabInApp: null,
62- // connectionStatus: true,
63- // connectRequested: true,
64- // },
65- // },
66- // });
31+ describe ( 'RouteDescription Component' , ( ) => {
32+ // Create a mock store with initial state that matches your mainSlice structure
33+ const mockStore = configureStore ( {
34+ reducer : {
35+ main : mainSlice . reducer ,
36+ } ,
37+ preloadedState : {
38+ main : {
39+ port : null ,
40+ currentTab : 0 ,
41+ currentTitle : 'No Target' ,
42+ tabs : {
43+ 0 : {
44+ currLocation : {
45+ index : 0 ,
46+ stateSnapshot : { } ,
47+ } ,
48+ hierarchy : { } ,
49+ sliderIndex : 0 ,
50+ viewIndex : 0 ,
51+ snapshots : [ ] ,
52+ playing : false ,
53+ intervalId : null ,
54+ mode : { paused : false } ,
55+ status : {
56+ reactDevToolsInstalled : true ,
57+ targetPageisaReactApp : true ,
58+ } ,
59+ } ,
60+ } ,
61+ currentTabInApp : null ,
62+ connectionStatus : true ,
63+ connectRequested : true ,
64+ } ,
65+ } ,
66+ } ) ;
6767
68- // const mockActions = [
69- // {
70- // props: {
71- // routePath: 'http://example.com/test-route',
72- // key: 'action0',
73- // index: 0,
74- // state: {},
75- // displayName: '1.0',
76- // componentName: 'TestComponent',
77- // componentData: { actualDuration: 0 },
78- // selected: false,
79- // last: false,
80- // sliderIndex: 0,
81- // viewIndex: 0,
82- // isCurrIndex: false,
83- // },
84- // },
85- // ];
68+ const mockActions = [
69+ {
70+ props : {
71+ routePath : 'http://example.com/test-route' ,
72+ key : 'action0' ,
73+ index : 0 ,
74+ state : { } ,
75+ displayName : '1.0' ,
76+ componentName : 'TestComponent' ,
77+ componentData : { actualDuration : 0 } ,
78+ selected : false ,
79+ last : false ,
80+ sliderIndex : 0 ,
81+ viewIndex : 0 ,
82+ isCurrIndex : false ,
83+ } ,
84+ } ,
85+ ] ;
8686
87- // // Mock the vertical slider component
88- // jest.mock('../components/TimeTravel/VerticalSlider.tsx', () => {
89- // return function MockVerticalSlider({ snapshots }) {
90- // return <div data-testid='mock-slider'>{snapshots.length} snapshots</div>;
91- // };
92- // });
87+ // Mock the vertical slider component
88+ jest . mock ( '../components/TimeTravel/VerticalSlider.tsx' , ( ) => {
89+ return function MockVerticalSlider ( { snapshots } ) {
90+ return < div data-testid = 'mock-slider' > { snapshots . length } snapshots</ div > ;
91+ } ;
92+ } ) ;
9393
94- // beforeEach(() => {
95- // jest.clearAllMocks();
96- // });
94+ beforeEach ( ( ) => {
95+ jest . clearAllMocks ( ) ;
96+ } ) ;
9797
98- // test('renders route path correctly', () => {
99- // render(
100- // <Provider store={mockStore}>
101- // <RouteDescription actions={mockActions as unknown as JSX.Element[]} />
102- // </Provider>,
103- // );
104- // expect(screen.getByText('Route: /test-route')).toBeInTheDocument();
105- // });
98+ test ( 'renders route path correctly' , ( ) => {
99+ render (
100+ < Provider store = { mockStore } >
101+ < RouteDescription actions = { mockActions as unknown as JSX . Element [ ] } />
102+ </ Provider > ,
103+ ) ;
104+ expect ( screen . getByText ( 'Route: /test-route' ) ) . toBeInTheDocument ( ) ;
105+ } ) ;
106106
107- // test('renders actions container with correct height', () => {
108- // render(
109- // <Provider store={mockStore}>
110- // <RouteDescription actions={mockActions as unknown as JSX.Element[]} />
111- // </Provider>,
112- // );
113- // // @ts -ignore
114- // const container = screen.getByClassName('route-content');
115- // expect(container).toHaveStyle({ height: `${mockActions.length * 40.5}px` });
116- // });
117- // });
107+ test ( 'renders actions container with correct height' , ( ) => {
108+ render (
109+ < Provider store = { mockStore } >
110+ < RouteDescription actions = { mockActions as unknown as JSX . Element [ ] } />
111+ </ Provider > ,
112+ ) ;
113+ // @ts -ignore
114+ const container = screen . getByClassName ( 'route-content' ) ;
115+ expect ( container ) . toHaveStyle ( { height : `${ mockActions . length * 40.5 } px` } ) ;
116+ } ) ;
117+ } ) ;
118118
119- // // Action Component Tests
119+ // Action Component Tests
120120// describe('Action Component', () => {
121121// // @ts -ignore
122122// const useDispatchMock = useDispatch as jest.Mock;
@@ -194,77 +194,123 @@ const render = (component) => rtlRender(<Provider store={store}>{component}</Pro
194194// });
195195// });
196196
197+ // // VerticalSlider Component Tests
198+ // describe('VerticalSlider Component', () => {
199+ // const useDispatchMock = jest.fn();
200+ // const dummyDispatch = jest.fn();
197201
198- // VerticalSlider Component Tests
199- describe ( 'VerticalSlider Component' , ( ) => {
200- const mockSnapshots = [ { props : { index : 0 } } , { props : { index : 1 } } , { props : { index : 2 } } ] ;
201-
202- const mockState = {
203- main : {
204- tabs : {
205- 0 : {
206- currLocation : { index : 1 } ,
207- } ,
208- } ,
209- currentTab : 0 ,
210- } ,
211- } ;
212-
213- beforeEach ( ( ) => {
214- useDispatchMock . mockClear ( ) ;
215- } ) ;
216-
217- test ( 'renders slider with correct min and max values' , ( ) => {
218- render (
219- < Provider store = { mockStore } >
220- < VerticalSlider snapshots = { mockSnapshots } />
221- </ Provider > ,
222- ) ;
223-
224- const slider = screen . getByRole ( 'slider' ) ;
225- expect ( slider ) . toHaveAttribute ( 'aria-valuemin' , '0' ) ;
226- expect ( slider ) . toHaveAttribute ( 'aria-valuemax' , '2' ) ;
227- } ) ;
228-
229- test ( 'updates slider index when currLocation changes' , ( ) => {
230- const { rerender } = render (
231- < Provider store = { mockStore } >
232- < VerticalSlider snapshots = { mockSnapshots } />
233- </ Provider > ,
234- ) ;
235-
236- const updatedState = {
237- ...mockState ,
238- main : {
239- ...mockState . main ,
240- tabs : {
241- 0 : {
242- currLocation : { index : 2 } ,
243- } ,
244- } ,
245- } ,
246- } ;
247-
248- rerender (
249- < Provider store = { createMockStore ( updatedState ) } >
250- < VerticalSlider snapshots = { mockSnapshots } />
251- </ Provider > ,
252- ) ;
253-
254- const slider = screen . getByRole ( 'slider' ) ;
255- expect ( slider ) . toHaveAttribute ( 'aria-valuenow' , '2' ) ;
256- } ) ;
257-
258- test ( 'dispatches changeSlider action when slider value changes' , ( ) => {
259- render (
260- < Provider store = { mockStore } >
261- < VerticalSlider snapshots = { mockSnapshots } />
262- </ Provider > ,
263- ) ;
264-
265- const slider = screen . getByRole ( 'slider' ) ;
266- fireEvent . change ( slider , { target : { value : 2 } } ) ;
267-
268- expect ( dummyDispatch ) . toHaveBeenCalledWith ( changeSlider ( 2 ) ) ;
269- } ) ;
270- } ) ;
202+ // // Define the mock state
203+ // const mockState = {
204+ // main: {
205+ // tabs: {
206+ // 0: {
207+ // currLocation: { index: 1 },
208+ // },
209+ // },
210+ // currentTab: 0,
211+ // },
212+ // };
213+
214+ // const mockStore = configureStore({
215+ // reducer: {
216+ // // @ts -ignore
217+ // main: mainSlice.reducer,
218+ // },
219+ // preloadedState: mockState,
220+ // });
221+
222+ // // Helper function to create store with custom state
223+ // const createMockStore = (state: any) =>
224+ // configureStore({
225+ // reducer: {
226+ // // @ts -ignore
227+ // main: mainSlice.reducer,
228+ // },
229+ // preloadedState: state,
230+ // });
231+
232+ // const mockSnapshots = [{ props: { index: 0 } }, { props: { index: 1 } }, { props: { index: 2 } }];
233+
234+ // beforeEach(() => {
235+ // useDispatchMock.mockClear();
236+ // useDispatchMock.mockReturnValue(dummyDispatch);
237+ // });
238+
239+ // test('renders slider with correct min and max values', () => {
240+ // render(
241+ // <Provider store={mockStore}>
242+ // <VerticalSlider snapshots={mockSnapshots} />
243+ // </Provider>,
244+ // );
245+
246+ // const slider = screen.getByRole('slider');
247+ // expect(slider).toHaveAttribute('aria-valuemin', '0');
248+ // expect(slider).toHaveAttribute('aria-valuemax', '2');
249+ // });
250+
251+ // test('updates slider index when currLocation changes', () => {
252+ // const { rerender } = render(
253+ // <Provider store={mockStore}>
254+ // <VerticalSlider snapshots={mockSnapshots} />
255+ // </Provider>,
256+ // );
257+
258+ // const updatedState = {
259+ // ...mockState,
260+ // main: {
261+ // ...mockState.main,
262+ // tabs: {
263+ // 0: {
264+ // currLocation: { index: 2 },
265+ // },
266+ // },
267+ // },
268+ // };
269+
270+ // rerender(
271+ // <Provider store={createMockStore(updatedState)}>
272+ // <VerticalSlider snapshots={mockSnapshots} />
273+ // </Provider>,
274+ // );
275+
276+ // const slider = screen.getByRole('slider');
277+ // expect(slider).toHaveAttribute('aria-valuenow', '2');
278+ // });
279+
280+ // test('handles empty snapshots array', () => {
281+ // render(
282+ // <Provider store={mockStore}>
283+ // <VerticalSlider snapshots={[]} />
284+ // </Provider>,
285+ // );
286+
287+ // const slider = screen.getByRole('slider');
288+ // expect(slider).toHaveAttribute('aria-valuemin', '0');
289+ // expect(slider).toHaveAttribute('aria-valuemax', '-1');
290+ // expect(slider).not.toHaveAttribute('aria-valuenow');
291+ // });
292+
293+ // test('maintains slider position within bounds', () => {
294+ // const outOfBoundsState = {
295+ // ...mockState,
296+ // main: {
297+ // ...mockState.main,
298+ // tabs: {
299+ // 0: {
300+ // currLocation: { index: 999 }, // intentionally out of bounds
301+ // },
302+ // },
303+ // },
304+ // };
305+
306+ // render(
307+ // <Provider store={createMockStore(outOfBoundsState)}>
308+ // <VerticalSlider snapshots={mockSnapshots} />
309+ // </Provider>,
310+ // );
311+
312+ // const slider = screen.getByRole('slider');
313+ // // It seems the component defaults to 0 for out-of-bounds values
314+ // expect(slider).toHaveAttribute('aria-valuenow', '0');
315+ // });
316+ // });
0 commit comments