Skip to content

Commit 95b7027

Browse files
committed
ActionContainer test file
1 parent abfa9ee commit 95b7027

File tree

1 file changed

+165
-0
lines changed

1 file changed

+165
-0
lines changed
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
/* eslint-disable react/jsx-filename-extension */
3+
import React, {useEffect} from 'react'
4+
import {render, screen, fireEvent} from '@testing-library/react'
5+
import '@testing-library/jest-dom/extend-expect'
6+
import ActionContainer from '../containers/ActionContainer'
7+
import { useStoreContext } from '../store';
8+
9+
10+
11+
const state = {
12+
tabs: {
13+
87: {
14+
snapshots: [1, 2, 3, 4],
15+
hierarchy: {
16+
index: 0,
17+
name: 1,
18+
branch: 0,
19+
stateSnapshot: {
20+
state: {},
21+
children: [
22+
{
23+
state: { test: 'test' },
24+
name: 'App',
25+
componentData: { actualDuration: 3.5 },
26+
},
27+
],
28+
route: {
29+
id: 1,
30+
url: 'http://localhost:8080/',
31+
},
32+
},
33+
children: [
34+
{
35+
index: 1,
36+
name: 2,
37+
branch: 0,
38+
stateSnapshot: {
39+
state: {},
40+
children: [
41+
{
42+
state: { test: 'test' },
43+
name: 'App',
44+
componentData: { actualDuration: 3.5 },
45+
},
46+
],
47+
route: {
48+
id: 2,
49+
url: 'http://localhost:8080/',
50+
},
51+
},
52+
children: [
53+
{
54+
index: 2,
55+
name: 3,
56+
branch: 0,
57+
stateSnapshot: {
58+
state: {},
59+
children: [
60+
{
61+
state: { test: 'test' },
62+
name: 'App',
63+
componentData: { actualDuration: 3.5 },
64+
},
65+
],
66+
route: {
67+
id: 3,
68+
url: 'http://localhost:8080/',
69+
},
70+
},
71+
children: [
72+
{
73+
index: 3,
74+
name: 4,
75+
branch: 0,
76+
stateSnapshot: {
77+
state: {},
78+
children: [
79+
{
80+
state: { test: 'test' },
81+
name: 'App',
82+
componentData: { actualDuration: 3.5 },
83+
},
84+
],
85+
route: {
86+
id: 4,
87+
url: 'http://localhost:8080/test/',
88+
},
89+
},
90+
children: [],
91+
},
92+
],
93+
},
94+
],
95+
},
96+
],
97+
},
98+
currLocation: {
99+
index: 0,
100+
name: 1,
101+
branch: 0,
102+
},
103+
sliderIndex: 0,
104+
viewIndex: -1,
105+
},
106+
},
107+
currentTab: 87,
108+
};
109+
110+
const dispatch = jest.fn();
111+
const resetSlider = jest.fn()
112+
jest.spyOn(React, 'useEffect').mockImplementation(() => jest.fn())
113+
jest.mock('../store');
114+
useStoreContext.mockImplementation(() => [state, dispatch]);
115+
116+
const MockRouteDescription = jest.fn();
117+
jest.mock('../components/RouteDescription', () => () => {
118+
MockRouteDescription();
119+
return (
120+
<div>
121+
MockRouteDescription
122+
</div>
123+
);
124+
});
125+
126+
const MockSwitchApp = jest.fn();
127+
jest.mock('../components/SwitchApp', () => () => {
128+
MockSwitchApp();
129+
return (
130+
<div>
131+
MockSwitchApp
132+
</div>
133+
);
134+
});
135+
136+
137+
138+
describe('unit testing for ActionContainer', () => {
139+
140+
beforeEach(() => {
141+
useStoreContext.mockClear();
142+
dispatch.mockClear();
143+
render(<ActionContainer actionView={true}/>);
144+
});
145+
146+
test("Expect top arrow to be rendered", () => {
147+
expect(screen.getByRole('complementary')).toBeInTheDocument()
148+
149+
});
150+
151+
test("Expect RouteDescription to be rendered", () => {
152+
expect(screen.getAllByText('MockRouteDescription')).toHaveLength(2)
153+
154+
});
155+
156+
test("Expect SwitchApp to be rendered", () => {
157+
expect(screen.getByText('MockSwitchApp')).toBeInTheDocument()
158+
});
159+
160+
test("Click works on clear button", async () => {
161+
fireEvent.click(screen.getAllByRole('button')[0])
162+
await expect(dispatch).toHaveBeenCalledTimes(1)
163+
});
164+
165+
});

0 commit comments

Comments
 (0)