@@ -4,12 +4,15 @@ import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testin
44import { MatRadioButtonHarness } from '@angular/material/radio/testing' ;
55import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
66import { ActivatedRoute } from '@angular/router' ;
7+ import { SFProjectProfile } from 'realtime-server/lib/esm/scriptureforge/models/sf-project' ;
78import { createTestProjectProfile } from 'realtime-server/lib/esm/scriptureforge/models/sf-project-test-data' ;
89import { TextInfo } from 'realtime-server/lib/esm/scriptureforge/models/text-info' ;
910import {
11+ DraftConfig ,
1012 DraftUsfmConfig ,
1113 ParagraphBreakFormat ,
12- QuoteFormat
14+ QuoteFormat ,
15+ TranslateConfig
1316} from 'realtime-server/lib/esm/scriptureforge/models/translate-config' ;
1417import { of } from 'rxjs' ;
1518import { anything , deepEqual , mock , verify , when } from 'ts-mockito' ;
@@ -81,8 +84,15 @@ describe('DraftUsfmFormatComponent', () => {
8184
8285 it ( 'shows message if user is not online' , fakeAsync ( async ( ) => {
8386 const env = new TestEnvironment ( {
84- config : { paragraphFormat : ParagraphBreakFormat . MoveToEnd , quoteFormat : QuoteFormat . Denormalized }
87+ project : {
88+ translateConfig : {
89+ draftConfig : {
90+ usfmConfig : { paragraphFormat : ParagraphBreakFormat . MoveToEnd , quoteFormat : QuoteFormat . Normalized }
91+ } as DraftConfig
92+ } as TranslateConfig
93+ }
8594 } ) ;
95+
8696 expect ( env . offlineMessage ) . toBeNull ( ) ;
8797
8898 env . onlineStatusService . setIsOnline ( false ) ;
@@ -105,19 +115,63 @@ describe('DraftUsfmFormatComponent', () => {
105115 verify ( mockedDraftHandlingService . getDraft ( anything ( ) , anything ( ) ) ) . once ( ) ;
106116 } ) ) ;
107117
118+ it ( 'can navigate to first book and chapter if book does not exist' , fakeAsync ( ( ) => {
119+ when ( mockedActivatedRoute . params ) . thenReturn ( of ( { bookId : 'NUM' , chapter : '1' } ) ) ;
120+ const env = new TestEnvironment ( ) ;
121+ tick ( EDITOR_READY_TIMEOUT ) ;
122+ env . fixture . detectChanges ( ) ;
123+ tick ( EDITOR_READY_TIMEOUT ) ;
124+ expect ( env . component . bookNum ) . toBe ( 1 ) ;
125+ expect ( env . component . chapterNum ) . toBe ( 1 ) ;
126+ verify ( mockedDraftHandlingService . getDraft ( anything ( ) , anything ( ) ) ) . once ( ) ;
127+ } ) ) ;
128+
129+ it ( 'can navigate to book and chapter if first chapter has no draft' , fakeAsync ( ( ) => {
130+ const env = new TestEnvironment ( {
131+ project : {
132+ texts : [
133+ {
134+ bookNum : 1 ,
135+ chapters : [
136+ { number : 1 , lastVerse : 15 , isValid : true , permissions : { } , hasDraft : false } ,
137+ { number : 2 , lastVerse : 20 , isValid : true , permissions : { } , hasDraft : true } ,
138+ { number : 3 , lastVerse : 18 , isValid : true , permissions : { } , hasDraft : true }
139+ ] ,
140+ hasSource : true ,
141+ permissions : { }
142+ }
143+ ]
144+ }
145+ } ) ;
146+ tick ( EDITOR_READY_TIMEOUT ) ;
147+ env . fixture . detectChanges ( ) ;
148+ tick ( EDITOR_READY_TIMEOUT ) ;
149+ expect ( env . component . bookNum ) . toBe ( 1 ) ;
150+ expect ( env . component . chapterNum ) . toBe ( 2 ) ;
151+ expect ( env . component . chaptersWithDrafts ) . toEqual ( [ 2 , 3 ] ) ;
152+ verify ( mockedDraftHandlingService . getDraft ( anything ( ) , anything ( ) ) ) . once ( ) ;
153+ } ) ) ;
154+
108155 // Book and chapter changed
109156 it ( 'navigates to a different book and chapter' , fakeAsync ( ( ) => {
110157 const env = new TestEnvironment ( {
111- config : { paragraphFormat : ParagraphBreakFormat . MoveToEnd , quoteFormat : QuoteFormat . Denormalized }
158+ project : {
159+ translateConfig : {
160+ draftConfig : {
161+ usfmConfig : { paragraphFormat : ParagraphBreakFormat . MoveToEnd , quoteFormat : QuoteFormat . Denormalized }
162+ } as DraftConfig
163+ } as TranslateConfig
164+ }
112165 } ) ;
166+
113167 verify ( mockedDraftHandlingService . getDraft ( anything ( ) , anything ( ) ) ) . once ( ) ;
114- expect ( env . component . chapters . length ) . toEqual ( 1 ) ;
168+ expect ( env . component . chaptersWithDrafts . length ) . toEqual ( 1 ) ;
115169 expect ( env . component . booksWithDrafts . length ) . toEqual ( 2 ) ;
116170
117171 env . component . bookChanged ( 2 ) ;
118172 tick ( ) ;
119173 env . fixture . detectChanges ( ) ;
120- expect ( env . component . chapters . length ) . toEqual ( 2 ) ;
174+ expect ( env . component . chaptersWithDrafts . length ) . toEqual ( 2 ) ;
121175 verify ( mockedDraftHandlingService . getDraft ( anything ( ) , anything ( ) ) ) . twice ( ) ;
122176
123177 env . component . chapterChanged ( 2 ) ;
@@ -136,15 +190,27 @@ describe('DraftUsfmFormatComponent', () => {
136190
137191 it ( 'should show the currently selected format options' , fakeAsync ( ( ) => {
138192 const env = new TestEnvironment ( {
139- config : { paragraphFormat : ParagraphBreakFormat . MoveToEnd , quoteFormat : QuoteFormat . Normalized }
193+ project : {
194+ translateConfig : {
195+ draftConfig : {
196+ usfmConfig : { paragraphFormat : ParagraphBreakFormat . MoveToEnd , quoteFormat : QuoteFormat . Normalized }
197+ } as DraftConfig
198+ } as TranslateConfig
199+ }
140200 } ) ;
141201 expect ( env . component . paragraphFormat . value ) . toBe ( ParagraphBreakFormat . MoveToEnd ) ;
142202 expect ( env . component . quoteFormat . value ) . toBe ( QuoteFormat . Normalized ) ;
143203 } ) ) ;
144204
145205 it ( 'goes back if user chooses different configurations and then goes back' , fakeAsync ( async ( ) => {
146206 const env = new TestEnvironment ( {
147- config : { paragraphFormat : ParagraphBreakFormat . MoveToEnd , quoteFormat : QuoteFormat . Denormalized }
207+ project : {
208+ translateConfig : {
209+ draftConfig : {
210+ usfmConfig : { paragraphFormat : ParagraphBreakFormat . MoveToEnd , quoteFormat : QuoteFormat . Denormalized }
211+ } as DraftConfig
212+ } as TranslateConfig
213+ }
148214 } ) ;
149215 verify ( mockedDraftHandlingService . getDraft ( anything ( ) , anything ( ) ) ) . once ( ) ;
150216 expect ( env . harnesses ?. length ) . toEqual ( 5 ) ;
@@ -165,7 +231,13 @@ describe('DraftUsfmFormatComponent', () => {
165231
166232 it ( 'should save changes to the draft format' , fakeAsync ( async ( ) => {
167233 const env = new TestEnvironment ( {
168- config : { paragraphFormat : ParagraphBreakFormat . MoveToEnd , quoteFormat : QuoteFormat . Denormalized }
234+ project : {
235+ translateConfig : {
236+ draftConfig : {
237+ usfmConfig : { paragraphFormat : ParagraphBreakFormat . MoveToEnd , quoteFormat : QuoteFormat . Denormalized }
238+ } as DraftConfig
239+ } as TranslateConfig
240+ }
169241 } ) ;
170242 verify ( mockedDraftHandlingService . getDraft ( anything ( ) , anything ( ) ) ) . once ( ) ;
171243 expect ( env . harnesses ?. length ) . toEqual ( 5 ) ;
@@ -215,7 +287,7 @@ class TestEnvironment {
215287 readonly projectId = 'project01' ;
216288 onlineStatusService : TestOnlineStatusService ;
217289
218- constructor ( args : { config ?: DraftUsfmConfig ; quotationAnalysis ?: QuotationAnalysis } = { } ) {
290+ constructor ( args : { project ?: Partial < SFProjectProfile > ; quotationAnalysis ?: QuotationAnalysis } = { } ) {
219291 const userDoc = mock ( UserDoc ) ;
220292 this . onlineStatusService = TestBed . inject ( OnlineStatusService ) as TestOnlineStatusService ;
221293 when ( mockedDraftGenerationService . getLastCompletedBuild ( anything ( ) ) ) . thenReturn (
@@ -235,7 +307,7 @@ class TestEnvironment {
235307 when ( mockedNoticeService . show ( anything ( ) ) ) . thenResolve ( ) ;
236308 when ( mockedDialogService . confirm ( anything ( ) , anything ( ) , anything ( ) ) ) . thenResolve ( true ) ;
237309 when ( mockedServalAdministration . onlineRetrievePreTranslationStatus ( anything ( ) ) ) . thenResolve ( ) ;
238- this . setupProject ( args . config ) ;
310+ this . setupProject ( args . project ) ;
239311 this . fixture = TestBed . createComponent ( DraftUsfmFormatComponent ) ;
240312 this . component = this . fixture . componentInstance ;
241313 const loader = TestbedHarnessEnvironment . loader ( this . fixture ) ;
@@ -260,7 +332,7 @@ class TestEnvironment {
260332 return this . fixture . nativeElement . querySelector ( '.quote-format-warning' ) ;
261333 }
262334
263- setupProject ( config ?: DraftUsfmConfig ) : void {
335+ setupProject ( project ?: Partial < SFProjectProfile > ) : void {
264336 const texts : TextInfo [ ] = [
265337 {
266338 bookNum : 1 ,
@@ -286,7 +358,7 @@ class TestEnvironment {
286358 ] ;
287359 const projectDoc = {
288360 id : this . projectId ,
289- data : createTestProjectProfile ( { translateConfig : { draftConfig : { usfmConfig : config } } , texts } )
361+ data : createTestProjectProfile ( { translateConfig : project ?. translateConfig , texts : project ?. texts ?? texts } )
290362 } as SFProjectProfileDoc ;
291363 when ( mockedActivatedProjectService . projectId ) . thenReturn ( this . projectId ) ;
292364 when ( mockedActivatedProjectService . projectDoc$ ) . thenReturn ( of ( projectDoc ) ) ;
0 commit comments