1
+ import React from 'react'
2
+ import { render , screen , fireEvent } from '@testing-library/react'
3
+ import userEvent from '@testing-library/user-event'
4
+ import '@testing-library/jest-dom/extend-expect' // needed this to extend the jest-dom assertions (ex toHaveTextContent)
5
+ import TravelContainer from '../containers/TravelContainer'
6
+ import { useStoreContext } from '../store' ;
7
+ import { TravelContainerProps } from '../components/FrontendTypes' ;
8
+
9
+
10
+ // const state = {
11
+ // tabs: {
12
+ // 87: {
13
+ // snapshots: [0, 1, 2, 3], // because snapshot index starts at 0
14
+ // sliderIndex: 3,
15
+ // playing: false,
16
+ // },
17
+ // },
18
+ // currentTab: 87,
19
+ // };
20
+
21
+
22
+ // jest.fn() mocks a function - Create a new mock that can be used in place of `dispatch`.
23
+ const dispatch = jest . fn ( ) ;
24
+ const play = jest . fn ( ) ;
25
+
26
+
27
+
28
+ // jest.mock mocks a module - all exports of this module are basically set to jest.fn()
29
+ jest . mock ( '../store' ) ;
30
+
31
+ // useStoreContext is a mocked function that accepts a function that should be used as the implmentaton of the mock
32
+ // useStoreContext is being mocked and should use to function in arg -> return the state item and dispatch (mocked function)
33
+
34
+ describe ( 'when user loads a page with only one snapshot included and user has not played' , ( ) => {
35
+
36
+ const state = {
37
+ tabs : {
38
+ 87 : {
39
+ snapshots : [ 0 , 1 , 2 ] , // because snapshot index starts at 0
40
+ sliderIndex : 1 ,
41
+ playing : false ,
42
+ } ,
43
+ } ,
44
+ currentTab : 87 ,
45
+ } ;
46
+
47
+ useStoreContext . mockImplementation ( ( ) => [ state , dispatch ] ) ;
48
+
49
+ beforeEach ( ( ) => {
50
+ useStoreContext . mockClear ( ) ; // need to think about if mockClear is the correct item here
51
+ dispatch . mockClear ( ) ;
52
+
53
+ } )
54
+ render ( < TravelContainer snapshotsLength = { 0 } /> ) ;
55
+ // @ts -ignore
56
+ let slider1 = screen . getByRole < HTMLInputElement > ( 'slider' , { value : { now :1 , min :0 , max :0 } } )
57
+
58
+ // @ts -ignore
59
+ let slider0 = screen . getByRole < HTMLInputElement > ( 'slider' , { value : { now :0 , min :0 , max :0 } } )
60
+ let slider = screen . getByRole ( 'slider' )
61
+
62
+ screen . debug ( screen . getAllByRole ( 'slider' ) )
63
+
64
+ test ( 'first button contains text Play' , ( ) => {
65
+ let buttons = screen . getAllByRole ( 'button' )
66
+ expect ( buttons [ 0 ] ) . toHaveTextContent ( 'Play' )
67
+ } )
68
+
69
+ test ( 'slider icon is at the very left' , ( ) => {
70
+ render ( < TravelContainer snapshotsLength = { 0 } /> ) ;
71
+ // @ts -ignore
72
+ // let slider = screen.getByRole<HTMLInputElement>('slider',{ value: {now:1, min:0, max:0}})
73
+
74
+ expect ( slider1 ) . not . toBeInTheDocument ( )
75
+ expect ( slider0 ) . not . toBeInTheDocument ( )
76
+ } )
77
+
78
+ } )
79
+
80
+
81
+ // describe('when user as on hte second one',()=>{
82
+
83
+ // const state = {
84
+ // tabs: {
85
+ // 87: {
86
+ // snapshots: [0,1,2], // because snapshot index starts at 0
87
+ // sliderIndex: 1,
88
+ // playing: false,
89
+ // },
90
+ // },
91
+ // currentTab: 87,
92
+ // };
93
+
94
+ // useStoreContext.mockImplementation(() => [state, dispatch]);
95
+
96
+ // beforeEach(() => {
97
+ // useStoreContext.mockClear(); // need to think about if mockClear is the correct item here
98
+ // dispatch.mockClear();
99
+
100
+ // })
101
+
102
+ // test('first button contains text Play',()=>{
103
+ // render(<TravelContainer snapshotsLength={0}/>);
104
+ // let buttons = screen.getAllByRole('button')
105
+ // expect(buttons[0]).toHaveTextContent('Play')
106
+ // })
107
+
108
+ // test('slider icon is at the very left',()=>{
109
+ // render(<TravelContainer snapshotsLength={0}/>);
110
+ // // @ts -ignore
111
+ // let slider = screen.getByRole<HTMLInputElement>('slider',{ value: {now:0, min:0, max:0}}) as HTMLInputElement
112
+ // expect(slider).toBeInTheDocument()
113
+ // })
114
+
115
+ // })
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+ // describe("Play and carrot buttons exist", () => {
155
+
156
+ // beforeEach(() => {
157
+ // useStoreContext.mockClear(); // need to think about if mockClear is the correct item here
158
+ // dispatch.mockClear();
159
+
160
+ // })
161
+
162
+ // render(<TravelContainer snapshotsLength={2} />);
163
+ // // screen.debug()
164
+ // let buttons = screen.getAllByRole('button')
165
+
166
+ // test('First should say Play', () => {
167
+ // expect(buttons[0]).toHaveTextContent('Play')
168
+ // });
169
+
170
+ // test('Second button should say <', () => {
171
+ // expect(buttons[1]).toHaveTextContent('<')
172
+ // });
173
+
174
+ // test('Third should say >', () => {
175
+ // expect(buttons[2]).toHaveTextContent('>')
176
+ // });
177
+
178
+ // })
179
+
180
+
181
+ // / trying to make click happen
182
+
183
+ describe ( "Click on unlock" , ( ) => {
184
+
185
+ beforeEach ( ( ) => {
186
+ useStoreContext . mockClear ( ) ; // need to think about if mockClear is the correct item here
187
+ dispatch . mockClear ( ) ;
188
+
189
+ } )
190
+
191
+ // const user = userEvent.setup()
192
+ render ( < TravelContainer snapshotsLength = { 2 } /> ) ;
193
+
194
+ // const { container } = render(<TravelContainer snapshotsLength={2} />);
195
+ // screen.debug()
196
+
197
+ test ( 'Click on < button' , ( ) => {
198
+ // expect(dispatch).toHaveBeenCalledTimes(1)
199
+ // user.click(screen.getAllByRole('button')[1])
200
+ // expect(dispatch).toHaveBeenCalledTimes(1)
201
+ // user.click(screen.getAllByRole('button')[1])
202
+ fireEvent . click ( screen . getAllByRole ( 'button' ) [ 1 ] )
203
+ expect ( dispatch ) . toHaveBeenCalledTimes ( 1 )
204
+ fireEvent . click ( screen . getAllByRole ( 'button' ) [ 1 ] )
205
+
206
+ expect ( dispatch ) . toHaveBeenCalledTimes ( 2 )
207
+
208
+ // fireEvent.click(screen.getAllByRole('button')[0])
209
+ // expect(screen.getAllByRole('button')[0]).toHaveTextContent('Pause')
210
+ // screen.debug(screen.getAllByRole('button')[0])
211
+
212
+ } ) ;
213
+
214
+ } )
215
+
216
+
217
+ // desired test
218
+ /*
219
+ play button:
220
+ - if playing = false, it shows play
221
+ - if playing = true, it shows pauce
222
+ - when clicked, it toggles behavior
223
+ - slider reflects current state location
224
+
225
+
226
+
227
+
228
+ if there's only one snapshot
229
+ playing false
230
+ TravelContainer.tsx:55 snapshotsLength 1
231
+ TravelContainer.tsx:56 sliderIndex 0
232
+
233
+ current behavior is that play turns to pause, but returns back to play
234
+ slider isnt able to go anywhere, stays on left side
235
+ left and right dont do anything
236
+
237
+
238
+
239
+
240
+
241
+
242
+
243
+ */
0 commit comments