@@ -4,6 +4,7 @@ import {shallow} from 'enzyme';
44import sinon from 'sinon' ;
55import { Button } from '@ml/oceans/ui' ;
66import * as guide from '@ml/oceans/models/guide' ;
7+ import * as soundLibrary from '@ml/oceans/models/soundLibrary' ;
78
89const 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
1516describe ( '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