Skip to content

Commit 02c4f96

Browse files
committed
PlayPause control
1 parent 18a6f68 commit 02c4f96

File tree

5 files changed

+128
-3
lines changed

5 files changed

+128
-3
lines changed

__mocks__/fileTransformer.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const path = require('path');
2+
3+
module.exports = {
4+
process(src, filename, config, options) {
5+
return 'module.exports = ' + JSON.stringify(path.basename(filename)) + ';';
6+
}
7+
};

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,13 @@
4343
"json"
4444
],
4545
"moduleNameMapper": {
46-
"^.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|ico|vtt)$": "<rootDir>/__mocks__/fileMock.js",
46+
"^.+\\.(jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|ico|vtt)$": "<rootDir>/__mocks__/fileMock.js",
4747
"^.+\\.css$": "identity-obj-proxy"
4848
},
49+
"transform": {
50+
"^.+\\.js$": "babel-jest",
51+
"^.+\\.(svg)$": "<rootDir>/__mocks__/fileTransformer.js"
52+
},
4953
"testPathIgnorePatterns": [
5054
"<rootDir>/(build|docs|node_modules)/"
5155
],
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,26 @@
11
.component {}
2+
3+
.component:hover {
4+
background-color: #000;
5+
}
6+
7+
.button {
8+
width: 34px;
9+
height: 34px;
10+
background: none;
11+
border: 0;
12+
color: inherit;
13+
font: inherit;
14+
line-height: normal;
15+
overflow: visible;
16+
padding: 0;
17+
cursor: pointer;
18+
}
19+
20+
.button:focus {
21+
outline:0;
22+
}
23+
24+
.icon {
25+
padding: 5px;
26+
}

src/DefaultPlayer/PlayPause/PlayPause.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import React from 'react';
22
import styles from './PlayPause.css';
3+
import PlayArrow from './../Icon/play_arrow.svg';
4+
import Pause from './../Icon/pause.svg';
35

46
export default ({ togglePause, paused, className }) => {
57
return (
@@ -8,11 +10,19 @@ export default ({ togglePause, paused, className }) => {
810
className
911
].join(' ')}>
1012
<button
13+
className={styles.button}
1114
onClick={togglePause}
12-
type="button">
13-
{ paused
15+
aria-label={ paused
1416
? 'Play'
1517
: 'Pause' }
18+
type="button">
19+
{ paused
20+
? <PlayArrow
21+
className={styles.icon}
22+
fill="#fff" />
23+
: <Pause
24+
className={styles.icon}
25+
fill="#fff" /> }
1626
</button>
1727
</div>
1828
);
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import React from 'react';
2+
import { shallow } from 'enzyme';
3+
import PlayPause from './PlayPause';
4+
import styles from './PlayPause.css';
5+
import PlayArrow from './../Icon/play_arrow.svg';
6+
import Pause from './../Icon/pause.svg';
7+
8+
describe('PlayPause', () => {
9+
let component;
10+
11+
beforeAll(() => {
12+
component = shallow(<PlayPause />);
13+
});
14+
15+
it('should accept a className prop and append it to the components class', () => {
16+
const newClassNameString = 'a new className';
17+
expect(component.prop('className'))
18+
.toContain(styles.component);
19+
component.setProps({
20+
className: newClassNameString
21+
});
22+
expect(component.prop('className'))
23+
.toContain(styles.component);
24+
expect(component.prop('className'))
25+
.toContain(newClassNameString);
26+
});
27+
28+
it('triggers \'togglePause\' prop when the button is clicked', () => {
29+
const spy = jest.fn();
30+
component.setProps({
31+
togglePause: spy
32+
});
33+
expect(spy)
34+
.not.toHaveBeenCalled();
35+
component.find('button').simulate('click');
36+
expect(spy)
37+
.toHaveBeenCalled();
38+
});
39+
40+
describe('when paused', () => {
41+
beforeAll(() => {
42+
component.setProps({
43+
paused: true
44+
});
45+
});
46+
47+
it('shows a play icon', () => {
48+
expect(component.html())
49+
.toContain(PlayArrow);
50+
expect(component.html())
51+
.not.toContain(Pause);
52+
});
53+
54+
it('has correct aria-label', () => {
55+
expect(component.find('button').prop('aria-label'))
56+
.toEqual('Play');
57+
});
58+
});
59+
60+
describe('when playing', () => {
61+
beforeAll(() => {
62+
component.setProps({
63+
paused: false
64+
});
65+
});
66+
67+
it('shows a pause icon', () => {
68+
expect(component.html())
69+
.toContain(Pause);
70+
expect(component.html())
71+
.not.toContain(PlayArrow);
72+
});
73+
74+
it('has correct aria-label', () => {
75+
expect(component.find('button').prop('aria-label'))
76+
.toEqual('Pause');
77+
});
78+
});
79+
});

0 commit comments

Comments
 (0)