1
1
/* eslint-disable react/jsx-filename-extension */
2
2
3
- import { shallow , configure } from 'enzyme' ;
4
- import React , { useState } from 'react' ;
3
+ import { mount , configure } from 'enzyme' ;
4
+ import React from 'react' ;
5
+ import { act } from 'react-dom/test-utils' ;
5
6
import Adapter from 'enzyme-adapter-react-16' ;
6
7
import MainContainer from '../containers/MainContainer' ;
7
8
import { useStoreContext } from '../store' ;
@@ -19,9 +20,10 @@ configure({ adapter: new Adapter() });
19
20
const state = {
20
21
tabs : {
21
22
87 : {
22
- snapshots : [ 1 , 2 , 3 , 4 ] ,
23
+ snapshots : [ { } , { } , { } , { } ] ,
23
24
sliderIndex : 0 ,
24
25
viewIndex : - 1 ,
26
+ mode : { } ,
25
27
} ,
26
28
} ,
27
29
currentTab : 87 ,
@@ -32,16 +34,22 @@ jest.mock('../store');
32
34
useStoreContext . mockImplementation ( ( ) => [ state , dispatch ] ) ;
33
35
34
36
let wrapper ;
35
- // global.chrome = chrome;
36
- const setnpm = jest . fn ( ) ;
37
-
38
-
37
+ global . chrome = chrome ;
38
+ let eventListener ;
39
+ const port = {
40
+ onMessage : {
41
+ addListener : ( ( fn ) => {
42
+ eventListener = fn ;
43
+ } ) ,
44
+ } ,
45
+ onDisconnect : {
46
+ addListener : ( ) => { } ,
47
+ } ,
48
+ } ;
49
+ chrome . runtime . connect . returns ( port ) ;
39
50
40
51
beforeEach ( ( ) => {
41
- wrapper = shallow ( < MainContainer /> ) ;
42
- chrome . runtime . connect = ( ) => { }
43
- console . log ( chrome . runtime . connect ) ;
44
- chrome . runtime . onMessage . dispatch ( { action : 'initialConnectSnapshots' , payload : [ ] } ) ;
52
+ wrapper = mount ( < MainContainer /> ) ;
45
53
useStoreContext . mockClear ( ) ;
46
54
dispatch . mockClear ( ) ;
47
55
} ) ;
@@ -56,6 +64,14 @@ describe('MainContainer rendering', () => {
56
64
expect ( wrapper . find ( ButtonsContainer ) . length ) . toBe ( 0 ) ;
57
65
} ) ;
58
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 ( ) ;
59
75
expect ( wrapper . find ( HeadContainer ) . length ) . toBe ( 1 ) ;
60
76
expect ( wrapper . find ( ActionContainer ) . length ) . toBe ( 1 ) ;
61
77
expect ( wrapper . find ( StateContainer ) . length ) . toBe ( 1 ) ;
0 commit comments