Skip to content

Commit 3484b59

Browse files
committed
Unit test <Button/> calls to playSound
1 parent 33f2343 commit 3484b59

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

test/unit/oceans/ui.test.js

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {shallow} from 'enzyme';
44
import sinon from 'sinon';
55
import {Button} from '@ml/oceans/ui';
66
import * as guide from '@ml/oceans/models/guide';
7+
import * as soundLibrary from '@ml/oceans/models/soundLibrary';
78

89
const DEFAULT_PROPS = {
910
// radiumConfig.userAgent is required because our unit tests run in the "node" testEnvironment
@@ -13,14 +14,19 @@ const DEFAULT_PROPS = {
1314
};
1415

1516
describe('Button', () => {
16-
let onClickMock;
17+
let onClickMock, playSoundSpy;
1718

1819
beforeEach(() => {
20+
soundLibrary.injectSoundAPIs({playSound: sinon.fake()});
21+
playSoundSpy = sinon.spy(soundLibrary, 'playSound');
1922
onClickMock = sinon.fake.returns(false);
2023
});
2124

25+
afterEach(() => {
26+
soundLibrary.playSound.restore();
27+
});
28+
2229
it('dismisses guide on click', () => {
23-
guide.dismissCurrentGuide();
2430
const dismissCurrentGuideSpy = sinon.spy(guide, 'dismissCurrentGuide');
2531
const wrapper = shallow(
2632
<Button {...DEFAULT_PROPS} onClick={onClickMock} />
@@ -41,7 +47,34 @@ describe('Button', () => {
4147
expect(onClickMock.calledOnce);
4248
});
4349

44-
it('plays a sound if onClick prop does not return false', () => {});
50+
it('does not play a sound if onClick prop returns false', () => {
51+
const wrapper = shallow(
52+
<Button {...DEFAULT_PROPS} onClick={onClickMock} />
53+
);
54+
55+
wrapper.simulate('click');
56+
expect(!playSoundSpy.called);
57+
});
58+
59+
describe('onClick prop does not return false', () => {
60+
it('plays sound if supplied', () => {
61+
onClickMock = sinon.fake.returns(true);
62+
const wrapper = shallow(
63+
<Button {...DEFAULT_PROPS} onClick={onClickMock} sound="sortyes" />
64+
);
4565

46-
it('does not play a sound if onClick prop returns false', () => {});
66+
wrapper.simulate('click');
67+
expect(playSoundSpy.withArgs('sortyes').calledOnce);
68+
});
69+
70+
it('plays "other" sound if sound not supplied', () => {
71+
onClickMock = sinon.fake.returns(true);
72+
const wrapper = shallow(
73+
<Button {...DEFAULT_PROPS} onClick={onClickMock} />
74+
);
75+
76+
wrapper.simulate('click');
77+
expect(playSoundSpy.withArgs('other').calledOnce);
78+
});
79+
});
4780
});

0 commit comments

Comments
 (0)