Skip to content

Commit 36ab3c2

Browse files
committed
integration test for ActionContainer using RTK finally passed
1 parent 5376e2e commit 36ab3c2

File tree

2 files changed

+125
-24
lines changed

2 files changed

+125
-24
lines changed

src/app/__tests__/ActionContainer.test.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,16 @@ describe('unit testing for ActionContainer', () => {
186186
// });
187187

188188
// describe('integration testing for ActionContainer', () => {
189-
// beforeEach(() => {
190-
// mockeduseStoreContext.mockClear();
191-
// dispatch.mockClear();
192-
// render(
193-
// <ActionContainer actionView={true} />
194-
// )
195-
// render(
196-
// <TravelContainer snapshotsLength={0} />
197-
// )
198-
// });
189+
// beforeEach(() => {
190+
// mockeduseStoreContext.mockClear();
191+
// dispatch.mockClear();
192+
// render(
193+
// <ActionContainer actionView={true} />
194+
// )
195+
// render(
196+
// <TravelContainer snapshotsLength={0} />
197+
// )
198+
// });
199199

200200
// test('Slider resets on clear button', () => {
201201
// fireEvent.click(screen.getAllByRole('button')[0]);

src/app/__tests__/ActionContainerV2.test.tsx

Lines changed: 115 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,113 @@ import { mainSlice } from '../RTKslices'
1414
//you typically don't need to use jest.mock because you're interested in testing how the real components interact with the actual store.
1515
//The decision to use jest.mock depends on the type of testing (unit or integration) and your specific testing goals.
1616

17+
const customTabs = {
18+
87: {
19+
snapshots: [1, 2, 3, 4],
20+
hierarchy: {
21+
index: 0,
22+
name: 1,
23+
branch: 0,
24+
stateSnapshot: {
25+
state: {},
26+
children: [
27+
{
28+
state: { test: 'test' },
29+
name: 'App',
30+
componentData: { actualDuration: 3.5 },
31+
},
32+
],
33+
route: {
34+
id: 1,
35+
url: 'http://localhost:8080/',
36+
},
37+
},
38+
children: [
39+
{
40+
index: 1,
41+
name: 2,
42+
branch: 0,
43+
stateSnapshot: {
44+
state: {},
45+
children: [
46+
{
47+
state: { test: 'test' },
48+
name: 'App',
49+
componentData: { actualDuration: 3.5 },
50+
},
51+
],
52+
route: {
53+
id: 2,
54+
url: 'http://localhost:8080/',
55+
},
56+
},
57+
children: [
58+
{
59+
index: 2,
60+
name: 3,
61+
branch: 0,
62+
stateSnapshot: {
63+
state: {},
64+
children: [
65+
{
66+
state: { test: 'test' },
67+
name: 'App',
68+
componentData: { actualDuration: 3.5 },
69+
},
70+
],
71+
route: {
72+
id: 3,
73+
url: 'http://localhost:8080/',
74+
},
75+
},
76+
children: [
77+
{
78+
index: 3,
79+
name: 4,
80+
branch: 0,
81+
stateSnapshot: {
82+
state: {},
83+
children: [
84+
{
85+
state: { test: 'test' },
86+
name: 'App',
87+
componentData: { actualDuration: 3.5 },
88+
},
89+
],
90+
route: {
91+
id: 4,
92+
url: 'http://localhost:8080/test/',
93+
},
94+
},
95+
children: [],
96+
},
97+
],
98+
},
99+
],
100+
},
101+
],
102+
},
103+
currLocation: {
104+
index: 0,
105+
name: 1,
106+
branch: 0,
107+
},
108+
sliderIndex: 0,
109+
viewIndex: -1,
110+
},
111+
}
17112

18-
const customInitialState = {
19-
main: {
20-
port: null,
21-
currentTab: null,
22-
currentTitle: 'No Target',
23-
tabs: {},
24-
currentTabInApp: null,
25-
connectionStatus: true,
26-
reconnectRequested: false,
27-
},
28-
};
113+
const customInitialState = {
114+
main: {
115+
port: null,
116+
currentTab: 87, // Update with your desired value
117+
currentTitle: null,
118+
tabs: customTabs, // Replace with the actual (testing) tab data
119+
currentTabInApp: null,
120+
connectionStatus: false,
121+
reconnectRequested: false,
122+
},
123+
};
29124

30125
const customStore = configureStore({
31126
reducer: {
@@ -42,13 +137,19 @@ const render = component => rtlRender(
42137
</Provider>
43138
);
44139

140+
//need to add this mockFunction for setActionView
141+
//because in actual actioncontainer componenent, it is prop drilled down from maincontainer
142+
//here we set it as a jest.fn()
143+
//then we pass it into our actionContainer on render
144+
const setActionViewMock = jest.fn();
145+
45146
describe('Integration testing for ActionContainer.tsx', () => {
46147
test('renders the ActionContainer component', () => {
47148
//tests that the clearButton is rendered by testing if we can get "Clear"
48-
render(<ActionContainer />);
149+
//need to set actionView to true to correctly render clearbutton
150+
render(<ActionContainer setActionView={setActionViewMock} actionView={true}/>);
49151
const clearButton = screen.getByText('Clear'); // Use an existing element
50-
//need to click the clear button or anything for state to be defined?
51-
// fireEvent.click()
152+
expect(setActionViewMock).toHaveBeenCalledWith(true);
52153
expect(clearButton).toBeInTheDocument();
53154
});
54155
})

0 commit comments

Comments
 (0)