Skip to content

Commit 24173dd

Browse files
authored
Merge pull request #34 from oslabs-beta/workingBranch
Working branch
2 parents b455af6 + 42d33ce commit 24173dd

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import React from 'react';
2+
import { render as rtlRender, screen } from '@testing-library/react';
3+
import '@testing-library/jest-dom/extend-expect';
4+
import MainSlider from '../components/MainSlider';
5+
import { mainSlice } from '../RTKslices'
6+
import { Provider } from 'react-redux';
7+
import { configureStore } from '@reduxjs/toolkit';
8+
9+
10+
const customTabs = {
11+
100: {
12+
sliderIndex: 1,
13+
},
14+
}
15+
16+
const customInitialState = {
17+
main: {
18+
port: null,
19+
currentTab: 100,
20+
currentTitle: null,
21+
tabs: customTabs, // Replace with the actual (testing) tab data
22+
currentTabInApp: null,
23+
connectionStatus: false,
24+
connectRequested: true,
25+
},
26+
};
27+
28+
const customStore = configureStore({
29+
reducer: {
30+
main: mainSlice.reducer,
31+
},
32+
preloadedState: customInitialState,
33+
middleware: (getDefaultMiddleware) =>
34+
getDefaultMiddleware({ serializableCheck: false }),
35+
});
36+
37+
const render = component => rtlRender(
38+
<Provider store={customStore}>
39+
{component}
40+
</Provider>
41+
);
42+
43+
describe('Unit testing for MainSlider.jsx', () => {
44+
const props = {
45+
snapshotsLength: 1,
46+
};
47+
48+
describe('When user only has one snapshot to view', () => {
49+
test('Component should have min, max, value with correct values to indicate slider position for correct tab', () => {
50+
render(<MainSlider {...props} />);
51+
expect(screen.getByRole('slider')).toHaveAttribute('aria-valuemin', '0');
52+
expect(screen.getByRole('slider')).toHaveAttribute('aria-valuemax', '0');
53+
expect(screen.getByRole('slider')).toHaveAttribute('aria-valuenow', '0');
54+
});
55+
});
56+
57+
describe('When there are multiple snapshots and we are looking in between', () => {
58+
const props = {
59+
snapshotsLength: 3,
60+
};
61+
62+
test('Component should have min, max, value with correct values to indicate slider position when there are multiple snapshots', () => {
63+
render(<MainSlider {...props} />);
64+
expect(screen.getByRole('slider')).toHaveAttribute('aria-valuemax', '2');
65+
expect(screen.getByRole('slider')).toHaveAttribute('aria-valuemin', '0');
66+
expect(screen.getByRole('slider')).toHaveAttribute('aria-valuenow','0')
67+
});
68+
});
69+
70+
});

0 commit comments

Comments
 (0)