Skip to content

Commit 5cb313a

Browse files
committed
main container testing
1 parent a308312 commit 5cb313a

File tree

4 files changed

+115
-9
lines changed

4 files changed

+115
-9
lines changed

package-lock.json

Lines changed: 98 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"react-html-parser": "^2.0.2",
6363
"react-json-tree": "^0.11.2",
6464
"react-router-dom": "^5.0.1",
65-
"react-select": "^3.0.4"
65+
"react-select": "^3.0.4",
66+
"sinon-chrome": "^3.0.1"
6667
}
6768
}

src/app/__tests__/MainContainer.test.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
/* eslint-disable react/jsx-filename-extension */
22

33
import { shallow, configure } from 'enzyme';
4-
import React from 'react';
4+
import React, { useState } from 'react';
55
import Adapter from 'enzyme-adapter-react-16';
66
import MainContainer from '../containers/MainContainer';
77
import { useStoreContext } from '../store';
8-
import {
9-
addNewSnapshots, initialConnect, setPort
10-
} from '../actions/actions';
8+
119
import HeadContainer from '../containers/HeadContainer';
1210
import ActionContainer from '../containers/ActionContainer';
1311
import StateContainer from '../containers/StateContainer';
1412
import TravelContainer from '../containers/TravelContainer';
1513
import ButtonsContainer from '../containers/ButtonsContainer';
16-
import Action from '../components/Action';
14+
15+
const chrome = require('sinon-chrome');
1716

1817
configure({ adapter: new Adapter() });
1918

@@ -29,27 +28,34 @@ const state = {
2928
};
3029

3130
const dispatch = jest.fn();
32-
3331
jest.mock('../store');
3432
useStoreContext.mockImplementation(() => [state, dispatch]);
3533

3634
let wrapper;
35+
// global.chrome = chrome;
36+
const setnpm = jest.fn();
37+
38+
3739

3840
beforeEach(() => {
3941
wrapper = shallow(<MainContainer />);
42+
chrome.runtime.connect = () => {}
43+
console.log(chrome.runtime.connect);
44+
chrome.runtime.onMessage.dispatch({action: 'initialConnectSnapshots', payload: []});
4045
useStoreContext.mockClear();
4146
dispatch.mockClear();
4247
});
4348

4449
describe('MainContainer rendering', () => {
45-
test('With no connection, shouldn not render any containers', () => {
50+
test('With no connection, should not render any containers', () => {
51+
expect(wrapper.text()).toEqual('please install our npm package in your app');
4652
expect(wrapper.find(HeadContainer).length).toBe(0);
4753
expect(wrapper.find(ActionContainer).length).toBe(0);
4854
expect(wrapper.find(StateContainer).length).toBe(0);
4955
expect(wrapper.find(TravelContainer).length).toBe(0);
5056
expect(wrapper.find(ButtonsContainer).length).toBe(0);
5157
});
52-
test('With connection established, should render All containers', () => {
58+
test('With connection established, should render all containers', () => {
5359
expect(wrapper.find(HeadContainer).length).toBe(1);
5460
expect(wrapper.find(ActionContainer).length).toBe(1);
5561
expect(wrapper.find(StateContainer).length).toBe(1);

src/app/containers/MainContainer.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function MainContainer() {
3232
break;
3333
}
3434
case 'initialConnectSnapshots': {
35+
console.log('connection received')
3536
dispatch(initialConnect(payload));
3637
setnpm(true);
3738
break;

0 commit comments

Comments
 (0)