Skip to content

Commit c4f7286

Browse files
jasnoominzo-kim
andcommitted
updated travelcontainer to include child components
Co-authored-by: minzo-kim <[email protected]>
1 parent dbecc6a commit c4f7286

File tree

1 file changed

+73
-44
lines changed

1 file changed

+73
-44
lines changed
Lines changed: 73 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,107 @@
1+
/// in progress
12
import React from 'react'
23
import {render, screen, fireEvent} from '@testing-library/react'
34
import userEvent from '@testing-library/user-event'
45
import '@testing-library/jest-dom/extend-expect' // needed this to extend the jest-dom assertions (ex toHaveTextContent)
56
import TravelContainer from '../containers/TravelContainer'
7+
import MainSlider from '../components/MainSlider';
8+
// import {mockMainSlider} from '../components/__mocks__/MainSlider'
69
import { useStoreContext } from '../store';
710
import { TravelContainerProps } from '../components/FrontendTypes';
11+
import MainContainer from '../containers/MainContainer'
12+
import Dropdown from '../components/Dropdown'
813

914

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-
// };
2015

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 = {
3717
tabs: {
3818
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,
4121
playing: false,
4222
},
4323
},
4424
currentTab: 87,
4525
};
4626

27+
28+
const dispatch = jest.fn();
4729
useStoreContext.mockImplementation(() => [state, dispatch]);
4830

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(() => {
5067
useStoreContext.mockClear(); // need to think about if mockClear is the correct item here
5168
dispatch.mockClear();
69+
render(<TravelContainer snapshotsLength={0}/>);
5270

53-
})
54-
render(<TravelContainer snapshotsLength={0}/>);
55-
// @ts-ignore
56-
let slider1 = screen.getByRole<HTMLInputElement>('slider',{ value: {now:1, min:0, max:0}})
5771

58-
// @ts-ignore
59-
let slider0 = screen.getByRole<HTMLInputElement>('slider',{ value: {now:0, min:0, max:0}})
60-
let slider = screen.getByRole('slider')
72+
})
6173

62-
screen.debug(screen.getAllByRole('slider'))
74+
screen.debug()
6375

6476
test('first button contains text Play',()=>{
6577
let buttons = screen.getAllByRole('button')
6678
expect(buttons[0]).toHaveTextContent('Play')
6779
})
6880

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+
7686
})
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+
77101

102+
78103
})
104+
105+
106+
107+

0 commit comments

Comments
 (0)