@@ -14,18 +14,113 @@ import { mainSlice } from '../RTKslices'
14
14
//you typically don't need to use jest.mock because you're interested in testing how the real components interact with the actual store.
15
15
//The decision to use jest.mock depends on the type of testing (unit or integration) and your specific testing goals.
16
16
17
+ const customTabs = {
18
+ 87 : {
19
+ snapshots : [ 1 , 2 , 3 , 4 ] ,
20
+ hierarchy : {
21
+ index : 0 ,
22
+ name : 1 ,
23
+ branch : 0 ,
24
+ stateSnapshot : {
25
+ state : { } ,
26
+ children : [
27
+ {
28
+ state : { test : 'test' } ,
29
+ name : 'App' ,
30
+ componentData : { actualDuration : 3.5 } ,
31
+ } ,
32
+ ] ,
33
+ route : {
34
+ id : 1 ,
35
+ url : 'http://localhost:8080/' ,
36
+ } ,
37
+ } ,
38
+ children : [
39
+ {
40
+ index : 1 ,
41
+ name : 2 ,
42
+ branch : 0 ,
43
+ stateSnapshot : {
44
+ state : { } ,
45
+ children : [
46
+ {
47
+ state : { test : 'test' } ,
48
+ name : 'App' ,
49
+ componentData : { actualDuration : 3.5 } ,
50
+ } ,
51
+ ] ,
52
+ route : {
53
+ id : 2 ,
54
+ url : 'http://localhost:8080/' ,
55
+ } ,
56
+ } ,
57
+ children : [
58
+ {
59
+ index : 2 ,
60
+ name : 3 ,
61
+ branch : 0 ,
62
+ stateSnapshot : {
63
+ state : { } ,
64
+ children : [
65
+ {
66
+ state : { test : 'test' } ,
67
+ name : 'App' ,
68
+ componentData : { actualDuration : 3.5 } ,
69
+ } ,
70
+ ] ,
71
+ route : {
72
+ id : 3 ,
73
+ url : 'http://localhost:8080/' ,
74
+ } ,
75
+ } ,
76
+ children : [
77
+ {
78
+ index : 3 ,
79
+ name : 4 ,
80
+ branch : 0 ,
81
+ stateSnapshot : {
82
+ state : { } ,
83
+ children : [
84
+ {
85
+ state : { test : 'test' } ,
86
+ name : 'App' ,
87
+ componentData : { actualDuration : 3.5 } ,
88
+ } ,
89
+ ] ,
90
+ route : {
91
+ id : 4 ,
92
+ url : 'http://localhost:8080/test/' ,
93
+ } ,
94
+ } ,
95
+ children : [ ] ,
96
+ } ,
97
+ ] ,
98
+ } ,
99
+ ] ,
100
+ } ,
101
+ ] ,
102
+ } ,
103
+ currLocation : {
104
+ index : 0 ,
105
+ name : 1 ,
106
+ branch : 0 ,
107
+ } ,
108
+ sliderIndex : 0 ,
109
+ viewIndex : - 1 ,
110
+ } ,
111
+ }
17
112
18
- const customInitialState = {
19
- main : {
20
- port : null ,
21
- currentTab : null ,
22
- currentTitle : 'No Target' ,
23
- tabs : { } ,
24
- currentTabInApp : null ,
25
- connectionStatus : true ,
26
- reconnectRequested : false ,
27
- } ,
28
- } ;
113
+ const customInitialState = {
114
+ main : {
115
+ port : null ,
116
+ currentTab : 87 , // Update with your desired value
117
+ currentTitle : null ,
118
+ tabs : customTabs , // Replace with the actual (testing) tab data
119
+ currentTabInApp : null ,
120
+ connectionStatus : false ,
121
+ reconnectRequested : false ,
122
+ } ,
123
+ } ;
29
124
30
125
const customStore = configureStore ( {
31
126
reducer : {
@@ -42,13 +137,19 @@ const render = component => rtlRender(
42
137
</ Provider >
43
138
) ;
44
139
140
+ //need to add this mockFunction for setActionView
141
+ //because in actual actioncontainer componenent, it is prop drilled down from maincontainer
142
+ //here we set it as a jest.fn()
143
+ //then we pass it into our actionContainer on render
144
+ const setActionViewMock = jest . fn ( ) ;
145
+
45
146
describe ( 'Integration testing for ActionContainer.tsx' , ( ) => {
46
147
test ( 'renders the ActionContainer component' , ( ) => {
47
148
//tests that the clearButton is rendered by testing if we can get "Clear"
48
- render ( < ActionContainer /> ) ;
149
+ //need to set actionView to true to correctly render clearbutton
150
+ render ( < ActionContainer setActionView = { setActionViewMock } actionView = { true } /> ) ;
49
151
const clearButton = screen . getByText ( 'Clear' ) ; // Use an existing element
50
- //need to click the clear button or anything for state to be defined?
51
- // fireEvent.click()
152
+ expect ( setActionViewMock ) . toHaveBeenCalledWith ( true ) ;
52
153
expect ( clearButton ) . toBeInTheDocument ( ) ;
53
154
} ) ;
54
155
} )
0 commit comments