Skip to content

Commit bc4927d

Browse files
committed
Basic unit tests for <Pond/>
1 parent eabd4d8 commit bc4927d

File tree

1 file changed

+110
-1
lines changed

1 file changed

+110
-1
lines changed

test/unit/oceans/ui.test.js

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
Words,
99
wordSet,
1010
Train,
11-
Predict
11+
Predict,
12+
Pond
1213
} from '@ml/oceans/ui';
1314
import guide from '@ml/oceans/models/guide';
1415
import soundLibrary from '@ml/oceans/models/soundLibrary';
@@ -425,3 +426,111 @@ describe('Predict', () => {
425426
expect(wrapper.exists('#uitest-continue-btn')).toBeTruthy();
426427
});
427428
});
429+
430+
describe('Pond', () => {
431+
let playSoundStub;
432+
433+
beforeEach(() => {
434+
playSoundStub = sinon.stub(soundLibrary, 'playSound');
435+
});
436+
437+
afterEach(() => {
438+
soundLibrary.playSound.restore();
439+
resetState();
440+
});
441+
442+
it('recall icons toggle fish set on click', () => {
443+
let wrapper = shallow(<Pond {...DEFAULT_PROPS} />);
444+
let checkIcon = wrapper.find('FontAwesomeIcon').at(0);
445+
let banIcon = wrapper.find('FontAwesomeIcon').at(1);
446+
447+
expect(checkIcon.prop('style').backgroundColor).toEqual(colors.green);
448+
expect(banIcon.prop('style').backgroundColor).toBeFalsy();
449+
expect(playSoundStub.callCount).toEqual(0);
450+
451+
banIcon.simulate('click');
452+
wrapper = shallow(<Pond {...DEFAULT_PROPS} />);
453+
checkIcon = wrapper.find('FontAwesomeIcon').at(0);
454+
banIcon = wrapper.find('FontAwesomeIcon').at(1);
455+
456+
expect(checkIcon.prop('style').backgroundColor).toBeFalsy();
457+
expect(banIcon.prop('style').backgroundColor).toEqual(colors.red);
458+
expect(playSoundStub.withArgs('no').callCount).toEqual(1);
459+
});
460+
461+
describe('info button', () => {
462+
it('displays based on state', () => {
463+
let wrapper = shallow(<Pond {...DEFAULT_PROPS} />);
464+
expect(wrapper.exists('#uitest-info-btn')).toBeFalsy();
465+
466+
setState({
467+
appMode: AppMode.FishShort,
468+
pondFish: [{}],
469+
recallFish: [{}]
470+
});
471+
wrapper = shallow(<Pond {...DEFAULT_PROPS} />);
472+
expect(wrapper.exists('#uitest-info-btn')).toBeTruthy();
473+
});
474+
475+
it('toggles pond panel on click', () => {
476+
setState({
477+
appMode: AppMode.FishShort,
478+
pondFish: [{}],
479+
recallFish: [{}],
480+
pondPanelShowing: false
481+
});
482+
let wrapper = shallow(<Pond {...DEFAULT_PROPS} />);
483+
484+
wrapper.find('#uitest-info-btn').simulate('click');
485+
expect(getState().pondPanelShowing).toBeTruthy();
486+
expect(playSoundStub.withArgs('sortyes').callCount).toEqual(1);
487+
488+
wrapper = shallow(<Pond {...DEFAULT_PROPS} />);
489+
expect(wrapper.exists('PondPanel')).toBeTruthy();
490+
491+
wrapper.find('#uitest-info-btn').simulate('click');
492+
expect(getState().pondPanelShowing).toBeFalsy();
493+
expect(playSoundStub.withArgs('sortno').callCount).toEqual(1);
494+
495+
wrapper = shallow(<Pond {...DEFAULT_PROPS} />);
496+
expect(wrapper.exists('PondPanel')).toBeFalsy();
497+
});
498+
});
499+
500+
describe('navigation', () => {
501+
it('displays buttons based on canSkipPond state', () => {
502+
let wrapper = shallow(<Pond {...DEFAULT_PROPS} />);
503+
expect(getState().canSkipPond).toBeFalsy();
504+
expect(wrapper.exists('#uitest-nav-btns')).toBeFalsy();
505+
506+
setState({canSkipPond: true});
507+
wrapper = shallow(<Pond {...DEFAULT_PROPS} />);
508+
expect(wrapper.exists('#uitest-nav-btns')).toBeTruthy();
509+
});
510+
511+
it('displays different buttons based on appMode state', () => {
512+
const getBtnText = (btns, i) =>
513+
btns
514+
.at(i)
515+
.render()
516+
.text();
517+
518+
setState({canSkipPond: true, appMode: AppMode.FishLong});
519+
let wrapper = shallow(<Pond {...DEFAULT_PROPS} />);
520+
521+
let buttons = wrapper.find('#uitest-nav-btns').find('Button');
522+
expect(buttons.length).toEqual(3);
523+
expect(getBtnText(buttons, 0)).toEqual('New Word');
524+
expect(getBtnText(buttons, 1)).toEqual('Finish');
525+
expect(getBtnText(buttons, 2)).toEqual('Train More');
526+
527+
setState({appMode: 'not-fish-long'});
528+
wrapper = shallow(<Pond {...DEFAULT_PROPS} />);
529+
530+
buttons = wrapper.find('#uitest-nav-btns').find('Button');
531+
expect(buttons.length).toEqual(2);
532+
expect(getBtnText(buttons, 0)).toEqual('Continue');
533+
expect(getBtnText(buttons, 1)).toEqual('Train More');
534+
});
535+
});
536+
});

0 commit comments

Comments
 (0)