@@ -4,12 +4,15 @@ import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testin
44import { MatRadioButtonHarness } from '@angular/material/radio/testing' ;
55import { provideNoopAnimations } 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' ;
@@ -78,8 +81,15 @@ describe('DraftUsfmFormatComponent', () => {
7881
7982 it ( 'shows message if user is not online' , fakeAsync ( async ( ) => {
8083 const env = new TestEnvironment ( {
81- config : { paragraphFormat : ParagraphBreakFormat . MoveToEnd , quoteFormat : QuoteFormat . Denormalized }
84+ project : {
85+ translateConfig : {
86+ draftConfig : {
87+ usfmConfig : { paragraphFormat : ParagraphBreakFormat . MoveToEnd , quoteFormat : QuoteFormat . Normalized }
88+ } as DraftConfig
89+ } as TranslateConfig
90+ }
8291 } ) ;
92+
8393 expect ( env . offlineMessage ) . toBeNull ( ) ;
8494
8595 env . onlineStatusService . setIsOnline ( false ) ;
@@ -102,19 +112,63 @@ describe('DraftUsfmFormatComponent', () => {
102112 verify ( mockedDraftHandlingService . getDraft ( anything ( ) , anything ( ) ) ) . once ( ) ;
103113 } ) ) ;
104114
115+ it ( 'can navigate to first book and chapter if book does not exist' , fakeAsync ( ( ) => {
116+ when ( mockedActivatedRoute . params ) . thenReturn ( of ( { bookId : 'NUM' , chapter : '1' } ) ) ;
117+ const env = new TestEnvironment ( ) ;
118+ tick ( EDITOR_READY_TIMEOUT ) ;
119+ env . fixture . detectChanges ( ) ;
120+ tick ( EDITOR_READY_TIMEOUT ) ;
121+ expect ( env . component . bookNum ) . toBe ( 1 ) ;
122+ expect ( env . component . chapterNum ) . toBe ( 1 ) ;
123+ verify ( mockedDraftHandlingService . getDraft ( anything ( ) , anything ( ) ) ) . once ( ) ;
124+ } ) ) ;
125+
126+ it ( 'can navigate to book and chapter if first chapter has no draft' , fakeAsync ( ( ) => {
127+ const env = new TestEnvironment ( {
128+ project : {
129+ texts : [
130+ {
131+ bookNum : 1 ,
132+ chapters : [
133+ { number : 1 , lastVerse : 15 , isValid : true , permissions : { } , hasDraft : false } ,
134+ { number : 2 , lastVerse : 20 , isValid : true , permissions : { } , hasDraft : true } ,
135+ { number : 3 , lastVerse : 18 , isValid : true , permissions : { } , hasDraft : true }
136+ ] ,
137+ hasSource : true ,
138+ permissions : { }
139+ }
140+ ]
141+ }
142+ } ) ;
143+ tick ( EDITOR_READY_TIMEOUT ) ;
144+ env . fixture . detectChanges ( ) ;
145+ tick ( EDITOR_READY_TIMEOUT ) ;
146+ expect ( env . component . bookNum ) . toBe ( 1 ) ;
147+ expect ( env . component . chapterNum ) . toBe ( 2 ) ;
148+ expect ( env . component . chaptersWithDrafts ) . toEqual ( [ 2 , 3 ] ) ;
149+ verify ( mockedDraftHandlingService . getDraft ( anything ( ) , anything ( ) ) ) . once ( ) ;
150+ } ) ) ;
151+
105152 // Book and chapter changed
106153 it ( 'navigates to a different book and chapter' , fakeAsync ( ( ) => {
107154 const env = new TestEnvironment ( {
108- config : { paragraphFormat : ParagraphBreakFormat . MoveToEnd , quoteFormat : QuoteFormat . Denormalized }
155+ project : {
156+ translateConfig : {
157+ draftConfig : {
158+ usfmConfig : { paragraphFormat : ParagraphBreakFormat . MoveToEnd , quoteFormat : QuoteFormat . Denormalized }
159+ } as DraftConfig
160+ } as TranslateConfig
161+ }
109162 } ) ;
163+
110164 verify ( mockedDraftHandlingService . getDraft ( anything ( ) , anything ( ) ) ) . once ( ) ;
111- expect ( env . component . chapters . length ) . toEqual ( 1 ) ;
165+ expect ( env . component . chaptersWithDrafts . length ) . toEqual ( 1 ) ;
112166 expect ( env . component . booksWithDrafts . length ) . toEqual ( 2 ) ;
113167
114168 env . component . bookChanged ( 2 ) ;
115169 tick ( ) ;
116170 env . fixture . detectChanges ( ) ;
117- expect ( env . component . chapters . length ) . toEqual ( 2 ) ;
171+ expect ( env . component . chaptersWithDrafts . length ) . toEqual ( 2 ) ;
118172 verify ( mockedDraftHandlingService . getDraft ( anything ( ) , anything ( ) ) ) . twice ( ) ;
119173
120174 env . component . chapterChanged ( 2 ) ;
@@ -133,15 +187,27 @@ describe('DraftUsfmFormatComponent', () => {
133187
134188 it ( 'should show the currently selected format options' , fakeAsync ( ( ) => {
135189 const env = new TestEnvironment ( {
136- config : { paragraphFormat : ParagraphBreakFormat . MoveToEnd , quoteFormat : QuoteFormat . Normalized }
190+ project : {
191+ translateConfig : {
192+ draftConfig : {
193+ usfmConfig : { paragraphFormat : ParagraphBreakFormat . MoveToEnd , quoteFormat : QuoteFormat . Normalized }
194+ } as DraftConfig
195+ } as TranslateConfig
196+ }
137197 } ) ;
138198 expect ( env . component . paragraphFormat . value ) . toBe ( ParagraphBreakFormat . MoveToEnd ) ;
139199 expect ( env . component . quoteFormat . value ) . toBe ( QuoteFormat . Normalized ) ;
140200 } ) ) ;
141201
142202 it ( 'goes back if user chooses different configurations and then goes back' , fakeAsync ( async ( ) => {
143203 const env = new TestEnvironment ( {
144- config : { paragraphFormat : ParagraphBreakFormat . MoveToEnd , quoteFormat : QuoteFormat . Denormalized }
204+ project : {
205+ translateConfig : {
206+ draftConfig : {
207+ usfmConfig : { paragraphFormat : ParagraphBreakFormat . MoveToEnd , quoteFormat : QuoteFormat . Denormalized }
208+ } as DraftConfig
209+ } as TranslateConfig
210+ }
145211 } ) ;
146212 verify ( mockedDraftHandlingService . getDraft ( anything ( ) , anything ( ) ) ) . once ( ) ;
147213 expect ( env . harnesses ?. length ) . toEqual ( 5 ) ;
@@ -162,7 +228,13 @@ describe('DraftUsfmFormatComponent', () => {
162228
163229 it ( 'should save changes to the draft format' , fakeAsync ( async ( ) => {
164230 const env = new TestEnvironment ( {
165- config : { paragraphFormat : ParagraphBreakFormat . MoveToEnd , quoteFormat : QuoteFormat . Denormalized }
231+ project : {
232+ translateConfig : {
233+ draftConfig : {
234+ usfmConfig : { paragraphFormat : ParagraphBreakFormat . MoveToEnd , quoteFormat : QuoteFormat . Denormalized }
235+ } as DraftConfig
236+ } as TranslateConfig
237+ }
166238 } ) ;
167239 verify ( mockedDraftHandlingService . getDraft ( anything ( ) , anything ( ) ) ) . once ( ) ;
168240 expect ( env . harnesses ?. length ) . toEqual ( 5 ) ;
@@ -212,7 +284,7 @@ class TestEnvironment {
212284 readonly projectId = 'project01' ;
213285 onlineStatusService : TestOnlineStatusService ;
214286
215- constructor ( args : { config ?: DraftUsfmConfig ; quotationAnalysis ?: QuotationAnalysis } = { } ) {
287+ constructor ( args : { project ?: Partial < SFProjectProfile > ; quotationAnalysis ?: QuotationAnalysis } = { } ) {
216288 const userDoc = mock ( UserDoc ) ;
217289 this . onlineStatusService = TestBed . inject ( OnlineStatusService ) as TestOnlineStatusService ;
218290 when ( mockedDraftGenerationService . getLastCompletedBuild ( anything ( ) ) ) . thenReturn (
@@ -232,7 +304,7 @@ class TestEnvironment {
232304 when ( mockedNoticeService . show ( anything ( ) ) ) . thenResolve ( ) ;
233305 when ( mockedDialogService . confirm ( anything ( ) , anything ( ) , anything ( ) ) ) . thenResolve ( true ) ;
234306 when ( mockedServalAdministration . onlineRetrievePreTranslationStatus ( anything ( ) ) ) . thenResolve ( ) ;
235- this . setupProject ( args . config ) ;
307+ this . setupProject ( args . project ) ;
236308 this . fixture = TestBed . createComponent ( DraftUsfmFormatComponent ) ;
237309 this . component = this . fixture . componentInstance ;
238310 const loader = TestbedHarnessEnvironment . loader ( this . fixture ) ;
@@ -257,7 +329,7 @@ class TestEnvironment {
257329 return this . fixture . nativeElement . querySelector ( '.quote-format-warning' ) ;
258330 }
259331
260- setupProject ( config ?: DraftUsfmConfig ) : void {
332+ setupProject ( project ?: Partial < SFProjectProfile > ) : void {
261333 const texts : TextInfo [ ] = [
262334 {
263335 bookNum : 1 ,
@@ -283,7 +355,7 @@ class TestEnvironment {
283355 ] ;
284356 const projectDoc = {
285357 id : this . projectId ,
286- data : createTestProjectProfile ( { translateConfig : { draftConfig : { usfmConfig : config } } , texts } )
358+ data : createTestProjectProfile ( { translateConfig : project ?. translateConfig , texts : project ?. texts ?? texts } )
287359 } as SFProjectProfileDoc ;
288360 when ( mockedActivatedProjectService . projectId ) . thenReturn ( this . projectId ) ;
289361 when ( mockedActivatedProjectService . projectDoc$ ) . thenReturn ( of ( projectDoc ) ) ;
0 commit comments