-
Notifications
You must be signed in to change notification settings - Fork 733
/
Copy pathApp.test.tsx
50 lines (40 loc) · 1.67 KB
/
App.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import React from 'react';
import App from './App';
import MenuBar from './components/MenuBar/MenuBar';
import PreJoinScreens from './components/PreJoinScreens/PreJoinScreens';
import Room from './components/Room/Room';
import { shallow } from 'enzyme';
import useHeight from './hooks/useHeight/useHeight';
import useRoomState from './hooks/useRoomState/useRoomState';
jest.mock('swiper/react', () => ({
Swiper: jest.fn(),
SwiperSlide: jest.fn(),
}));
jest.mock('swiper', () => ({
Pagination: jest.fn(),
}));
jest.mock('./hooks/useRoomState/useRoomState');
jest.mock('./hooks/useHeight/useHeight');
const mockUseRoomState = useRoomState as jest.Mock<any>;
const mockUseHeight = useHeight as jest.Mock<any>;
mockUseHeight.mockImplementation(() => '500px');
describe('the App component', () => {
it('should render correctly when disconnected from a room', () => {
mockUseRoomState.mockImplementation(() => 'disconnected');
const wrapper = shallow(<App />);
expect(wrapper.find(PreJoinScreens).exists()).toBe(true);
expect(wrapper.find(Room).exists()).toBe(false);
expect(wrapper.find(MenuBar).exists()).toBe(false);
});
it('should render correctly when connected (or reconnecting) to a room', () => {
mockUseRoomState.mockImplementation(() => 'connected');
const wrapper = shallow(<App />);
expect(wrapper.find(PreJoinScreens).exists()).toBe(false);
expect(wrapper.find(Room).exists()).toBe(true);
expect(wrapper.find(MenuBar).exists()).toBe(true);
});
it('should set the height of the main container using the useHeight hook', () => {
const wrapper = shallow(<App />);
expect(wrapper.prop('style')).toEqual({ height: '500px' });
});
});