@@ -15,6 +15,7 @@ import guide from '@ml/oceans/models/guide';
1515import soundLibrary from '@ml/oceans/models/soundLibrary' ;
1616import train from '@ml/oceans/models/train' ;
1717import modeHelpers from '@ml/oceans/modeHelpers' ;
18+ import helpers from '@ml/oceans/helpers' ;
1819import { setState , getState , resetState } from '@ml/oceans/state' ;
1920import { AppMode , Modes } from '@ml/oceans/constants' ;
2021import colors from '@ml/oceans/colors' ;
@@ -327,6 +328,8 @@ describe('Train', () => {
327328 continueButton . simulate ( 'click' ) ;
328329
329330 expect ( toModeStub . withArgs ( Modes . Predicting ) . callCount ) . toEqual ( 1 ) ;
331+
332+ modeHelpers . toMode . restore ( ) ;
330333 } ) ;
331334} ) ;
332335
@@ -498,6 +501,16 @@ describe('Pond', () => {
498501 } ) ;
499502
500503 describe ( 'navigation' , ( ) => {
504+ let toModeStub ;
505+
506+ beforeEach ( ( ) => {
507+ toModeStub = sinon . stub ( modeHelpers , 'toMode' ) ;
508+ } ) ;
509+
510+ afterEach ( ( ) => {
511+ modeHelpers . toMode . restore ( ) ;
512+ } ) ;
513+
501514 it ( 'displays buttons based on canSkipPond state' , ( ) => {
502515 let wrapper = shallow ( < Pond { ...DEFAULT_PROPS } /> ) ;
503516 expect ( getState ( ) . canSkipPond ) . toBeFalsy ( ) ;
@@ -532,5 +545,63 @@ describe('Pond', () => {
532545 expect ( getBtnText ( buttons , 0 ) ) . toEqual ( 'Continue' ) ;
533546 expect ( getBtnText ( buttons , 1 ) ) . toEqual ( 'Train More' ) ;
534547 } ) ;
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+ } ) ;
535606 } ) ;
536607} ) ;
0 commit comments