@@ -4,22 +4,19 @@ import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testin
4
4
import { By } from '@angular/platform-browser' ;
5
5
import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
6
6
import { createTestProjectProfile } from 'realtime-server/lib/esm/scriptureforge/models/sf-project-test-data' ;
7
- import { BehaviorSubject , of , Subject } from 'rxjs' ;
8
- import { anything , instance , mock , verify , when } from 'ts-mockito' ;
7
+ import { BehaviorSubject , of } from 'rxjs' ;
8
+ import { anything , mock , verify , when } from 'ts-mockito' ;
9
9
import { ActivatedProjectService } from 'xforge-common/activated-project.service' ;
10
10
import { createTestFeatureFlag , FeatureFlagService } from 'xforge-common/feature-flags/feature-flag.service' ;
11
- import { RealtimeQuery } from 'xforge-common/models/realtime-query' ;
12
11
import { NoticeService } from 'xforge-common/notice.service' ;
13
12
import { OnlineStatusService } from 'xforge-common/online-status.service' ;
14
13
import { TestRealtimeModule } from 'xforge-common/test-realtime.module' ;
15
14
import { configureTestingModule , TestTranslocoModule } from 'xforge-common/test-utils' ;
16
15
import { SFProjectProfileDoc } from '../../../core/models/sf-project-profile-doc' ;
17
16
import { SF_TYPE_REGISTRY } from '../../../core/models/sf-type-registry' ;
18
- import { TrainingDataDoc } from '../../../core/models/training-data-doc' ;
19
17
import { ProgressService , TextProgress } from '../../../shared/progress-service/progress.service' ;
20
18
import { NllbLanguageService } from '../../nllb-language.service' ;
21
19
import { DraftSource , DraftSourcesAsArrays , DraftSourcesService } from '../draft-sources.service' ;
22
- import { TrainingDataService } from '../training-data/training-data.service' ;
23
20
import { DraftGenerationStepsComponent , DraftGenerationStepsResult } from './draft-generation-steps.component' ;
24
21
25
22
describe ( 'DraftGenerationStepsComponent' , ( ) => {
@@ -29,18 +26,11 @@ describe('DraftGenerationStepsComponent', () => {
29
26
const mockActivatedProjectService = mock ( ActivatedProjectService ) ;
30
27
const mockFeatureFlagService = mock ( FeatureFlagService ) ;
31
28
const mockNllbLanguageService = mock ( NllbLanguageService ) ;
32
- const mockTrainingDataService = mock ( TrainingDataService ) ;
33
29
const mockProgressService = mock ( ProgressService ) ;
34
30
const mockOnlineStatusService = mock ( OnlineStatusService ) ;
35
31
const mockNoticeService = mock ( NoticeService ) ;
36
32
const mockDraftSourceService = mock ( DraftSourcesService ) ;
37
33
38
- const mockTrainingDataQuery : RealtimeQuery < TrainingDataDoc > = mock ( RealtimeQuery ) ;
39
- const trainingDataQueryLocalChanges$ : Subject < void > = new Subject < void > ( ) ;
40
- when ( mockTrainingDataQuery . localChanges$ ) . thenReturn ( trainingDataQueryLocalChanges$ ) ;
41
- when ( mockTrainingDataQuery . ready$ ) . thenReturn ( of ( true ) ) ;
42
- when ( mockTrainingDataQuery . remoteChanges$ ) . thenReturn ( of ( ) ) ;
43
- when ( mockTrainingDataQuery . remoteDocChanges$ ) . thenReturn ( of ( ) ) ;
44
34
when ( mockActivatedProjectService . projectId ) . thenReturn ( 'project01' ) ;
45
35
46
36
configureTestingModule ( ( ) => ( {
@@ -50,7 +40,6 @@ describe('DraftGenerationStepsComponent', () => {
50
40
{ provide : DraftSourcesService , useMock : mockDraftSourceService } ,
51
41
{ provide : FeatureFlagService , useMock : mockFeatureFlagService } ,
52
42
{ provide : NllbLanguageService , useMock : mockNllbLanguageService } ,
53
- { provide : TrainingDataService , useMock : mockTrainingDataService } ,
54
43
{ provide : ProgressService , useMock : mockProgressService } ,
55
44
{ provide : OnlineStatusService , useMock : mockOnlineStatusService } ,
56
45
{ provide : NoticeService , useMock : mockNoticeService } ,
@@ -127,10 +116,6 @@ describe('DraftGenerationStepsComponent', () => {
127
116
when ( mockActivatedProjectService . changes$ ) . thenReturn ( targetProjectDoc$ ) ;
128
117
when ( mockNllbLanguageService . isNllbLanguageAsync ( anything ( ) ) ) . thenResolve ( true ) ;
129
118
when ( mockNllbLanguageService . isNllbLanguageAsync ( 'xyz' ) ) . thenResolve ( false ) ;
130
- when ( mockTrainingDataService . queryTrainingDataAsync ( anything ( ) , anything ( ) ) ) . thenResolve (
131
- instance ( mockTrainingDataQuery )
132
- ) ;
133
- when ( mockTrainingDataQuery . docs ) . thenReturn ( [ ] ) ;
134
119
when ( mockFeatureFlagService . showDeveloperTools ) . thenReturn ( createTestFeatureFlag ( false ) ) ;
135
120
136
121
fixture = TestBed . createComponent ( DraftGenerationStepsComponent ) ;
@@ -408,10 +393,6 @@ describe('DraftGenerationStepsComponent', () => {
408
393
when ( mockFeatureFlagService . showDeveloperTools ) . thenReturn ( createTestFeatureFlag ( false ) ) ;
409
394
when ( mockNllbLanguageService . isNllbLanguageAsync ( anything ( ) ) ) . thenResolve ( true ) ;
410
395
when ( mockNllbLanguageService . isNllbLanguageAsync ( 'xyz' ) ) . thenResolve ( false ) ;
411
- when ( mockTrainingDataService . queryTrainingDataAsync ( anything ( ) , anything ( ) ) ) . thenResolve (
412
- instance ( mockTrainingDataQuery )
413
- ) ;
414
- when ( mockTrainingDataQuery . docs ) . thenReturn ( [ ] ) ;
415
396
416
397
fixture = TestBed . createComponent ( DraftGenerationStepsComponent ) ;
417
398
component = fixture . componentInstance ;
@@ -662,10 +643,6 @@ describe('DraftGenerationStepsComponent', () => {
662
643
when ( mockActivatedProjectService . changes$ ) . thenReturn ( of ( { } as any ) ) ;
663
644
when ( mockActivatedProjectService . projectDoc ) . thenReturn ( { } as any ) ;
664
645
when ( mockFeatureFlagService . showDeveloperTools ) . thenReturn ( createTestFeatureFlag ( true ) ) ;
665
- when ( mockTrainingDataService . queryTrainingDataAsync ( anything ( ) , anything ( ) ) ) . thenResolve (
666
- instance ( mockTrainingDataQuery )
667
- ) ;
668
- when ( mockTrainingDataQuery . docs ) . thenReturn ( [ ] ) ;
669
646
670
647
fixture = TestBed . createComponent ( DraftGenerationStepsComponent ) ;
671
648
component = fixture . componentInstance ;
@@ -799,10 +776,6 @@ describe('DraftGenerationStepsComponent', () => {
799
776
when ( mockDraftSourceService . getDraftProjectSources ( ) ) . thenReturn ( of ( config ) ) ;
800
777
when ( mockActivatedProjectService . projectDoc ) . thenReturn ( mockTargetProjectDoc ) ;
801
778
when ( mockActivatedProjectService . projectDoc$ ) . thenReturn ( of ( mockTargetProjectDoc ) ) ;
802
- when ( mockTrainingDataService . queryTrainingDataAsync ( anything ( ) , anything ( ) ) ) . thenResolve (
803
- instance ( mockTrainingDataQuery )
804
- ) ;
805
- when ( mockTrainingDataQuery . docs ) . thenReturn ( [ ] ) ;
806
779
807
780
fixture = TestBed . createComponent ( DraftGenerationStepsComponent ) ;
808
781
component = fixture . componentInstance ;
@@ -870,61 +843,26 @@ describe('DraftGenerationStepsComponent', () => {
870
843
texts : availableBooks ,
871
844
translateConfig : {
872
845
source : { projectRef : 'sourceProject' , shortName : 'sP1' , writingSystem : { tag : 'eng' } } ,
873
- draftConfig : { additionalTrainingData : true }
846
+ draftConfig : { additionalTrainingData : true , lastSelectedTrainingDataFiles : [ 'file1' ] }
874
847
} ,
875
848
writingSystem : { tag : 'nllb' }
876
849
} )
877
850
} as SFProjectProfileDoc ;
878
851
const targetProjectDoc$ = new BehaviorSubject < SFProjectProfileDoc > ( mockTargetProjectDoc ) ;
879
- const mockTrainingDataDoc = mock ( TrainingDataDoc ) ;
880
852
881
853
beforeEach ( fakeAsync ( ( ) => {
882
854
when ( mockDraftSourceService . getDraftProjectSources ( ) ) . thenReturn ( of ( config ) ) ;
883
855
when ( mockActivatedProjectService . projectDoc$ ) . thenReturn ( targetProjectDoc$ ) ;
884
856
when ( mockActivatedProjectService . changes$ ) . thenReturn ( targetProjectDoc$ ) ;
885
857
when ( mockActivatedProjectService . projectDoc ) . thenReturn ( mockTargetProjectDoc ) ;
886
858
when ( mockFeatureFlagService . showDeveloperTools ) . thenReturn ( createTestFeatureFlag ( false ) ) ;
887
- when ( mockTrainingDataService . queryTrainingDataAsync ( anything ( ) , anything ( ) ) ) . thenResolve (
888
- instance ( mockTrainingDataQuery )
889
- ) ;
890
- when ( mockTrainingDataQuery . docs ) . thenReturn ( [ mockTrainingDataDoc ] ) ;
891
859
892
860
fixture = TestBed . createComponent ( DraftGenerationStepsComponent ) ;
893
861
component = fixture . componentInstance ;
894
862
fixture . detectChanges ( ) ;
895
863
tick ( ) ;
896
864
} ) ) ;
897
865
898
- it ( 'should allow additional training data' , ( ) => {
899
- expect ( component . trainingDataFilesAvailable ) . toBe ( true ) ;
900
- expect ( component . availableTrainingFiles . length ) . toBe ( 1 ) ;
901
- } ) ;
902
-
903
- it ( 'updates available training data file after uploaded or deleted' , ( ) => {
904
- fixture . detectChanges ( ) ;
905
- component . tryAdvanceStep ( ) ;
906
- fixture . detectChanges ( ) ;
907
- component . onTranslateBookSelect ( [ 3 ] , config . draftingSources [ 0 ] ) ;
908
- fixture . detectChanges ( ) ;
909
- component . tryAdvanceStep ( ) ;
910
- component . onTranslatedBookSelect ( [ 2 ] ) ;
911
- fixture . detectChanges ( ) ;
912
- component . tryAdvanceStep ( ) ;
913
- expect ( component . availableTrainingFiles . length ) . toEqual ( 1 ) ;
914
-
915
- // Delete a training data file
916
- when ( mockTrainingDataQuery . docs ) . thenReturn ( [ ] ) ;
917
- trainingDataQueryLocalChanges$ . next ( ) ;
918
- fixture . detectChanges ( ) ;
919
- expect ( component . availableTrainingFiles . length ) . toEqual ( 0 ) ;
920
-
921
- // Upload a training data file
922
- when ( mockTrainingDataQuery . docs ) . thenReturn ( [ mockTrainingDataDoc ] ) ;
923
- trainingDataQueryLocalChanges$ . next ( ) ;
924
- fixture . detectChanges ( ) ;
925
- expect ( component . availableTrainingFiles . length ) . toEqual ( 1 ) ;
926
- } ) ;
927
-
928
866
it ( 'generates draft with training data file' , ( ) => {
929
867
fixture . detectChanges ( ) ;
930
868
component . tryAdvanceStep ( ) ;
@@ -935,13 +873,7 @@ describe('DraftGenerationStepsComponent', () => {
935
873
component . onTranslatedBookSelect ( [ 2 ] ) ;
936
874
fixture . detectChanges ( ) ;
937
875
component . tryAdvanceStep ( ) ;
938
- expect ( component . availableTrainingFiles . length ) . toEqual ( 1 ) ;
939
- expect ( component . selectedTrainingFileIds ) . toEqual ( [ ] ) ;
940
876
941
- const fileIds = [ 'file1' ] ;
942
- component . onTrainingDataSelect ( fileIds ) ;
943
- fixture . detectChanges ( ) ;
944
- expect ( component . selectedTrainingFileIds ) . toEqual ( fileIds ) ;
945
877
spyOn ( component . done , 'emit' ) ;
946
878
component . tryAdvanceStep ( ) ;
947
879
fixture . detectChanges ( ) ;
@@ -950,7 +882,7 @@ describe('DraftGenerationStepsComponent', () => {
950
882
expect ( component . done . emit ) . toHaveBeenCalledWith ( {
951
883
trainingScriptureRanges : [ { projectId : 'source1' , scriptureRange : 'EXO' } ] ,
952
884
translationScriptureRanges : [ { projectId : 'draftingSource' , scriptureRange : 'LEV' } ] ,
953
- trainingDataFiles : fileIds ,
885
+ trainingDataFiles : [ 'file1' ] ,
954
886
fastTraining : false ,
955
887
useEcho : false
956
888
} ) ;
@@ -1021,10 +953,6 @@ describe('DraftGenerationStepsComponent', () => {
1021
953
when ( mockActivatedProjectService . projectDoc$ ) . thenReturn (
1022
954
new BehaviorSubject < SFProjectProfileDoc > ( mockTargetProjectDoc )
1023
955
) ;
1024
- when ( mockTrainingDataService . queryTrainingDataAsync ( anything ( ) , anything ( ) ) ) . thenResolve (
1025
- instance ( mockTrainingDataQuery )
1026
- ) ;
1027
- when ( mockTrainingDataQuery . docs ) . thenReturn ( [ ] ) ;
1028
956
when ( mockFeatureFlagService . showDeveloperTools ) . thenReturn ( createTestFeatureFlag ( false ) ) ;
1029
957
1030
958
fixture = TestBed . createComponent ( DraftGenerationStepsComponent ) ;
0 commit comments