Skip to content

Commit 60cecf6

Browse files
Merge branch 'master' into i18n-object
2 parents b8f8fb8 + 2bf9809 commit 60cecf6

File tree

3 files changed

+50
-8
lines changed

3 files changed

+50
-8
lines changed

package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@
1313
"^@ml(.*)$": "<rootDir>/src/$1",
1414
"^@public(.*)$": "<rootDir>/public/$1"
1515
},
16-
"setupTestFrameworkScriptFile": "<rootDir>/test/setup.js",
17-
"globals": {
18-
"window": {},
19-
"location": {}
20-
}
16+
"setupTestFrameworkScriptFile": "<rootDir>/test/setup.js"
2117
},
2218
"scripts": {
2319
"build": "webpack -p",

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={{
@@ -1580,7 +1581,7 @@ let Guide = class Guide extends React.Component {
15801581
);
15811582
}
15821583
};
1583-
Guide = Radium(Guide);
1584+
export const Guide = Radium(UnwrappedGuide); // Exported for unit tests.
15841585

15851586
export default class UI extends React.Component {
15861587
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';
@@ -626,3 +627,47 @@ describe('Pond', () => {
626627
});
627628
});
628629
});
630+
631+
describe('Guide', () => {
632+
let clock, currentGuideStub, playSoundStub;
633+
634+
beforeEach(() => {
635+
clock = sinon.useFakeTimers();
636+
currentGuideStub = sinon.stub(guide, 'getCurrentGuide');
637+
currentGuideStub.returns({
638+
id: 'guide-id',
639+
style: '',
640+
heading: 'hey, listen!',
641+
text: 'this is an important message'
642+
});
643+
playSoundStub = sinon.stub(soundLibrary, 'playSound');
644+
});
645+
646+
afterEach(() => {
647+
clock.restore();
648+
guide.getCurrentGuide.restore();
649+
soundLibrary.playSound.restore();
650+
});
651+
652+
it('sets guideTypingTimer if not already started', () => {
653+
setState({guideShowing: false, guideTypingTimer: null});
654+
const wrapper = shallow(<Guide {...DEFAULT_PROPS} />);
655+
656+
expect(getState().guideTypingTimer).not.toBeNull();
657+
});
658+
659+
it('is dismissable', () => {
660+
const dismissCurrentGuideStub = sinon
661+
.stub(guide, 'dismissCurrentGuide')
662+
.returns(true);
663+
const wrapper = shallow(<Guide {...DEFAULT_PROPS} />);
664+
const dismissHandler = wrapper.find('#uitest-dismiss-guide');
665+
666+
dismissHandler.simulate('click');
667+
668+
expect(dismissCurrentGuideStub.callCount).toEqual(1);
669+
expect(playSoundStub.withArgs('other').callCount).toEqual(1);
670+
671+
guide.dismissCurrentGuide.restore();
672+
});
673+
});

0 commit comments

Comments
 (0)