Skip to content

Commit 038b89a

Browse files
authored
Merge pull request #40 from oslabs-beta/kelvin/finished/web
removed unused comments, replaced store and reducer with RTK files, u…
2 parents e61b053 + 930ad8a commit 038b89a

37 files changed

+309
-1125
lines changed

src/app/__tests__/ActionContainer.test.tsx

Lines changed: 209 additions & 193 deletions
Large diffs are not rendered by default.

src/app/__tests__/ActionContainerV2.test.tsx

Lines changed: 0 additions & 212 deletions
This file was deleted.

src/app/__tests__/ButtonContainer.test.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ import '@testing-library/jest-dom/extend-expect';
44
import { TextEncoder } from 'util';
55
global.TextEncoder = TextEncoder;
66
import ButtonsContainer from '../containers/ButtonsContainer';
7-
// import { useStoreContext } from '../store';
87
import userEvent from '@testing-library/user-event';
9-
// import { toggleMode } from '../actions/actions';
10-
import { toggleMode, mainSlice } from '../RTKslices';
8+
import { toggleMode, mainSlice } from '../slices/mainSlice';
119
import { useDispatch, Provider } from 'react-redux';
1210
import { configureStore } from '@reduxjs/toolkit';
1311

src/app/__tests__/ErrorContainer.test.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import React from 'react';
22
import { render as rtlRender, screen } from '@testing-library/react';
33
import '@testing-library/jest-dom/extend-expect'; // needed this to extend the jest-dom assertions (ex toHaveTextContent)
44
import ErrorContainer from '../containers/ErrorContainer';
5-
// import { useStoreContext } from '../store';
65
import { configureStore } from '@reduxjs/toolkit';
7-
import { mainSlice } from '../RTKslices'
6+
import { mainSlice } from '../slices/mainSlice'
87
import { Provider } from 'react-redux';
98

109
const customTabs = {
@@ -107,7 +106,7 @@ const customInitialState = {
107106
main: {
108107
port: null,
109108
currentTab: 87, // Update with your desired value
110-
currentTitle: 'No Target', //I updated this to 'No Target' to match the initialState in RTKslices.tsx. It used to be null, but that doesn't make sense because if it doesn't get updated, we would render null instead of No Target
109+
currentTitle: 'No Target', //I updated this to 'No Target' to match the initialState in mainSlice.ts. It used to be null, but that doesn't make sense because if it doesn't get updated, we would render null instead of No Target
111110
tabs: customTabs, // Replace with the actual (testing) tab data
112111
currentTabInApp: 'null',
113112
connectionStatus: false,

src/app/__tests__/MainContainer.test.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import React from 'react';
33
import { render, screen } from '@testing-library/react';
44
import MainContainer from '../containers/MainContainer';
5-
6-
//Added :
75
import { useDispatch, useSelector } from 'react-redux';
86

97
jest.mock('react-redux', () => ({
@@ -16,9 +14,7 @@ const mockState = {
1614
tabs: {},
1715
currentTab: null,
1816
},
19-
};
20-
21-
// End
17+
};// End
2218

2319
const chrome = require('sinon-chrome');
2420

@@ -63,6 +59,7 @@ global.chrome = chrome;
6359
const port = {
6460
onMessage: {
6561
addListener: () => {},
62+
hasListener: () => {},
6663
},
6764
onDisconnect: {
6865
addListener: () => {},

src/app/__tests__/MainSlider.test.tsx

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,70 @@
11
import React from 'react';
2-
import { render, screen } from '@testing-library/react';
2+
import { render as rtlRender, screen } from '@testing-library/react';
33
import '@testing-library/jest-dom/extend-expect';
4-
import { TextEncoder } from 'util';
5-
global.TextEncoder = TextEncoder;
64
import MainSlider from '../components/MainSlider';
7-
import { useStoreContext } from '../store';
5+
import { mainSlice } from '../slices/mainSlice'
6+
import { Provider } from 'react-redux';
7+
import { configureStore } from '@reduxjs/toolkit';
88

9-
jest.mock('../store');
10-
const mockeduseStoreContext = jest.mocked(useStoreContext);
119

12-
describe('Unit testing for MainSlider.jsx', () => {
13-
const props = {
14-
snapshotsLength: 1,
15-
};
16-
17-
const state = {
18-
tabs: {
19-
100: {
10+
const customTabs = {
11+
100: {
2012
sliderIndex: 1,
2113
},
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,
2225
},
23-
currentTab: 100,
2426
};
2527

26-
const dispatch = jest.fn();
27-
mockeduseStoreContext.mockImplementation(() => [state, dispatch]);
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+
};
2847

2948
describe('When user only has one snapshot to view', () => {
3049
test('Component should have min, max, value with correct values to indicate slider position for correct tab', () => {
3150
render(<MainSlider {...props} />);
32-
expect(screen.getByRole('slider')).toHaveAttribute('aria-valuemin', '0');
33-
expect(screen.getByRole('slider')).toHaveAttribute('aria-valuemax', '0');
34-
expect(screen.getByRole('slider')).toHaveAttribute('aria-valuenow', '0');
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+
});
3555
});
36-
});
3756

3857
describe('When there are multiple snapshots and we are looking in between', () => {
39-
const props = {
40-
snapshotsLength: 3,
41-
};
42-
43-
test('Component should have min, max, value with correct values to indicate slider position when there are multiple snapshots', () => {
44-
render(<MainSlider {...props} />);
45-
expect(screen.getByRole('slider')).toHaveAttribute('aria-valuemax', '2');
46-
expect(screen.getByRole('slider')).toHaveAttribute('aria-valuemin', '0');
47-
expect(screen.getByRole('slider')).toHaveAttribute('aria-valuenow','0')
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+
});
4868
});
49-
});
50-
});
69+
70+
});

0 commit comments

Comments
 (0)