1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- /* eslint-disable @typescript-eslint/no-empty-function */
3
- /* eslint-disable @typescript-eslint/no-var-requires */
4
- /* eslint-disable react/jsx-filename-extension */
5
- import { shallow , configure } from 'enzyme' ;
6
1
import React from 'react' ;
7
- import Adapter from 'enzyme-adapter- react-16 ' ;
2
+ import { render , screen } from '@testing-library/ react' ;
8
3
import MainContainer from '../containers/MainContainer' ;
9
4
import { useStoreContext } from '../store' ;
10
5
11
- import ActionContainer from '../containers/ActionContainer' ;
12
- import StateContainer from '../containers/StateContainer' ;
13
- import TravelContainer from '../containers/TravelContainer' ;
14
- import ButtonsContainer from '../containers/ButtonsContainer' ;
15
- import ErrorContainer from '../containers/ErrorContainer' ;
16
-
17
6
const chrome = require ( 'sinon-chrome' ) ;
18
7
19
- configure ( { adapter : new ( Adapter as any ) ( ) } ) ;
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
+ } ) ;
20
35
21
36
const state = {
22
37
tabs : { } ,
23
38
currentTab : null ,
24
39
} ;
25
-
26
40
const dispatch = jest . fn ( ) ;
27
41
jest . mock ( '../../../node_modules/intro.js/introjs.css' , ( ) => jest . fn ( ) ) ;
28
42
jest . mock ( '../store' ) ;
29
43
useStoreContext . mockImplementation ( ( ) => [ state , dispatch ] ) ;
30
44
31
- let wrapper ;
32
45
global . chrome = chrome ;
33
46
const port = {
34
47
onMessage : {
@@ -40,21 +53,42 @@ const port = {
40
53
} ;
41
54
chrome . runtime . connect . returns ( port ) ;
42
55
43
- beforeEach ( ( ) => {
44
- wrapper = shallow ( < MainContainer /> ) ;
45
- useStoreContext . mockClear ( ) ;
46
- dispatch . mockClear ( ) ;
56
+ describe ( 'With no snapshots, should not render any containers' , ( ) => {
57
+ test ( 'With no snapshots, ErrorContainer should render' , ( ) => {
58
+ render ( < MainContainer /> ) ;
59
+ expect ( screen . getByText ( 'mockErrorContainer' ) ) . toBeInTheDocument ( ) ;
60
+ expect ( mockErrorContainer ) . toBeCalledTimes ( 1 ) ;
61
+ const error = screen . queryByText ( 'mockErrorContainer' ) ;
62
+ expect ( error ) . not . toBeNull ( ) ;
63
+ } ) ;
64
+ test ( 'With no snapshots, ActionContainer should not render' , ( ) => {
65
+ render ( < MainContainer /> ) ;
66
+ const ActionContainer = screen . queryByText ( 'mockActionContainer' ) ;
67
+ expect ( ActionContainer ) . not . toBeInTheDocument ( ) ;
68
+ } ) ;
69
+ test ( 'With no snapshots, StateContainer should not render' , ( ) => {
70
+ render ( < MainContainer /> ) ;
71
+ const StateContainer = screen . queryByText ( 'mockStateContainer' ) ;
72
+ expect ( StateContainer ) . toBeNull ( ) ;
73
+ } ) ;
74
+ test ( 'With no snapshots, TravelContainer should not render' , ( ) => {
75
+ render ( < MainContainer /> ) ;
76
+ const TravelContainer = screen . queryByText ( 'mockTravelContainer' ) ;
77
+ expect ( TravelContainer ) . toBeNull ( ) ;
78
+ } ) ;
79
+ test ( 'With no snapshots, ButtonsContainer should not render' , ( ) => {
80
+ render ( < MainContainer /> ) ;
81
+ const ButtonsContainer = screen . queryByText ( 'mockButtonsContainer' ) ;
82
+ expect ( ButtonsContainer ) . toBeNull ( ) ;
83
+ } ) ;
47
84
} ) ;
48
85
49
- describe ( 'MainContainer rendering' , ( ) => {
50
- test ( 'With no snapshots, should not render any containers' , ( ) => {
51
- expect ( wrapper . find ( ErrorContainer ) . length ) . toBe ( 1 ) ;
52
- expect ( wrapper . find ( ActionContainer ) . length ) . toBe ( 0 ) ;
53
- expect ( wrapper . find ( StateContainer ) . length ) . toBe ( 0 ) ;
54
- expect ( wrapper . find ( TravelContainer ) . length ) . toBe ( 0 ) ;
55
- expect ( wrapper . find ( ButtonsContainer ) . length ) . toBe ( 0 ) ;
56
- } ) ;
57
- test ( 'With snapshots, should render all containers' , ( ) => {
86
+ describe ( 'With snapshots, should render all containers' , ( ) => {
87
+ beforeEach ( ( ) => {
88
+ render ( < MainContainer /> ) ;
89
+ useStoreContext . mockClear ( ) ;
90
+ dispatch . mockClear ( ) ;
91
+ mockErrorContainer . mockClear ( ) ;
58
92
state . currentTab = 87 ;
59
93
state . tabs [ 87 ] = {
60
94
snapshots : [ { } ] ,
@@ -67,11 +101,20 @@ describe('MainContainer rendering', () => {
67
101
sliderIndex : 0 ,
68
102
mode : { } ,
69
103
} ;
70
-
71
- wrapper = shallow ( < MainContainer /> ) ;
72
- expect ( wrapper . find ( ActionContainer ) . length ) . toBe ( 1 ) ;
73
- expect ( wrapper . find ( StateContainer ) . length ) . toBe ( 1 ) ;
74
- expect ( wrapper . find ( TravelContainer ) . length ) . toBe ( 1 ) ;
75
- expect ( wrapper . find ( ButtonsContainer ) . length ) . toBe ( 1 ) ;
104
+ } ) ;
105
+ test ( 'With snapshots, ErrorContainer should not render' , ( ) => {
106
+ expect ( mockErrorContainer ) . toBeCalledTimes ( 0 ) ;
107
+ } ) ;
108
+ test ( 'With snapshots, ActionContainer should not render' , ( ) => {
109
+ expect ( screen . getByText ( 'mockActionContainer' ) ) . toBeInTheDocument ( ) ;
110
+ } ) ;
111
+ test ( 'With snapshots, StateContainer should render' , ( ) => {
112
+ expect ( screen . getByText ( 'mockStateContainer' ) ) . toBeInTheDocument ( ) ;
113
+ } ) ;
114
+ test ( 'With snapshots, TravelContainer should render' , ( ) => {
115
+ expect ( screen . getByText ( 'mockTravelContainer' ) ) . toBeInTheDocument ( ) ;
116
+ } ) ;
117
+ test ( 'With snapshots, ButtonsContainer should render' , ( ) => {
118
+ expect ( screen . getByText ( 'mockButtonsContainer' ) ) . toBeInTheDocument ( ) ;
76
119
} ) ;
77
120
} ) ;
0 commit comments