-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayPauseButton.test.tsx
63 lines (44 loc) · 2.19 KB
/
PlayPauseButton.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
59
60
61
62
63
import { cleanup, render } from "@testing-library/react";
import { makePlayPauseButton } from "../overrides/makePlayPauseButton";
import PlayPauseButton from './PlayPauseButton';
afterEach(cleanup)
const { play, pause } = makePlayPauseButton({
root: {
color: '#ffcb19',
cursor: 'pointer',
fontSize: '6vh',
},
})
describe('PlayPauseButton component', () => {
it('should render play button when isPlaying is false', () => {
const onClick = jest.fn();
render(<PlayPauseButton PlayButton={play} PauseButton={pause} onClick={onClick} isPlaying={false}></PlayPauseButton>)
const playButton = document.querySelector('[data-testid="play"]');
const pauseButton = document.querySelector('[data-testid="pause"]');
expect(playButton).not.toBeNull();
expect(pauseButton).toBeNull();
});
it('should render pause button when isPlaying is true', () => {
const onClick = jest.fn();
render(<PlayPauseButton PlayButton={play} PauseButton={pause} onClick={onClick} isPlaying={true}></PlayPauseButton>)
const playButton = document.querySelector('[data-testid="play"]');
const pauseButton = document.querySelector('[data-testid="pause"]');
expect(pauseButton).not.toBeNull();
expect(playButton).toBeNull();
});
it('should change value when clicked', () => {
const onClick = jest.fn(() => isPlaying = !isPlaying);
let isPlaying = false;
render(<PlayPauseButton PlayButton={play} PauseButton={pause} onClick={onClick} isPlaying={isPlaying}></PlayPauseButton>)
const playButton = document.querySelector('[data-testid="play"]');
expect(playButton).not.toBeNull();
for (let i = 0; i < 5; i++){
playButton.dispatchEvent(new MouseEvent("click", { bubbles: true }));
}
expect(isPlaying).toBe(true);
expect(onClick).toHaveBeenCalledTimes(5);
render(<PlayPauseButton PlayButton={play} PauseButton={pause} onClick={onClick} isPlaying={isPlaying}></PlayPauseButton>)
const pauseButton = document.querySelector('[data-testid="pause"]');
expect(pauseButton).not.toBeNull();
});
});