@@ -374,6 +374,7 @@ describe('CheckingComponent', () => {
374
374
env . setBookChapter ( 'JHN' , 2 ) ;
375
375
expect ( env . getQuestionText ( question ) ) . toBe ( 'John 2' ) ;
376
376
expect ( await env . getCurrentBookAndChapter ( ) ) . toBe ( 'John 2' ) ;
377
+ env . waitForQuestionTimersToComplete ( ) ;
377
378
} ) ) ;
378
379
379
380
it ( 'start question respects route book/chapter' , fakeAsync ( async ( ) => {
@@ -391,6 +392,41 @@ describe('CheckingComponent', () => {
391
392
discardPeriodicTasks ( ) ;
392
393
} ) ) ;
393
394
395
+ it ( 'updates active question when route book/chapter changes' , fakeAsync ( ( ) => {
396
+ const env = new TestEnvironment ( {
397
+ user : CHECKER_USER ,
398
+ projectBookRoute : 'JHN' ,
399
+ projectChapterRoute : 1 ,
400
+ questionScope : 'book'
401
+ } ) ;
402
+ expect ( env . component . questionsList ! . activeQuestionDoc ! . data ! . dataId ) . toBe ( 'q5Id' ) ;
403
+ env . setBookChapter ( 'JHN' , 2 ) ;
404
+ env . fixture . detectChanges ( ) ;
405
+ expect ( env . component . questionsList ! . activeQuestionDoc ! . data ! . dataId ) . toBe ( 'q15Id' ) ;
406
+ flush ( ) ;
407
+ discardPeriodicTasks ( ) ;
408
+ } ) ) ;
409
+
410
+ it ( 'clears active question when route book/chapter changes to chapter without questions' , fakeAsync ( ( ) => {
411
+ const env = new TestEnvironment ( {
412
+ user : CHECKER_USER ,
413
+ projectBookRoute : 'MAT' ,
414
+ projectChapterRoute : 1 ,
415
+ questionScope : 'book'
416
+ } ) ;
417
+ expect ( env . component . questionsList ! . activeQuestionDoc ! . data ! . dataId ) . toBe ( 'q16Id' ) ;
418
+ env . setBookChapter ( 'MAT' , 2 ) ;
419
+ env . fixture . detectChanges ( ) ;
420
+ expect ( env . component . questionsList ! . activeQuestionDoc ) . toBe ( undefined ) ;
421
+ expect ( env . component . chapter ) . toEqual ( 2 ) ;
422
+ env . setBookChapter ( 'MAT' , 3 ) ;
423
+ env . fixture . detectChanges ( ) ;
424
+ expect ( env . component . questionsList ! . activeQuestionDoc ) . toBe ( undefined ) ;
425
+ expect ( env . component . chapter ) . toEqual ( 3 ) ;
426
+ flush ( ) ;
427
+ discardPeriodicTasks ( ) ;
428
+ } ) ) ;
429
+
394
430
it ( 'can select a question' , fakeAsync ( ( ) => {
395
431
const env = new TestEnvironment ( { user : CHECKER_USER } ) ;
396
432
const question = env . selectQuestion ( 1 ) ;
@@ -569,8 +605,7 @@ describe('CheckingComponent', () => {
569
605
expect ( env . isSegmentHighlighted ( 1 , 5 ) ) . toBe ( true ) ;
570
606
expect ( env . segmentHasQuestion ( 1 , 5 ) ) . toBe ( true ) ;
571
607
expect ( env . component . questionVerseRefs . some ( verseRef => verseRef . equals ( new VerseRef ( 'JHN 1:5' ) ) ) ) . toBe ( true ) ;
572
- tick ( ) ;
573
- flush ( ) ;
608
+ env . waitForQuestionTimersToComplete ( ) ;
574
609
} ) ) ;
575
610
576
611
it ( 'records audio for question when button clicked' , fakeAsync ( ( ) => {
@@ -851,6 +886,38 @@ describe('CheckingComponent', () => {
851
886
env . waitForQuestionTimersToComplete ( ) ;
852
887
} ) ) ;
853
888
889
+ it ( 'should not reset scope after a user changes chapter' , fakeAsync ( ( ) => {
890
+ const env = new TestEnvironment ( {
891
+ user : ADMIN_USER ,
892
+ projectBookRoute : 'JHN' ,
893
+ projectChapterRoute : 1 ,
894
+ questionScope : 'chapter'
895
+ } ) ;
896
+ expect ( env . questions . length ) . toEqual ( 14 ) ;
897
+ env . component . onChapterSelect ( 2 ) ;
898
+ env . setBookChapter ( 'JHN' , 2 ) ;
899
+ tick ( ) ;
900
+ env . fixture . detectChanges ( ) ;
901
+ expect ( env . component . activeQuestionScope ) . toEqual ( 'chapter' ) ;
902
+ env . waitForQuestionTimersToComplete ( ) ;
903
+ } ) ) ;
904
+
905
+ it ( 'should not reset scope after a user changes book' , fakeAsync ( ( ) => {
906
+ const env = new TestEnvironment ( {
907
+ user : ADMIN_USER ,
908
+ projectBookRoute : 'JHN' ,
909
+ projectChapterRoute : 1 ,
910
+ questionScope : 'book'
911
+ } ) ;
912
+ expect ( env . questions . length ) . toEqual ( 15 ) ;
913
+ env . component . onBookSelect ( 40 ) ;
914
+ env . setBookChapter ( 'MAT' , 1 ) ;
915
+ tick ( ) ;
916
+ env . fixture . detectChanges ( ) ;
917
+ expect ( env . component . activeQuestionScope ) . toEqual ( 'book' ) ;
918
+ env . waitForQuestionTimersToComplete ( ) ;
919
+ } ) ) ;
920
+
854
921
it ( 'can narrow questions scope' , fakeAsync ( ( ) => {
855
922
const env = new TestEnvironment ( {
856
923
user : ADMIN_USER ,
@@ -921,7 +988,8 @@ describe('CheckingComponent', () => {
921
988
env . waitForQuestionTimersToComplete ( ) ;
922
989
923
990
expect ( spyUpdateQuestionRefs ) . toHaveBeenCalledTimes ( 1 ) ;
924
- expect ( spyRefreshSummary ) . toHaveBeenCalledTimes ( 1 ) ;
991
+ // Called at least once or more depending on if another question replaces the archived question
992
+ expect ( spyRefreshSummary ) . toHaveBeenCalled ( ) ;
925
993
} ) ) ;
926
994
} ) ;
927
995
@@ -1913,8 +1981,9 @@ describe('CheckingComponent', () => {
1913
1981
const env = new TestEnvironment ( { user : CHECKER_USER } ) ;
1914
1982
const questionDoc = spy ( env . getQuestionDoc ( 'q6Id' ) ) ;
1915
1983
env . selectQuestion ( 6 ) ;
1984
+ verify ( questionDoc ! . updateAnswerFileCache ( ) ) . times ( 1 ) ;
1916
1985
env . simulateRemoteEditAnswer ( 0 , 'Question 6 edited answer' ) ;
1917
- verify ( questionDoc ! . updateAnswerFileCache ( ) ) . times ( 3 ) ;
1986
+ verify ( questionDoc ! . updateAnswerFileCache ( ) ) . times ( 2 ) ;
1918
1987
expect ( ) . nothing ( ) ;
1919
1988
tick ( ) ;
1920
1989
flush ( ) ;
@@ -1924,8 +1993,9 @@ describe('CheckingComponent', () => {
1924
1993
const env = new TestEnvironment ( { user : ADMIN_USER } ) ;
1925
1994
const questionDoc = spy ( env . getQuestionDoc ( 'q6Id' ) ) ;
1926
1995
env . selectQuestion ( 6 ) ;
1996
+ verify ( questionDoc ! . updateAnswerFileCache ( ) ) . times ( 1 ) ;
1927
1997
env . simulateRemoteDeleteAnswer ( 'q6Id' , 0 ) ;
1928
- verify ( questionDoc ! . updateAnswerFileCache ( ) ) . times ( 3 ) ;
1998
+ verify ( questionDoc ! . updateAnswerFileCache ( ) ) . times ( 2 ) ;
1929
1999
expect ( ) . nothing ( ) ;
1930
2000
tick ( ) ;
1931
2001
flush ( ) ;
@@ -2760,7 +2830,11 @@ class TestEnvironment {
2760
2830
{
2761
2831
bookNum : 40 ,
2762
2832
hasSource : false ,
2763
- chapters : [ { number : 1 , lastVerse : 28 , isValid : true , permissions : { } } ] ,
2833
+ chapters : [
2834
+ { number : 1 , lastVerse : 28 , isValid : true , permissions : { } } ,
2835
+ { number : 2 , lastVerse : 23 , isValid : true , permissions : { } } ,
2836
+ { number : 3 , lastVerse : 26 , isValid : true , permissions : { } }
2837
+ ] ,
2764
2838
permissions : { }
2765
2839
}
2766
2840
] ,
@@ -3258,6 +3332,16 @@ class TestEnvironment {
3258
3332
id : getTextDocId ( projectId , 40 , 1 ) ,
3259
3333
data : this . createTextDataForChapter ( 1 ) ,
3260
3334
type : RichText . type . name
3335
+ } ,
3336
+ {
3337
+ id : getTextDocId ( projectId , 40 , 2 ) ,
3338
+ data : this . createTextDataForChapter ( 2 ) ,
3339
+ type : RichText . type . name
3340
+ } ,
3341
+ {
3342
+ id : getTextDocId ( projectId , 40 , 3 ) ,
3343
+ data : this . createTextDataForChapter ( 3 ) ,
3344
+ type : RichText . type . name
3261
3345
}
3262
3346
] ) ;
3263
3347
when ( mockedProjectService . getText ( anything ( ) ) ) . thenCall ( id =>
0 commit comments