Skip to content

Commit 4b9b124

Browse files
committed
Unit test <Guide/>
1 parent 31a7908 commit 4b9b124

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

src/oceans/ui.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,7 +1472,7 @@ let UnwrappedPond = class Pond extends React.Component {
14721472
};
14731473
export const Pond = Radium(UnwrappedPond); // Exported for unit tests.
14741474

1475-
let Guide = class Guide extends React.Component {
1475+
let UnwrappedGuide = class Guide extends React.Component {
14761476
onShowing() {
14771477
clearInterval(getState().guideTypingTimer);
14781478
setState({guideShowing: true, guideTypingTimer: null});
@@ -1523,6 +1523,7 @@ let Guide = class Guide extends React.Component {
15231523
key={currentGuide.id}
15241524
style={guideBgStyle}
15251525
onClick={this.dismissGuideClick}
1526+
id="uitest-dismiss-guide"
15261527
>
15271528
<div
15281529
style={{
@@ -1584,7 +1585,7 @@ let Guide = class Guide extends React.Component {
15841585
);
15851586
}
15861587
};
1587-
Guide = Radium(Guide);
1588+
export const Guide = Radium(UnwrappedGuide); // Exported for unit tests.
15881589

15891590
export default class UI extends React.Component {
15901591
render() {

test/unit/oceans/ui.test.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
wordSet,
1010
Train,
1111
Predict,
12-
Pond
12+
Pond,
13+
Guide
1314
} from '@ml/oceans/ui';
1415
import guide from '@ml/oceans/models/guide';
1516
import soundLibrary from '@ml/oceans/models/soundLibrary';
@@ -605,3 +606,45 @@ describe('Pond', () => {
605606
});
606607
});
607608
});
609+
610+
describe('Guide', () => {
611+
let currentGuideStub, playSoundStub;
612+
613+
beforeEach(() => {
614+
currentGuideStub = sinon.stub(guide, 'getCurrentGuide');
615+
currentGuideStub.returns({
616+
id: 'guide-id',
617+
style: '',
618+
heading: 'hey, listen!',
619+
text: 'this is an important message'
620+
});
621+
playSoundStub = sinon.stub(soundLibrary, 'playSound');
622+
});
623+
624+
afterEach(() => {
625+
guide.getCurrentGuide.restore();
626+
soundLibrary.playSound.restore();
627+
});
628+
629+
it('sets guideTypingTimer if not already started', () => {
630+
setState({guideShowing: false, guideTypingTimer: null});
631+
const wrapper = shallow(<Guide {...DEFAULT_PROPS} />);
632+
633+
expect(getState().guideTypingTimer).not.toBeNull();
634+
});
635+
636+
it('is dismissable', () => {
637+
const dismissCurrentGuideStub = sinon
638+
.stub(guide, 'dismissCurrentGuide')
639+
.returns(true);
640+
const wrapper = shallow(<Guide {...DEFAULT_PROPS} />);
641+
const dismissHandler = wrapper.find('#uitest-dismiss-guide');
642+
643+
dismissHandler.simulate('click');
644+
645+
expect(dismissCurrentGuideStub.callCount).toEqual(1);
646+
expect(playSoundStub.withArgs('other').callCount).toEqual(1);
647+
648+
guide.dismissCurrentGuide.restore();
649+
});
650+
});

0 commit comments

Comments
 (0)