Skip to content

Commit 8ec56da

Browse files
author
Madelyn Kasula
authored
Merge pull request #346 from code-dot-org/unit-testing
Unit test <Guide/>
2 parents e144c66 + 144b15d commit 8ec56da

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-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: 46 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,47 @@ describe('Pond', () => {
605606
});
606607
});
607608
});
609+
610+
describe('Guide', () => {
611+
let clock, currentGuideStub, playSoundStub;
612+
613+
beforeEach(() => {
614+
clock = sinon.useFakeTimers();
615+
currentGuideStub = sinon.stub(guide, 'getCurrentGuide');
616+
currentGuideStub.returns({
617+
id: 'guide-id',
618+
style: '',
619+
heading: 'hey, listen!',
620+
text: 'this is an important message'
621+
});
622+
playSoundStub = sinon.stub(soundLibrary, 'playSound');
623+
});
624+
625+
afterEach(() => {
626+
clock.restore();
627+
guide.getCurrentGuide.restore();
628+
soundLibrary.playSound.restore();
629+
});
630+
631+
it('sets guideTypingTimer if not already started', () => {
632+
setState({guideShowing: false, guideTypingTimer: null});
633+
const wrapper = shallow(<Guide {...DEFAULT_PROPS} />);
634+
635+
expect(getState().guideTypingTimer).not.toBeNull();
636+
});
637+
638+
it('is dismissable', () => {
639+
const dismissCurrentGuideStub = sinon
640+
.stub(guide, 'dismissCurrentGuide')
641+
.returns(true);
642+
const wrapper = shallow(<Guide {...DEFAULT_PROPS} />);
643+
const dismissHandler = wrapper.find('#uitest-dismiss-guide');
644+
645+
dismissHandler.simulate('click');
646+
647+
expect(dismissCurrentGuideStub.callCount).toEqual(1);
648+
expect(playSoundStub.withArgs('other').callCount).toEqual(1);
649+
650+
guide.dismissCurrentGuide.restore();
651+
});
652+
});

0 commit comments

Comments
 (0)