Skip to content

Commit 1478b48

Browse files
authored
Merge pull request #66 from oslabs-beta/ctstamper/fixing-formatting
Fixed formatting
2 parents dd213ff + bf2495a commit 1478b48

12 files changed

+563
-598
lines changed

src/app/__tests__/ActionContainer.test.tsx

Lines changed: 143 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -5,136 +5,131 @@ import ActionContainer from '../containers/ActionContainer';
55
import TravelContainer from '../containers/TravelContainer';
66
import { Provider } from 'react-redux';
77
import { configureStore } from '@reduxjs/toolkit';
8-
import { mainSlice } from '../slices/mainSlice'
8+
import { mainSlice } from '../slices/mainSlice';
99
import { useDispatch } from 'react-redux';
1010
//Note for testing:
11-
//typically, jest.mock is commonly used in unit testing to isolate the code under test.
12-
//In contrast, when performing integration testing of components with a real Redux store,
13-
//you typically don't need to use jest.mock because you're interested in testing how the real components interact with the actual store.
11+
//typically, jest.mock is commonly used in unit testing to isolate the code under test.
12+
//In contrast, when performing integration testing of components with a real Redux store,
13+
//you typically don't need to use jest.mock because you're interested in testing how the real components interact with the actual store.
1414
//The decision to use jest.mock depends on the type of testing (unit or integration) and your specific testing goals.
1515

16-
const customTabs = {
17-
87: {
18-
snapshots: [1, 2, 3, 4],
19-
hierarchy: {
20-
index: 0,
21-
name: 1,
22-
branch: 0,
23-
stateSnapshot: {
24-
state: {},
25-
children: [
26-
{
27-
state: { test: 'test' },
28-
name: 'App',
29-
componentData: { actualDuration: 3.5 },
30-
},
31-
],
32-
route: {
33-
id: 1,
34-
url: 'http://localhost:8080/',
35-
},
36-
},
16+
const customTabs = {
17+
87: {
18+
snapshots: [1, 2, 3, 4],
19+
hierarchy: {
20+
index: 0,
21+
name: 1,
22+
branch: 0,
23+
stateSnapshot: {
24+
state: {},
25+
children: [
26+
{
27+
state: { test: 'test' },
28+
name: 'App',
29+
componentData: { actualDuration: 3.5 },
30+
},
31+
],
32+
route: {
33+
id: 1,
34+
url: 'http://localhost:8080/',
35+
},
36+
},
37+
children: [
38+
{
39+
index: 1,
40+
name: 2,
41+
branch: 0,
42+
stateSnapshot: {
43+
state: {},
3744
children: [
3845
{
39-
index: 1,
40-
name: 2,
41-
branch: 0,
42-
stateSnapshot: {
43-
state: {},
44-
children: [
45-
{
46-
state: { test: 'test' },
47-
name: 'App',
48-
componentData: { actualDuration: 3.5 },
49-
},
50-
],
51-
route: {
52-
id: 2,
53-
url: 'http://localhost:8080/',
54-
},
55-
},
46+
state: { test: 'test' },
47+
name: 'App',
48+
componentData: { actualDuration: 3.5 },
49+
},
50+
],
51+
route: {
52+
id: 2,
53+
url: 'http://localhost:8080/',
54+
},
55+
},
56+
children: [
57+
{
58+
index: 2,
59+
name: 3,
60+
branch: 0,
61+
stateSnapshot: {
62+
state: {},
5663
children: [
5764
{
58-
index: 2,
59-
name: 3,
60-
branch: 0,
61-
stateSnapshot: {
62-
state: {},
63-
children: [
64-
{
65-
state: { test: 'test' },
66-
name: 'App',
67-
componentData: { actualDuration: 3.5 },
68-
},
69-
],
70-
route: {
71-
id: 3,
72-
url: 'http://localhost:8080/',
73-
},
74-
},
65+
state: { test: 'test' },
66+
name: 'App',
67+
componentData: { actualDuration: 3.5 },
68+
},
69+
],
70+
route: {
71+
id: 3,
72+
url: 'http://localhost:8080/',
73+
},
74+
},
75+
children: [
76+
{
77+
index: 3,
78+
name: 4,
79+
branch: 0,
80+
stateSnapshot: {
81+
state: {},
7582
children: [
7683
{
77-
index: 3,
78-
name: 4,
79-
branch: 0,
80-
stateSnapshot: {
81-
state: {},
82-
children: [
83-
{
84-
state: { test: 'test' },
85-
name: 'App',
86-
componentData: { actualDuration: 3.5 },
87-
},
88-
],
89-
route: {
90-
id: 4,
91-
url: 'http://localhost:8080/test/',
92-
},
93-
},
94-
children: [],
84+
state: { test: 'test' },
85+
name: 'App',
86+
componentData: { actualDuration: 3.5 },
9587
},
9688
],
89+
route: {
90+
id: 4,
91+
url: 'http://localhost:8080/test/',
92+
},
9793
},
98-
],
99-
},
100-
],
101-
},
102-
currLocation: {
103-
index: 0,
104-
name: 1,
105-
branch: 0,
106-
},
107-
sliderIndex: 0,
108-
viewIndex: -1,
109-
},
110-
}
111-
112-
const customInitialState = {
113-
main: {
114-
port: null,
115-
currentTab: 87, // Update with your desired value
116-
currentTitle: 'test string',
117-
tabs: customTabs, // Replace with the actual (testing) tab data
118-
currentTabInApp: 'test string',
119-
connectionStatus: false,
120-
connectRequested: true,
94+
children: [],
95+
},
96+
],
97+
},
98+
],
12199
},
122-
};
100+
],
101+
},
102+
currLocation: {
103+
index: 0,
104+
name: 1,
105+
branch: 0,
106+
},
107+
sliderIndex: 0,
108+
viewIndex: -1,
109+
},
110+
};
111+
112+
const customInitialState = {
113+
main: {
114+
port: null,
115+
currentTab: 87, // Update with your desired value
116+
currentTitle: 'test string',
117+
tabs: customTabs, // Replace with the actual (testing) tab data
118+
currentTabInApp: 'test string',
119+
connectionStatus: false,
120+
connectRequested: true,
121+
},
122+
};
123123

124124
const customStore = configureStore({
125125
reducer: {
126126
main: mainSlice.reducer,
127127
},
128128
preloadedState: customInitialState, // Provide custom initial state
129-
middleware: (getDefaultMiddleware) =>
130-
getDefaultMiddleware({ serializableCheck: false }),
129+
middleware: (getDefaultMiddleware) => getDefaultMiddleware({ serializableCheck: false }),
131130
});
132131

133-
const render = component => rtlRender(
134-
<Provider store={customStore}>
135-
{component}
136-
</Provider>
137-
);
132+
const render = (component) => rtlRender(<Provider store={customStore}>{component}</Provider>);
138133

139134
const MockRouteDescription = jest.fn();
140135
jest.mock('../components/RouteDescription', () => () => {
@@ -149,7 +144,7 @@ jest.mock('../components/SwitchApp', () => () => {
149144
});
150145
//need to add this mockFunction for setActionView
151146
//because in actual actioncontainer componenent, it is prop drilled down from maincontainer
152-
//here we set it as a jest.fn()
147+
//here we set it as a jest.fn()
153148
//then we pass it into our actionContainer on render
154149
const setActionViewMock = jest.fn();
155150
const toggleActionContainer = jest.fn();
@@ -160,15 +155,21 @@ jest.mock('react-redux', () => ({
160155

161156
// const dispatch = jest.fn();
162157

163-
describe('unit testing for ActionContainer', ()=>{
158+
describe('unit testing for ActionContainer', () => {
164159
const useDispatchMock = useDispatch as jest.Mock; //getting a reference to the mock function you setup during jest.mock configuration on line 18
165-
const dummyDispatch = jest.fn(); //separate mock function created because we need to explicitly define on line 30 what
166-
useDispatchMock.mockReturnValue(dummyDispatch);//exactly useDispatchMock returns (which is a jest.fn())
167-
beforeEach(()=>{
168-
render(<ActionContainer actionView={true} setActionView={setActionViewMock} toggleActionContainer ={toggleActionContainer}/>)
160+
const dummyDispatch = jest.fn(); //separate mock function created because we need to explicitly define on line 30 what
161+
useDispatchMock.mockReturnValue(dummyDispatch); //exactly useDispatchMock returns (which is a jest.fn())
162+
beforeEach(() => {
163+
render(
164+
<ActionContainer
165+
actionView={true}
166+
setActionView={setActionViewMock}
167+
toggleActionContainer={toggleActionContainer}
168+
/>,
169+
);
169170
});
170171

171-
test('expect top arrow to be rendered', ()=>{
172+
test('expect top arrow to be rendered', () => {
172173
// render(<ActionContainer actionView = {true} setActionView={setActionViewMock}/>)
173174
expect(screen.getByRole('complementary')).toBeInTheDocument();
174175
});
@@ -187,25 +188,34 @@ describe('unit testing for ActionContainer', ()=>{
187188
fireEvent.click(screen.getAllByRole('button')[0]);
188189
expect(dummyDispatch).toHaveBeenCalledTimes(1);
189190
});
190-
})
191+
});
191192

192193
describe('Integration testing for ActionContainer.tsx', () => {
193-
test('renders the ActionContainer component', () => {
194-
//tests that the clearButton is rendered by testing if we can get "Clear"
195-
//need to set actionView to true to correctly render clearbutton
196-
render(<ActionContainer setActionView={setActionViewMock} actionView={true} toggleActionContainer={toggleActionContainer}/>);
197-
const clearButton = screen.getByText('Clear'); // Use an existing element
198-
expect(setActionViewMock).toHaveBeenCalledWith(true);
199-
expect(clearButton).toBeInTheDocument();
200-
});
194+
test('renders the ActionContainer component', () => {
195+
//tests that the clearButton is rendered by testing if we can get "Clear"
196+
//need to set actionView to true to correctly render clearbutton
197+
render(
198+
<ActionContainer
199+
setActionView={setActionViewMock}
200+
actionView={true}
201+
toggleActionContainer={toggleActionContainer}
202+
/>,
203+
);
204+
const clearButton = screen.getByText('Clear'); // Use an existing element
205+
expect(setActionViewMock).toHaveBeenCalledWith(true);
206+
expect(clearButton).toBeInTheDocument();
207+
});
201208

202-
test('Slider resets on clear button', ()=>{
203-
render(<ActionContainer actionView = {true} setActionView={setActionViewMock} toggleActionContainer={toggleActionContainer}/>)
204-
render( <TravelContainer snapshotsLength={0} />)
205-
fireEvent.click(screen.getAllByRole('button')[0]);
206-
expect(screen.getByRole('slider')).toHaveStyle('left: 0');
207-
});
209+
test('Slider resets on clear button', () => {
210+
render(
211+
<ActionContainer
212+
actionView={true}
213+
setActionView={setActionViewMock}
214+
toggleActionContainer={toggleActionContainer}
215+
/>,
216+
);
217+
render(<TravelContainer snapshotsLength={0} />);
218+
fireEvent.click(screen.getAllByRole('button')[0]);
219+
expect(screen.getByRole('slider')).toHaveStyle('left: 0');
220+
});
208221
});
209-
210-
211-

src/app/__tests__/ButtonContainer.test.tsx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ const customTabs = {
108108
sliderIndex: 0,
109109
viewIndex: -1,
110110
},
111-
}
111+
};
112112

113113
const customInitialState = {
114114
main: {
@@ -127,29 +127,24 @@ const customStore = configureStore({
127127
main: mainSlice.reducer,
128128
},
129129
preloadedState: customInitialState, // Provide custom initial state
130-
middleware: (getDefaultMiddleware) =>
131-
getDefaultMiddleware({ serializableCheck: false }),
130+
middleware: (getDefaultMiddleware) => getDefaultMiddleware({ serializableCheck: false }),
132131
});
133132

134-
const render = component => rtlRender(
135-
<Provider store={customStore}>
136-
{component}
137-
</Provider>
138-
);
133+
const render = (component) => rtlRender(<Provider store={customStore}>{component}</Provider>);
139134

140135
jest.mock('react-redux', () => ({
141136
...jest.requireActual('react-redux'), // Use the actual react-redux module except for the functions you want to mock
142137
useDispatch: jest.fn(), // set up a mock function for useDispatch
143138
}));
144139

145-
//these are needed for the Clicking pause-button toggles locked/unlocked test, as the onClick triggers the exportHandler, which uses the .creatObjectURL and .revokeObjectURL methods, so we declare them as jest functions here
140+
//these are needed for the Clicking pause-button toggles locked/unlocked test, as the onClick triggers the exportHandler, which uses the .creatObjectURL and .revokeObjectURL methods, so we declare them as jest functions here
146141
global.URL.createObjectURL = jest.fn(() => 'https://pdf.com');
147142
global.URL.revokeObjectURL = jest.fn();
148143

149144
describe('Unit testing for ButtonContainer', () => {
150145
const useDispatchMock = useDispatch as jest.Mock; //getting a reference to the mock function you setup during jest.mock configuration on line 18
151-
const dummyDispatch = jest.fn(); //separate mock function created because we need to explicitly define on line 30 what
152-
useDispatchMock.mockReturnValue(dummyDispatch);//exactly useDispatchMock returns (which is a jest.fn())
146+
const dummyDispatch = jest.fn(); //separate mock function created because we need to explicitly define on line 30 what
147+
useDispatchMock.mockReturnValue(dummyDispatch); //exactly useDispatchMock returns (which is a jest.fn())
153148
beforeEach;
154149

155150
const currentTab = customInitialState.main.tabs[customInitialState.main.currentTab];
@@ -210,7 +205,6 @@ describe('Unit testing for ButtonContainer', () => {
210205
});
211206
});
212207

213-
214208
describe('Upload/Download', () => {
215209
test('Clicking upload and download buttons', async () => {
216210
render(<ButtonsContainer />);

0 commit comments

Comments
 (0)