@@ -7,22 +7,28 @@ import { ActivatedRoute } from '@angular/router';
77import { saveAs } from 'file-saver' ;
88import { SystemRole } from 'realtime-server/lib/esm/common/models/system-role' ;
99import { createTestProjectProfile } from 'realtime-server/lib/esm/scriptureforge/models/sf-project-test-data' ;
10+ import { TrainingData } from 'realtime-server/lib/esm/scriptureforge/models/training-data' ;
1011import { DraftConfig } from 'realtime-server/lib/esm/scriptureforge/models/translate-config' ;
1112import { BehaviorSubject , of , throwError } from 'rxjs' ;
12- import { anything , mock , verify , when } from 'ts-mockito' ;
13+ import { anything , instance , mock , verify , when } from 'ts-mockito' ;
1314import { ActivatedProjectService } from 'xforge-common/activated-project.service' ;
1415import { AuthService } from 'xforge-common/auth.service' ;
16+ import { FileService } from 'xforge-common/file.service' ;
1517import { I18nService } from 'xforge-common/i18n.service' ;
1618import { NoticeService } from 'xforge-common/notice.service' ;
1719import { OnlineStatusService } from 'xforge-common/online-status.service' ;
1820import { provideTestOnlineStatus } from 'xforge-common/test-online-status-providers' ;
1921import { TestOnlineStatusService } from 'xforge-common/test-online-status.service' ;
2022import { configureTestingModule } from 'xforge-common/test-utils' ;
23+ import { FileType } from '../../xforge-common/models/file-offline-data' ;
24+ import { RealtimeQuery } from '../../xforge-common/models/realtime-query' ;
2125import { SFProjectProfileDoc } from '../core/models/sf-project-profile-doc' ;
26+ import { TrainingDataDoc } from '../core/models/training-data-doc' ;
2227import { SFProjectService } from '../core/sf-project.service' ;
2328import { BuildDto } from '../machine-api/build-dto' ;
2429import { DraftZipProgress } from '../translate/draft-generation/draft-generation' ;
2530import { DraftGenerationService } from '../translate/draft-generation/draft-generation.service' ;
31+ import { TrainingDataService } from '../translate/draft-generation/training-data/training-data.service' ;
2632import { ServalAdministrationService } from './serval-administration.service' ;
2733import { ServalProjectComponent } from './serval-project.component' ;
2834
@@ -36,23 +42,27 @@ const mockActivatedProjectService = mock(ActivatedProjectService);
3642const mockActivatedRoute = mock ( ActivatedRoute ) ;
3743const mockAuthService = mock ( AuthService ) ;
3844const mockDraftGenerationService = mock ( DraftGenerationService ) ;
45+ const mockFileService = mock ( FileService ) ;
3946const mockedI18nService = mock ( I18nService ) ;
4047const mockNoticeService = mock ( NoticeService ) ;
4148const mockSFProjectService = mock ( SFProjectService ) ;
4249const mockServalAdministrationService = mock ( ServalAdministrationService ) ;
50+ const mockTrainingDataService = mock ( TrainingDataService ) ;
4351
44- describe ( 'ServalProjectComponent' , ( ) => {
52+ fdescribe ( 'ServalProjectComponent' , ( ) => {
4553 configureTestingModule ( ( ) => ( {
4654 providers : [
4755 provideTestOnlineStatus ( ) ,
4856 { provide : ActivatedProjectService , useMock : mockActivatedProjectService } ,
4957 { provide : ActivatedRoute , useMock : mockActivatedRoute } ,
5058 { provide : AuthService , useMock : mockAuthService } ,
5159 { provide : DraftGenerationService , useMock : mockDraftGenerationService } ,
60+ { provide : FileService , useMock : mockFileService } ,
5261 { provide : I18nService , useMock : mockedI18nService } ,
5362 { provide : NoticeService , useMock : mockNoticeService } ,
5463 { provide : OnlineStatusService , useClass : TestOnlineStatusService } ,
5564 { provide : ServalAdministrationService , useMock : mockServalAdministrationService } ,
65+ { provide : TrainingDataService , useMock : mockTrainingDataService } ,
5666 { provide : SFProjectService , useMock : mockSFProjectService } ,
5767 provideNoopAnimations ( )
5868 ]
@@ -116,33 +126,33 @@ describe('ServalProjectComponent', () => {
116126 it ( 'should disable the download button when offline' , fakeAsync ( ( ) => {
117127 const env = new TestEnvironment ( ) ;
118128 env . onlineStatus = false ;
119- expect ( env . firstDownloadButton . innerText ) . toContain ( 'Download' ) ;
120- expect ( env . firstDownloadButton . disabled ) . toBe ( true ) ;
129+ expect ( env . firstSourceDownloadButton . innerText ) . toContain ( 'Download' ) ;
130+ expect ( env . firstSourceDownloadButton . disabled ) . toBe ( true ) ;
121131 } ) ) ;
122132
123133 it ( 'should display a notice if the project cannot be downloaded' , fakeAsync ( ( ) => {
124134 const env = new TestEnvironment ( ) ;
125135 when ( mockServalAdministrationService . downloadProject ( anything ( ) ) ) . thenReturn (
126136 throwError ( ( ) => new HttpErrorResponse ( { status : 404 } ) )
127137 ) ;
128- expect ( env . firstDownloadButton . innerText ) . toContain ( 'Download' ) ;
129- expect ( env . firstDownloadButton . disabled ) . toBe ( false ) ;
130- env . clickElement ( env . firstDownloadButton ) ;
138+ expect ( env . firstSourceDownloadButton . innerText ) . toContain ( 'Download' ) ;
139+ expect ( env . firstSourceDownloadButton . disabled ) . toBe ( false ) ;
140+ env . clickElement ( env . firstSourceDownloadButton ) ;
131141 verify ( mockNoticeService . showError ( anything ( ) ) ) . once ( ) ;
132142 } ) ) ;
133143
134144 it ( 'should have a download button' , fakeAsync ( ( ) => {
135145 const env = new TestEnvironment ( ) ;
136- expect ( env . downloadButtons . length ) . toBe ( 4 ) ;
137- expect ( env . firstDownloadButton . innerText ) . toContain ( 'Download' ) ;
138- expect ( env . firstDownloadButton . disabled ) . toBe ( false ) ;
146+ expect ( env . sourceDownloadButtons . length ) . toBe ( 4 ) ;
147+ expect ( env . firstSourceDownloadButton . innerText ) . toContain ( 'Download' ) ;
148+ expect ( env . firstSourceDownloadButton . disabled ) . toBe ( false ) ;
139149 } ) ) ;
140150
141151 it ( 'should allow clicking of the button to download' , fakeAsync ( ( ) => {
142152 const env = new TestEnvironment ( ) ;
143- expect ( env . firstDownloadButton . innerText ) . toContain ( 'Download' ) ;
144- expect ( env . firstDownloadButton . disabled ) . toBe ( false ) ;
145- env . clickElement ( env . firstDownloadButton ) ;
153+ expect ( env . firstSourceDownloadButton . innerText ) . toContain ( 'Download' ) ;
154+ expect ( env . firstSourceDownloadButton . disabled ) . toBe ( false ) ;
155+ env . clickElement ( env . firstSourceDownloadButton ) ;
146156 expect ( saveAs ) . toHaveBeenCalled ( ) ;
147157 } ) ) ;
148158 } ) ;
@@ -186,6 +196,33 @@ describe('ServalProjectComponent', () => {
186196 } ) ) ;
187197 } ) ;
188198
199+ describe ( 'download training data' , ( ) => {
200+ it ( 'should show training data saved on a project' , fakeAsync ( ( ) => {
201+ const env = new TestEnvironment ( ) ;
202+ tick ( ) ;
203+ env . fixture . detectChanges ( ) ;
204+ expect ( env . component . trainingDataFiles ) . toBeDefined ( ) ;
205+ expect ( env . component . trainingDataFiles . length ) . toBe ( 1 ) ;
206+ expect ( env . component . trainingDataFiles [ 0 ] . dataId ) . toBe ( 'dataId01' ) ;
207+ expect ( env . component . trainingDataFiles [ 0 ] . fileUrl ) . toBe ( 'file-url' ) ;
208+ } ) ) ;
209+
210+ it ( 'should disable the download button when offline' , fakeAsync ( ( ) => {
211+ const env = new TestEnvironment ( ) ;
212+ env . onlineStatus = false ;
213+ expect ( env . downloadTrainingDataButton . disabled ) . toBe ( true ) ;
214+ } ) ) ;
215+
216+ it ( 'can download the training data' , fakeAsync ( ( ) => {
217+ const env = new TestEnvironment ( ) ;
218+ tick ( ) ;
219+ env . fixture . detectChanges ( ) ;
220+ expect ( env . downloadTrainingDataButton ) . not . toBeNull ( ) ;
221+ env . clickElement ( env . downloadTrainingDataButton ) ;
222+ verify ( mockFileService . onlineDownloadFile ( FileType . TrainingData , 'file-url' , 'training-data-01.csv' ) ) . once ( ) ;
223+ } ) ) ;
224+ } ) ;
225+
189226 describe ( 'get last completed build' , ( ) => {
190227 it ( 'does not get last completed build if project does not have draft books' , fakeAsync ( ( ) => {
191228 const env = new TestEnvironment ( { preTranslate : false } ) ;
@@ -360,6 +397,19 @@ describe('ServalProjectComponent', () => {
360397 when ( mockDraftGenerationService . getBuildProgress ( anything ( ) ) ) . thenReturn ( of ( { additionalInfo : { } } as BuildDto ) ) ;
361398 when ( mockSFProjectService . hasDraft ( anything ( ) ) ) . thenReturn ( args . preTranslate ) ;
362399 when ( mockSFProjectService . onlineSetServalConfig ( this . mockProjectId , anything ( ) ) ) . thenResolve ( ) ;
400+ const trainingData : TrainingDataDoc [ ] = [
401+ {
402+ id : 'training01' ,
403+ data : {
404+ fileUrl : 'file-url' ,
405+ dataId : 'dataId01' ,
406+ title : 'training-data-01.csv'
407+ } as TrainingData
408+ } as TrainingDataDoc
409+ ] ;
410+ const mockQuery : RealtimeQuery < TrainingDataDoc > = mock ( RealtimeQuery < TrainingDataDoc > ) ;
411+ when ( mockQuery . docs ) . thenReturn ( trainingData ) ;
412+ when ( mockTrainingDataService . queryTrainingDataAsync ( anything ( ) , anything ( ) ) ) . thenResolve ( instance ( mockQuery ) ) ;
363413
364414 spyOn ( saveAs , 'saveAs' ) . and . stub ( ) ;
365415
@@ -380,16 +430,20 @@ describe('ServalProjectComponent', () => {
380430 return this . fixture . nativeElement . querySelector ( '#view-event-log' ) ;
381431 }
382432
383- get firstDownloadButton ( ) : HTMLInputElement {
384- return this . fixture . nativeElement . querySelector ( 'td button' ) ;
433+ get firstSourceDownloadButton ( ) : HTMLInputElement {
434+ return this . fixture . nativeElement . querySelector ( '.draft-sources-table td button' ) ;
385435 }
386436
387- get downloadButtons ( ) : NodeListOf < HTMLButtonElement > {
388- return this . fixture . nativeElement . querySelectorAll ( 'td button' ) ;
437+ get sourceDownloadButtons ( ) : NodeListOf < HTMLButtonElement > {
438+ return this . fixture . nativeElement . querySelectorAll ( '.draft-sources-table td button' ) ;
389439 }
390440
391441 get downloadDraftButton ( ) : HTMLInputElement {
392- return this . fixture . nativeElement . querySelector ( '#download-draft' ) ;
442+ return this . fixture . nativeElement . querySelector ( '#download-draft' ) ! ;
443+ }
444+
445+ get downloadTrainingDataButton ( ) : HTMLInputElement {
446+ return this . fixture . nativeElement . querySelector ( '.training-data-table td button' ) ;
393447 }
394448
395449 get saveServalConfigButton ( ) : HTMLInputElement {
0 commit comments