|
| 1 | +/// in progress |
1 | 2 | import React from 'react'
|
2 | 3 | import {render, screen, fireEvent} from '@testing-library/react'
|
3 | 4 | import userEvent from '@testing-library/user-event'
|
4 | 5 | import '@testing-library/jest-dom/extend-expect' // needed this to extend the jest-dom assertions (ex toHaveTextContent)
|
5 | 6 | import TravelContainer from '../containers/TravelContainer'
|
| 7 | +import MainSlider from '../components/MainSlider'; |
| 8 | +// import {mockMainSlider} from '../components/__mocks__/MainSlider' |
6 | 9 | import { useStoreContext } from '../store';
|
7 | 10 | import { TravelContainerProps } from '../components/FrontendTypes';
|
| 11 | +import MainContainer from '../containers/MainContainer' |
| 12 | +import Dropdown from '../components/Dropdown' |
8 | 13 |
|
9 | 14 |
|
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 | 15 |
|
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 = { |
| 16 | +const state = { |
37 | 17 | tabs: {
|
38 | 18 | 87: {
|
39 |
| - snapshots: [0,1,2], // because snapshot index starts at 0 |
40 |
| - sliderIndex: 1, |
| 19 | + snapshots: [0, 1, 2, 3], // because snapshot index starts at 0 |
| 20 | + sliderIndex: 3, |
41 | 21 | playing: false,
|
42 | 22 | },
|
43 | 23 | },
|
44 | 24 | currentTab: 87,
|
45 | 25 | };
|
46 | 26 |
|
| 27 | + |
| 28 | +const dispatch = jest.fn(); |
47 | 29 | useStoreContext.mockImplementation(() => [state, dispatch]);
|
48 | 30 |
|
49 |
| - beforeEach(() => { |
| 31 | + |
| 32 | + |
| 33 | +// jest.mock mocks a module - all exports of this module are basically set to jest.fn() |
| 34 | +jest.mock('../store'); |
| 35 | + |
| 36 | +// mocking the Mainslider component to return div with MockSlider in it |
| 37 | +const mockSlider = jest.fn(); |
| 38 | +jest.mock("../components/MainSlider", () => (props) => { |
| 39 | + mockSlider(props); |
| 40 | + return ( |
| 41 | + <div> |
| 42 | + MockSlider |
| 43 | + </div> |
| 44 | + ); |
| 45 | +}); |
| 46 | +const mockDropDown = jest.fn(); |
| 47 | + |
| 48 | +// mocking the dropdown component to return div with mockDropDown in it |
| 49 | +jest.mock("../components/Dropdown", () => (props) => { |
| 50 | + mockDropDown(props); |
| 51 | + return ( |
| 52 | + <div> |
| 53 | + mockDropDown |
| 54 | + </div> |
| 55 | + ); |
| 56 | +}); |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | +describe('testing the TravelContainer module',()=>{ |
| 61 | + // nested blocks. |
| 62 | + // high level block, test that the play button exists, slider gets renders, dropdown gets rendered. |
| 63 | + // nested: play button. when paused vs not. starts at a condition, then pressed is changed into another condition. |
| 64 | + |
| 65 | + // before each, clear usestorcontext and dispatch |
| 66 | + beforeEach(() => { |
50 | 67 | useStoreContext.mockClear(); // need to think about if mockClear is the correct item here
|
51 | 68 | dispatch.mockClear();
|
| 69 | + render(<TravelContainer snapshotsLength={0}/>); |
52 | 70 |
|
53 |
| - }) |
54 |
| - render(<TravelContainer snapshotsLength={0}/>); |
55 |
| - // @ts-ignore |
56 |
| - let slider1 = screen.getByRole<HTMLInputElement>('slider',{ value: {now:1, min:0, max:0}}) |
57 | 71 |
|
58 |
| - // @ts-ignore |
59 |
| - let slider0 = screen.getByRole<HTMLInputElement>('slider',{ value: {now:0, min:0, max:0}}) |
60 |
| - let slider = screen.getByRole('slider') |
| 72 | + }) |
61 | 73 |
|
62 |
| - screen.debug(screen.getAllByRole('slider')) |
| 74 | + screen.debug() |
63 | 75 |
|
64 | 76 | test('first button contains text Play',()=>{
|
65 | 77 | let buttons = screen.getAllByRole('button')
|
66 | 78 | expect(buttons[0]).toHaveTextContent('Play')
|
67 | 79 | })
|
68 | 80 |
|
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() |
| 81 | + test('MainSlider exists in document',()=>{ |
| 82 | + |
| 83 | + expect(screen.getByText('MockSlider')).toBeInTheDocument(); |
| 84 | + |
| 85 | + |
76 | 86 | })
|
| 87 | + test('Dropdown exists in document',()=>{ |
| 88 | + |
| 89 | + expect(screen.getByText('mockDropDown')).toBeInTheDocument(); |
| 90 | + |
| 91 | +}) |
| 92 | + |
| 93 | + // describe('When paused and user click pause/play button',()=>{ |
| 94 | + // // |
| 95 | + // }) |
| 96 | + |
| 97 | + // describe('When playing and user clicks',()=>{ |
| 98 | + // // |
| 99 | + // }) |
| 100 | + |
77 | 101 |
|
| 102 | + |
78 | 103 | })
|
| 104 | + |
| 105 | + |
| 106 | + |
| 107 | + |
0 commit comments