@@ -8,12 +8,14 @@ import {
88 Words ,
99 wordSet ,
1010 Train ,
11- Predict
11+ Predict ,
12+ Pond
1213} from '@ml/oceans/ui' ;
1314import guide from '@ml/oceans/models/guide' ;
1415import soundLibrary from '@ml/oceans/models/soundLibrary' ;
1516import train from '@ml/oceans/models/train' ;
1617import modeHelpers from '@ml/oceans/modeHelpers' ;
18+ import helpers from '@ml/oceans/helpers' ;
1719import { setState , getState , resetState } from '@ml/oceans/state' ;
1820import { AppMode , Modes } from '@ml/oceans/constants' ;
1921import colors from '@ml/oceans/colors' ;
@@ -326,6 +328,8 @@ describe('Train', () => {
326328 continueButton . simulate ( 'click' ) ;
327329
328330 expect ( toModeStub . withArgs ( Modes . Predicting ) . callCount ) . toEqual ( 1 ) ;
331+
332+ modeHelpers . toMode . restore ( ) ;
329333 } ) ;
330334} ) ;
331335
@@ -425,3 +429,179 @@ describe('Predict', () => {
425429 expect ( wrapper . exists ( '#uitest-continue-btn' ) ) . toBeTruthy ( ) ;
426430 } ) ;
427431} ) ;
432+
433+ describe ( 'Pond' , ( ) => {
434+ let playSoundStub ;
435+
436+ beforeEach ( ( ) => {
437+ playSoundStub = sinon . stub ( soundLibrary , 'playSound' ) ;
438+ } ) ;
439+
440+ afterEach ( ( ) => {
441+ soundLibrary . playSound . restore ( ) ;
442+ resetState ( ) ;
443+ } ) ;
444+
445+ it ( 'recall icons toggle fish set on click' , ( ) => {
446+ let wrapper = shallow ( < Pond { ...DEFAULT_PROPS } /> ) ;
447+ let checkIcon = wrapper . find ( 'FontAwesomeIcon' ) . at ( 0 ) ;
448+ let banIcon = wrapper . find ( 'FontAwesomeIcon' ) . at ( 1 ) ;
449+
450+ expect ( checkIcon . prop ( 'style' ) . backgroundColor ) . toEqual ( colors . green ) ;
451+ expect ( banIcon . prop ( 'style' ) . backgroundColor ) . toBeFalsy ( ) ;
452+ expect ( playSoundStub . callCount ) . toEqual ( 0 ) ;
453+
454+ banIcon . simulate ( 'click' ) ;
455+ wrapper = shallow ( < Pond { ...DEFAULT_PROPS } /> ) ;
456+ checkIcon = wrapper . find ( 'FontAwesomeIcon' ) . at ( 0 ) ;
457+ banIcon = wrapper . find ( 'FontAwesomeIcon' ) . at ( 1 ) ;
458+
459+ expect ( checkIcon . prop ( 'style' ) . backgroundColor ) . toBeFalsy ( ) ;
460+ expect ( banIcon . prop ( 'style' ) . backgroundColor ) . toEqual ( colors . red ) ;
461+ expect ( playSoundStub . withArgs ( 'no' ) . callCount ) . toEqual ( 1 ) ;
462+ } ) ;
463+
464+ describe ( 'info button' , ( ) => {
465+ it ( 'displays based on state' , ( ) => {
466+ let wrapper = shallow ( < Pond { ...DEFAULT_PROPS } /> ) ;
467+ expect ( wrapper . exists ( '#uitest-info-btn' ) ) . toBeFalsy ( ) ;
468+
469+ setState ( {
470+ appMode : AppMode . FishShort ,
471+ pondFish : [ { } ] ,
472+ recallFish : [ { } ]
473+ } ) ;
474+ wrapper = shallow ( < Pond { ...DEFAULT_PROPS } /> ) ;
475+ expect ( wrapper . exists ( '#uitest-info-btn' ) ) . toBeTruthy ( ) ;
476+ } ) ;
477+
478+ it ( 'toggles pond panel on click' , ( ) => {
479+ setState ( {
480+ appMode : AppMode . FishShort ,
481+ pondFish : [ { } ] ,
482+ recallFish : [ { } ] ,
483+ pondPanelShowing : false
484+ } ) ;
485+ let wrapper = shallow ( < Pond { ...DEFAULT_PROPS } /> ) ;
486+
487+ wrapper . find ( '#uitest-info-btn' ) . simulate ( 'click' ) ;
488+ expect ( getState ( ) . pondPanelShowing ) . toBeTruthy ( ) ;
489+ expect ( playSoundStub . withArgs ( 'sortyes' ) . callCount ) . toEqual ( 1 ) ;
490+
491+ wrapper = shallow ( < Pond { ...DEFAULT_PROPS } /> ) ;
492+ expect ( wrapper . exists ( 'PondPanel' ) ) . toBeTruthy ( ) ;
493+
494+ wrapper . find ( '#uitest-info-btn' ) . simulate ( 'click' ) ;
495+ expect ( getState ( ) . pondPanelShowing ) . toBeFalsy ( ) ;
496+ expect ( playSoundStub . withArgs ( 'sortno' ) . callCount ) . toEqual ( 1 ) ;
497+
498+ wrapper = shallow ( < Pond { ...DEFAULT_PROPS } /> ) ;
499+ expect ( wrapper . exists ( 'PondPanel' ) ) . toBeFalsy ( ) ;
500+ } ) ;
501+ } ) ;
502+
503+ describe ( 'navigation' , ( ) => {
504+ let toModeStub ;
505+
506+ beforeEach ( ( ) => {
507+ toModeStub = sinon . stub ( modeHelpers , 'toMode' ) ;
508+ } ) ;
509+
510+ afterEach ( ( ) => {
511+ modeHelpers . toMode . restore ( ) ;
512+ } ) ;
513+
514+ it ( 'displays buttons based on canSkipPond state' , ( ) => {
515+ let wrapper = shallow ( < Pond { ...DEFAULT_PROPS } /> ) ;
516+ expect ( getState ( ) . canSkipPond ) . toBeFalsy ( ) ;
517+ expect ( wrapper . exists ( '#uitest-nav-btns' ) ) . toBeFalsy ( ) ;
518+
519+ setState ( { canSkipPond : true } ) ;
520+ wrapper = shallow ( < Pond { ...DEFAULT_PROPS } /> ) ;
521+ expect ( wrapper . exists ( '#uitest-nav-btns' ) ) . toBeTruthy ( ) ;
522+ } ) ;
523+
524+ it ( 'displays different buttons based on appMode state' , ( ) => {
525+ const getBtnText = ( btns , i ) =>
526+ btns
527+ . at ( i )
528+ . render ( )
529+ . text ( ) ;
530+
531+ setState ( { canSkipPond : true , appMode : AppMode . FishLong } ) ;
532+ let wrapper = shallow ( < Pond { ...DEFAULT_PROPS } /> ) ;
533+
534+ let buttons = wrapper . find ( '#uitest-nav-btns' ) . find ( 'Button' ) ;
535+ expect ( buttons . length ) . toEqual ( 3 ) ;
536+ expect ( getBtnText ( buttons , 0 ) ) . toEqual ( 'New Word' ) ;
537+ expect ( getBtnText ( buttons , 1 ) ) . toEqual ( 'Finish' ) ;
538+ expect ( getBtnText ( buttons , 2 ) ) . toEqual ( 'Train More' ) ;
539+
540+ setState ( { appMode : 'not-fish-long' } ) ;
541+ wrapper = shallow ( < Pond { ...DEFAULT_PROPS } /> ) ;
542+
543+ buttons = wrapper . find ( '#uitest-nav-btns' ) . find ( 'Button' ) ;
544+ expect ( buttons . length ) . toEqual ( 2 ) ;
545+ expect ( getBtnText ( buttons , 0 ) ) . toEqual ( 'Continue' ) ;
546+ expect ( getBtnText ( buttons , 1 ) ) . toEqual ( 'Train More' ) ;
547+ } ) ;
548+
549+ it ( '"new word" button resets training and transitions to Modes.Words' , ( ) => {
550+ const resetTrainingStub = sinon . stub ( helpers , 'resetTraining' ) ;
551+
552+ setState ( { canSkipPond : true , appMode : AppMode . FishLong } ) ;
553+ let wrapper = shallow ( < Pond { ...DEFAULT_PROPS } /> ) ;
554+ const newWordBtn = wrapper . find ( '#uitest-nav-btns Button' ) . at ( 0 ) ;
555+
556+ newWordBtn . simulate ( 'click' ) ;
557+
558+ const newState = getState ( ) ;
559+ expect ( newState . pondClickedFish ) . toBeNull ( ) ;
560+ expect ( newState . pondPanelShowing ) . toBeFalsy ( ) ;
561+ expect ( resetTrainingStub . callCount ) . toEqual ( 1 ) ;
562+ expect ( toModeStub . withArgs ( Modes . Words ) . callCount ) . toEqual ( 1 ) ;
563+
564+ helpers . resetTraining . restore ( ) ;
565+ } ) ;
566+
567+ it ( '"finish" button calls onContinue' , ( ) => {
568+ const onContinueSpy = sinon . spy ( ) ;
569+ setState ( {
570+ canSkipPond : true ,
571+ appMode : AppMode . FishLong ,
572+ onContinue : onContinueSpy
573+ } ) ;
574+ let wrapper = shallow ( < Pond { ...DEFAULT_PROPS } /> ) ;
575+ const finishBtn = wrapper . find ( '#uitest-nav-btns Button' ) . at ( 1 ) ;
576+
577+ finishBtn . simulate ( 'click' ) ;
578+ expect ( onContinueSpy . callCount ) . toEqual ( 1 ) ;
579+ } ) ;
580+
581+ it ( '"continue" button calls onContinue' , ( ) => {
582+ const onContinueSpy = sinon . spy ( ) ;
583+ setState ( {
584+ canSkipPond : true ,
585+ onContinue : onContinueSpy
586+ } ) ;
587+ let wrapper = shallow ( < Pond { ...DEFAULT_PROPS } /> ) ;
588+ const continueBtn = wrapper . find ( '#uitest-nav-btns Button' ) . at ( 0 ) ;
589+
590+ continueBtn . simulate ( 'click' ) ;
591+ expect ( onContinueSpy . callCount ) . toEqual ( 1 ) ;
592+ } ) ;
593+
594+ it ( '"train more" button transitions to Modes.Training' , ( ) => {
595+ setState ( { canSkipPond : true } ) ;
596+ let wrapper = shallow ( < Pond { ...DEFAULT_PROPS } /> ) ;
597+ const trainMoreBtn = wrapper . find ( '#uitest-nav-btns Button' ) . at ( 1 ) ;
598+
599+ trainMoreBtn . simulate ( 'click' ) ;
600+
601+ const newState = getState ( ) ;
602+ expect ( newState . pondClickedFish ) . toBeNull ( ) ;
603+ expect ( newState . pondPanelShowing ) . toBeFalsy ( ) ;
604+ expect ( toModeStub . withArgs ( Modes . Training ) . callCount ) . toEqual ( 1 ) ;
605+ } ) ;
606+ } ) ;
607+ } ) ;
0 commit comments