@@ -16,7 +16,10 @@ import {
1616 DynamicFormService ,
1717 DynamicInputModel ,
1818} from '@ng-dynamic-forms/core' ;
19- import { TranslateModule } from '@ngx-translate/core' ;
19+ import {
20+ TranslateModule ,
21+ TranslateService ,
22+ } from '@ngx-translate/core' ;
2023import { Operation } from 'fast-json-patch' ;
2124import { of as observableOf } from 'rxjs' ;
2225
@@ -28,6 +31,7 @@ import { Community } from '../../../../core/shared/community.model';
2831import { hasValue } from '../../../empty.util' ;
2932import { FormComponent } from '../../../form/form.component' ;
3033import { AuthServiceMock } from '../../../mocks/auth.service.mock' ;
34+ import { translateServiceStub } from '../../../mocks/translate.service.mock' ;
3135import { NotificationsService } from '../../../notifications/notifications.service' ;
3236import { createSuccessfulRemoteDataObject$ } from '../../../remote-data.utils' ;
3337import { NotificationsServiceStub } from '../../../testing/notifications-service.stub' ;
@@ -55,8 +59,8 @@ describe('ComColFormComponent', () => {
5559 const dcTitle = 'dc.title' ;
5660 const dcAbstract = 'dc.description.abstract' ;
5761
58- const abstractMD = { [ dcAbstract ] : [ { value : 'Community description' , language : null } ] } ;
59- const newTitleMD = { [ dcTitle ] : [ { value : 'New Community Title' , language : null } ] } ;
62+ const abstractMD = { [ dcAbstract ] : [ { value : 'Community description' , language : 'en_US' } ] } ;
63+ const newTitleMD = { [ dcTitle ] : [ { value : 'New Community Title' , language : 'en_US' } ] } ;
6064 const formModel = [
6165 new DynamicInputModel ( {
6266 id : 'title' ,
@@ -103,6 +107,7 @@ describe('ComColFormComponent', () => {
103107 { provide : AuthService , useValue : new AuthServiceMock ( ) } ,
104108 { provide : RequestService , useValue : requestServiceStub } ,
105109 { provide : ObjectCacheService , useValue : objectCacheStub } ,
110+ { provide : TranslateService , useValue : translateServiceStub } ,
106111 ] ,
107112 schemas : [ NO_ERRORS_SCHEMA ] ,
108113 } )
@@ -132,7 +137,7 @@ describe('ComColFormComponent', () => {
132137 describe ( 'onSubmit' , ( ) => {
133138 beforeEach ( ( ) => {
134139 spyOn ( comp . submitForm , 'emit' ) ;
135- comp . formModel = formModel ;
140+ comp . formModels . set ( 'en_US' , formModel ) ;
136141 } ) ;
137142
138143 it ( 'should emit the new version of the community' , ( ) => {
@@ -143,37 +148,38 @@ describe('ComColFormComponent', () => {
143148 {
144149 op : 'replace' ,
145150 path : '/metadata/dc.title' ,
146- value : {
151+ value : [ {
147152 value : 'New Community Title' ,
148- language : null ,
149- } ,
153+ language : 'en_US' ,
154+ } ] ,
150155 } ,
151156 {
152157 op : 'replace' ,
153158 path : '/metadata/dc.description.abstract' ,
154- value : {
159+ value : [ {
155160 value : 'Community description' ,
156- language : null ,
157- } ,
161+ language : 'en_US' ,
162+ } ] ,
158163 } ,
159164 ] ;
160165
166+ const expectedDso = Object . assign ( { } , comp . dso , {
167+ metadata : {
168+ 'dc.title' : [ {
169+ value : 'New Community Title' ,
170+ language : 'en_US' ,
171+ } ] ,
172+ 'dc.description.abstract' : [ {
173+ value : 'Community description' ,
174+ language : 'en_US' ,
175+ } ] ,
176+ } ,
177+ type : Community . type ,
178+ } ) ;
179+
161180 expect ( comp . submitForm . emit ) . toHaveBeenCalledWith (
162181 {
163- dso : Object . assign ( { } , comp . dso , {
164- metadata : {
165- 'dc.title' : [ {
166- value : 'New Community Title' ,
167- language : null ,
168- } ] ,
169- 'dc.description.abstract' : [ {
170- value : 'Community description' ,
171- language : null ,
172- } ] ,
173- } ,
174- type : Community . type ,
175- } ,
176- ) ,
182+ dso : expectedDso ,
177183 operations : operations ,
178184 } ,
179185 ) ;
@@ -314,8 +320,16 @@ describe('ComColFormComponent', () => {
314320 function initComponent ( dso : Community ) {
315321 fixture = TestBed . createComponent ( ComColFormComponent ) ;
316322 comp = fixture . componentInstance ;
317- comp . formModel = [ ] ;
323+ comp . formModels . set ( 'en_US' , formModel ) ;
324+ comp . defaultLanguageCode = 'en_US' ;
318325 comp . dso = dso ;
326+ comp . dso . firstMetadataValue = ( name , language ) => {
327+ if ( name === 'dc.title' ) {
328+ return newTitleMD [ dcTitle ] [ 0 ] . value ;
329+ } else if ( name === 'dc.description.abstract' ) {
330+ return abstractMD [ dcAbstract ] [ 0 ] . value ;
331+ }
332+ } ;
319333 ( comp as any ) . type = Community . type ;
320334 comp . uploaderComponent = { uploader : { } } as any ;
321335
0 commit comments