-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathVideo.test.tsx
58 lines (49 loc) · 1.81 KB
/
Video.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
51
52
53
54
55
56
57
58
import 'react-native';
import React from 'react';
import {
cleanup,
fireEvent,
render,
screen,
} from '@testing-library/react-native';
import App from '../App';
// 'react-native-video' is being mocked in /__mocks__/react-native-video.ts
jest.mock('@react-native-community/async-storage', () => ({
setItem: jest.fn(),
}));
afterEach(cleanup);
it('renders/navigates throughout app screens', async () => {
// Render the app from the root
render(<App />);
// Navigate to video screen
fireEvent.press(screen.getByText(/video/i));
// Grab video comp., full-screen and pause/start pressables
const videoTestInstance = screen.getByLabelText('video-player');
const enterFullScreenButton = screen.getByText(/full screen/i);
const pauseStartButton = screen.getByText(/pause\/start/i);
// We make sure to veify that the video is initially playing and
// presented not in full screen mode
expect(videoTestInstance).toHaveProp('paused', false);
expect(videoTestInstance).toHaveProp('fullscreen', false);
expect(videoTestInstance).toHaveStyle({
width: 200,
height: 200,
});
// Simulate pause video and enter full screen mode
fireEvent.press(enterFullScreenButton);
fireEvent.press(pauseStartButton);
// Props indeed changed and match the scenario with the style we expect
expect(videoTestInstance).toHaveProp('paused', true);
expect(videoTestInstance).toHaveProp('fullscreen', true);
expect(videoTestInstance).toHaveStyle({
width: '100%',
height: 200,
zIndex: 5,
});
// Play video and assert not paused anymore
fireEvent.press(pauseStartButton);
expect(videoTestInstance).toHaveProp('paused', false);
// Exit full screen mode and assert by value of prop
fireEvent.press(screen.getByText(/exit full screen/i));
expect(videoTestInstance).toHaveProp('fullscreen', false);
});