Skip to content

Commit ceb2b31

Browse files
committed
MainContainer.test.tsx added
1 parent 3e9023d commit ceb2b31

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import React, { useEffect } from 'react';
2+
import { render, screen, fireEvent } from '@testing-library/react';
3+
import MainContainer from '../containers/MainContainer';
4+
import { useStoreContext } from '../store';
5+
6+
const chrome = require('sinon-chrome');
7+
8+
const mockActionContainer = jest.fn();
9+
jest.mock('../containers/ActionContainer', () => (props) => {
10+
mockActionContainer(props);
11+
return <div>mockActionContainer</div>;
12+
});
13+
14+
const mockStateContainer = jest.fn();
15+
jest.mock('../containers/StateContainer', () => (props) => {
16+
mockStateContainer(props);
17+
return <div>mockStateContainer</div>;
18+
});
19+
20+
const mockTravelContainer = jest.fn();
21+
jest.mock('../containers/TravelContainer', () => (props) => {
22+
mockTravelContainer(props);
23+
return <div>mockTravelContainer</div>;
24+
});
25+
const mockButtonsContainer = jest.fn();
26+
jest.mock('../containers/ButtonsContainer', () => (props) => {
27+
mockButtonsContainer(props);
28+
return <div>mockButtonsContainer</div>;
29+
});
30+
const mockErrorContainer = jest.fn();
31+
jest.mock('../containers/ErrorContainer', () => (props) => {
32+
mockErrorContainer(props);
33+
return <div>mockErrorContainer</div>;
34+
});
35+
36+
const state = {
37+
tabs: {},
38+
currentTab: null,
39+
};
40+
const dispatch = jest.fn();
41+
const toggleActionContainer = jest.fn();
42+
jest.mock('../../../node_modules/intro.js/introjs.css', () => jest.fn());
43+
jest.mock('../store');
44+
useStoreContext.mockImplementation(() => [state, dispatch]);
45+
46+
global.chrome = chrome;
47+
const port = {
48+
onMessage: {
49+
addListener: () => {},
50+
},
51+
onDisconnect: {
52+
addListener: () => {},
53+
},
54+
};
55+
chrome.runtime.connect.returns(port);
56+
57+
describe('With no snapshots, should not render any containers', () => {
58+
test('With no snapshots, ErrorContainer should render', () => {
59+
render(<MainContainer />);
60+
expect(screen.getByText('mockErrorContainer')).toBeInTheDocument();
61+
expect(mockErrorContainer).toBeCalledTimes(1);
62+
const error = screen.queryByText('mockErrorContainer');
63+
expect(error).not.toBeNull();
64+
});
65+
test('With no snapshots, ActionContainer should not render', () => {
66+
render(<MainContainer />);
67+
const ActionContainer = screen.queryByText('mockActionContainer');
68+
expect(ActionContainer).not.toBeInTheDocument();
69+
});
70+
test('With no snapshots, StateContainer should not render', () => {
71+
render(<MainContainer />);
72+
const StateContainer = screen.queryByText('mockStateContainer');
73+
expect(StateContainer).toBeNull();
74+
});
75+
test('With no snapshots, TravelContainer should not render', () => {
76+
render(<MainContainer />);
77+
const TravelContainer = screen.queryByText('mockTravelContainer');
78+
expect(TravelContainer).toBeNull();
79+
});
80+
test('With no snapshots, ButtonsContainer should not render', () => {
81+
render(<MainContainer />);
82+
const ButtonsContainer = screen.queryByText('mockButtonsContainer');
83+
expect(ButtonsContainer).toBeNull();
84+
});
85+
});
86+
87+
describe('With snapshots, should render all containers', () => {
88+
beforeEach(() => {
89+
render(<MainContainer />);
90+
useStoreContext.mockClear();
91+
dispatch.mockClear();
92+
mockErrorContainer.mockClear();
93+
state.currentTab = 87;
94+
state.tabs[87] = {
95+
snapshots: [{}],
96+
status: {
97+
contentScriptLaunched: true,
98+
reactDevToolsInstalled: true,
99+
targetPageisaReactApp: true,
100+
},
101+
viewIndex: -1,
102+
sliderIndex: 0,
103+
mode: {},
104+
};
105+
});
106+
test('With snapshots, ErrorContainer should not render', () => {
107+
expect(mockErrorContainer).toBeCalledTimes(0);
108+
});
109+
test('With snapshots, ActionContainer should not render', () => {
110+
expect(screen.getByText('mockActionContainer')).toBeInTheDocument();
111+
});
112+
test('With snapshots, StateContainer should render', () => {
113+
expect(screen.getByText('mockStateContainer')).toBeInTheDocument();
114+
});
115+
test('With snapshots, TravelContainer should render', () => {
116+
expect(screen.getByText('mockTravelContainer')).toBeInTheDocument();
117+
});
118+
test('With snapshots, ButtonsContainer should render', () => {
119+
expect(screen.getByText('mockButtonsContainer')).toBeInTheDocument();
120+
});
121+
});

0 commit comments

Comments
 (0)