1
1
/* eslint-disable react/jsx-filename-extension */
2
2
3
- import { mount , configure } from 'enzyme' ;
3
+ import { shallow , configure } from 'enzyme' ;
4
4
import React from 'react' ;
5
- import { act } from 'react-dom/test-utils' ;
6
5
import Adapter from 'enzyme-adapter-react-16' ;
7
6
import MainContainer from '../containers/MainContainer' ;
8
7
import { useStoreContext } from '../store' ;
@@ -18,15 +17,8 @@ const chrome = require('sinon-chrome');
18
17
configure ( { adapter : new Adapter ( ) } ) ;
19
18
20
19
const state = {
21
- tabs : {
22
- 87 : {
23
- snapshots : [ { } , { } , { } , { } ] ,
24
- sliderIndex : 0 ,
25
- viewIndex : - 1 ,
26
- mode : { } ,
27
- } ,
28
- } ,
29
- currentTab : 87 ,
20
+ tabs : { } ,
21
+ currentTab : null ,
30
22
} ;
31
23
32
24
const dispatch = jest . fn ( ) ;
@@ -35,12 +27,9 @@ useStoreContext.mockImplementation(() => [state, dispatch]);
35
27
36
28
let wrapper ;
37
29
global . chrome = chrome ;
38
- let eventListener ;
39
30
const port = {
40
31
onMessage : {
41
- addListener : fn => {
42
- eventListener = fn ;
43
- } ,
32
+ addListener : ( ) => { } ,
44
33
} ,
45
34
onDisconnect : {
46
35
addListener : ( ) => { } ,
@@ -49,29 +38,32 @@ const port = {
49
38
chrome . runtime . connect . returns ( port ) ;
50
39
51
40
beforeEach ( ( ) => {
52
- wrapper = mount ( < MainContainer /> ) ;
41
+ wrapper = shallow ( < MainContainer /> ) ;
53
42
useStoreContext . mockClear ( ) ;
54
43
dispatch . mockClear ( ) ;
55
44
} ) ;
56
45
57
46
describe ( 'MainContainer rendering' , ( ) => {
58
- test . skip ( 'With no connection, should not render any containers' , ( ) => {
59
- expect ( wrapper . text ( ) ) . toEqual ( 'please install our npm package in your app' ) ;
47
+ test ( 'With no snapshots, should not render any containers' , ( ) => {
48
+ expect ( wrapper . text ( ) ) . toEqual (
49
+ 'No React application found. Please install our npm package in your app.' ,
50
+ ) ;
60
51
expect ( wrapper . find ( HeadContainer ) . length ) . toBe ( 0 ) ;
61
52
expect ( wrapper . find ( ActionContainer ) . length ) . toBe ( 0 ) ;
62
53
expect ( wrapper . find ( StateContainer ) . length ) . toBe ( 0 ) ;
63
54
expect ( wrapper . find ( TravelContainer ) . length ) . toBe ( 0 ) ;
64
55
expect ( wrapper . find ( ButtonsContainer ) . length ) . toBe ( 0 ) ;
65
56
} ) ;
66
- test ( 'With connection established, should render all containers' , ( ) => {
67
- // fake connect
68
- act ( ( ) => {
69
- eventListener ( {
70
- action : 'initialConnectSnapshots' ,
71
- payload : 'test' ,
72
- } ) ;
73
- } ) ;
74
- wrapper . update ( ) ;
57
+ test ( 'With snapshots, should render all containers' , ( ) => {
58
+ state . currentTab = 87 ;
59
+ state . tabs [ 87 ] = {
60
+ snapshots : [ { } ] ,
61
+ viewIndex : - 1 ,
62
+ sliderIndex : 0 ,
63
+ mode : { } ,
64
+ } ;
65
+
66
+ wrapper = shallow ( < MainContainer /> ) ;
75
67
expect ( wrapper . find ( HeadContainer ) . length ) . toBe ( 1 ) ;
76
68
expect ( wrapper . find ( ActionContainer ) . length ) . toBe ( 1 ) ;
77
69
expect ( wrapper . find ( StateContainer ) . length ) . toBe ( 1 ) ;
0 commit comments