Skip to content

Commit 12c48fb

Browse files
committed
updated rtlRender to include Theme provider and assigned aria-label within Travel Container component to facilitate testing purposes
1 parent 9290bf1 commit 12c48fb

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

src/app/__tests__/TravelContainerV2.test.tsx

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import { Provider } from 'react-redux';
55
import { configureStore } from '@reduxjs/toolkit';
66
import { mainSlice } from '../RTKslices'
77
import { useDispatch } from 'react-redux';
8+
import { ThemeProvider } from '@mui/material/styles';
9+
import theme from '../components/theme';
810
import '@testing-library/jest-dom/extend-expect'; // needed this to extend the jest-dom assertions (ex toHaveTextContent)
911

1012
const customTabs = {
1113
87: {
12-
snapshots: [1, 2, 3, 4],
14+
snapshots: [0, 1, 2, 3],
1315
hierarchy: {
1416
index: 0,
1517
name: 1,
@@ -100,6 +102,7 @@ const customTabs = {
100102
},
101103
sliderIndex: 3, //updated to 3
102104
viewIndex: -1,
105+
playing: false,
103106
},
104107
}
105108

@@ -124,11 +127,15 @@ const customStore = configureStore({
124127
getDefaultMiddleware({ serializableCheck: false }),
125128
});
126129

127-
const render = component => rtlRender(
130+
const renderWithTheme = (component) => {
131+
return rtlRender(
128132
<Provider store={customStore}>
129-
{component}
133+
<ThemeProvider theme={theme}>
134+
{component}
135+
</ThemeProvider>
130136
</Provider>
131-
);
137+
);
138+
};
132139

133140
const mockSlider = jest.fn();
134141
jest.mock('../components/MainSlider', () => (props) => {
@@ -149,7 +156,7 @@ jest.mock('react-redux', () => ({
149156

150157
describe('All elements appear in the TravelContainer module', () => {
151158
beforeEach(() => {
152-
render(<TravelContainer snapshotsLength={0} />);
159+
renderWithTheme(<TravelContainer snapshotsLength={0} />);
153160
});
154161

155162
test('first button contains text Play', () => {
@@ -166,19 +173,19 @@ describe('All elements appear in the TravelContainer module', () => {
166173
});
167174

168175
test('Backward button exists in document', () => {
169-
let buttons = screen.getAllByRole('button');
170-
expect(buttons[1]).toHaveTextContent('<');
171-
});
176+
// Use the getByLabelText query to find the button by its label
177+
const backwardButton = screen.getByLabelText('Backward');
178+
expect(backwardButton).toBeInTheDocument();
179+
});
172180

173-
test('Forward button exists in document', () => {
174-
let buttons = screen.getAllByRole('button');
175-
expect(buttons[2]).toHaveTextContent('>');
176-
});
181+
test('Forward button exists in document', () => {
182+
const forwardButton = screen.getByLabelText('Forward');
183+
expect(forwardButton).toBeInTheDocument();
184+
});
177185
});
178-
186+
179187
// describe('Testing backward and forward button', () => {
180188
// beforeEach(() => {
181-
// dispatch.mockClear();
182189
// render(<TravelContainer snapshotsLength={0} />);
183190
// });
184191

src/app/containers/TravelContainer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ function TravelContainer(props: TravelContainerProps): JSX.Element {
8181
{playing ? 'Pause' : 'Play'}
8282
</Button>
8383
<MainSlider snapshotsLength={snapshotsLength} />
84-
<Button variant="contained" className='backward-button' onClick={() => dispatch(moveBackward(false))} type='button' sx={{height: 25, minWidth: 30, p: 0, mr: 1}}>
84+
<Button variant="contained" className='backward-button' onClick={() => dispatch(moveBackward(false))} type='button' sx={{height: 25, minWidth: 30, p: 0, mr: 1}} aria-label='Backward'>
8585
<FastRewindIcon sx={{color: '#000'}}/>
8686
</Button>
87-
<Button variant="contained" className='forward-button' onClick={() => dispatch(moveForward(false))} type='button' sx={{height: 25, minWidth: 30, p: 0}}>
87+
<Button variant="contained" className='forward-button' onClick={() => dispatch(moveForward(false))} type='button' sx={{height: 25, minWidth: 30, p: 0}} aria-label='Forward'>
8888
<FastForwardIcon sx={{color: '#000'}}/>
8989
</Button>
9090
<Dropdown speeds={speeds} selectedSpeed={selectedSpeed} setSpeed={setSpeed} />

0 commit comments

Comments
 (0)