@@ -6,18 +6,33 @@ import {
66} from '@angular/core/testing' ;
77import { ActivatedRoute } from '@angular/router' ;
88import { TranslateModule } from '@ngx-translate/core' ;
9+ import { of } from 'rxjs' ;
910
11+ import { SiteDataService } from '../../../core/data/site-data.service' ;
12+ import { LocaleService } from '../../../core/locale/locale.service' ;
1013import { ActivatedRouteStub } from '../../../shared/testing/active-router.stub' ;
1114import { PrivacyContentComponent } from './privacy-content.component' ;
1215
1316describe ( 'PrivacyContentComponent' , ( ) => {
1417 let component : PrivacyContentComponent ;
1518 let fixture : ComponentFixture < PrivacyContentComponent > ;
19+ let siteServiceSpy : jasmine . SpyObj < SiteDataService > ;
20+ let localeServiceSpy : jasmine . SpyObj < LocaleService > ;
1621
1722 beforeEach ( waitForAsync ( ( ) => {
23+ siteServiceSpy = jasmine . createSpyObj ( 'SiteDataService' , [ 'find' ] ) ;
24+ localeServiceSpy = jasmine . createSpyObj ( 'LocaleService' , [ 'getCurrentLanguageCode' ] ) ;
25+
26+ siteServiceSpy . find . and . returnValue ( of ( { metadataAsList : [ ] } as any ) ) ;
27+ localeServiceSpy . getCurrentLanguageCode . and . returnValue ( 'en' ) ;
28+
1829 TestBed . configureTestingModule ( {
1930 imports : [ TranslateModule . forRoot ( ) , PrivacyContentComponent ] ,
20- providers : [ { provide : ActivatedRoute , useValue : new ActivatedRouteStub ( ) } ] ,
31+ providers : [
32+ { provide : ActivatedRoute , useValue : new ActivatedRouteStub ( ) } ,
33+ { provide : SiteDataService , useValue : siteServiceSpy } ,
34+ { provide : LocaleService , useValue : localeServiceSpy } ,
35+ ] ,
2136 schemas : [ NO_ERRORS_SCHEMA ] ,
2237 } ) . compileComponents ( ) ;
2338 } ) ) ;
@@ -31,4 +46,41 @@ describe('PrivacyContentComponent', () => {
3146 it ( 'should create' , ( ) => {
3247 expect ( component ) . toBeTruthy ( ) ;
3348 } ) ;
49+
50+ it ( 'should use fallback language when current language is not available' , ( done ) => {
51+ const mockSite = {
52+ metadataAsList : [
53+ { key : 'cris.cms.privacy-policy' , language : 'en' , value : 'Privacy policy in english' } ,
54+ ] ,
55+ } ;
56+
57+ siteServiceSpy . find . and . returnValue ( of ( mockSite as any ) ) ;
58+ localeServiceSpy . getCurrentLanguageCode . and . returnValue ( 'it' ) ;
59+
60+ component . ngOnInit ( ) ;
61+
62+ component . privacyPolicyText$ . subscribe ( ( value ) => {
63+ expect ( value ) . toBe ( 'Privacy policy in english' ) ;
64+ done ( ) ;
65+ } ) ;
66+ } ) ;
67+
68+ it ( 'should use current language when available' , ( done ) => {
69+ const mockSite = {
70+ metadataAsList : [
71+ { key : 'cris.cms.privacy-policy' , language : 'en' , value : 'Privacy policy in english' } ,
72+ { key : 'cris.cms.privacy-policy' , language : 'it' , value : 'Privacy policy in italiano' } ,
73+ ] ,
74+ } ;
75+
76+ siteServiceSpy . find . and . returnValue ( of ( mockSite as any ) ) ;
77+ localeServiceSpy . getCurrentLanguageCode . and . returnValue ( 'it' ) ;
78+
79+ component . ngOnInit ( ) ;
80+
81+ component . privacyPolicyText$ . subscribe ( ( value ) => {
82+ expect ( value ) . toBe ( 'Privacy policy in italiano' ) ;
83+ done ( ) ;
84+ } ) ;
85+ } ) ;
3486} ) ;
0 commit comments