@@ -25,6 +25,10 @@ class TestVVTranslateParserComponent {
2525
2626describe ( 'VVTranslateParser' , ( ) => {
2727 let fixture : ComponentFixture < TestVVTranslateParserComponent > ;
28+ let compiler : TranslateFormatJsCompiler ;
29+ const SELECT_TEXT = 'Ich wohne in einem {text, select, A {Haus} B {Hotel} C {Keller} other {Garten}}.' ;
30+ const PLURAL_TEXT = 'Gib mir {num, plural, =0 {Kein} =1 {Ein} =2 {Zwei} other {mehr}} Bier' ;
31+ const HTML_TEXT = "'<h1>Headline</h1>'" ;
2832 beforeEach ( waitForAsync ( ( ) => {
2933 TestBed . configureTestingModule ( {
3034 declarations : [ TestVVTranslateParserComponent ] ,
@@ -34,14 +38,14 @@ describe('VVTranslateParser', () => {
3438 provide : TranslateLoader ,
3539 useValue : {
3640 getTranslation : ( ) => of ( {
37- TEST_SELECT :
38- 'Ich wohne in einem {text, select, A {Haus} B {Hotel} C {Keller} other {Garten}}.' ,
39- TEST_PLURAL :
40- 'Gib mir {num, plural, =0 {Kein} =1 {Ein} =2 {Zwei} other {mehr}} Bier' ,
41- DEEP : {
42- TEST : 'deep test' ,
41+ ...{
42+ TEST_SELECT : SELECT_TEXT ,
43+ TEST_PLURAL : PLURAL_TEXT ,
44+ DEEP : {
45+ TEST : 'deep test' ,
46+ } ,
47+ HTML : HTML_TEXT ,
4348 } ,
44- HTML : "'<h1>Headline</h1>'" ,
4549 } ) ,
4650 } ,
4751 } ,
@@ -53,53 +57,91 @@ describe('VVTranslateParser', () => {
5357 } ,
5458 } ) ,
5559 ] ,
60+ providers : [ TranslateFormatJsCompiler ] ,
5661 } ) . compileComponents ( ) ;
5762 fixture = TestBed . createComponent ( TestVVTranslateParserComponent ) ;
63+ compiler = TestBed . inject ( TranslateFormatJsCompiler ) ;
5864 fixture . detectChanges ( ) ;
5965 } ) ) ;
66+ describe ( 'should compileTranslations' , ( ) => {
67+ it . each `
68+ text | translation
69+ ${ 'A' } | ${ 'Ich wohne in einem Haus.' }
70+ ${ 'B' } | ${ 'Ich wohne in einem Hotel.' }
71+ ${ 'C' } | ${ 'Ich wohne in einem Keller.' }
72+ ${ 'D' } | ${ 'Ich wohne in einem Garten.' }
73+ ${ 'E' } | ${ 'Ich wohne in einem Garten.' }
74+ ` (
75+ 'should translate select correctly with $text' ,
76+ ( { text, translation } ) => {
77+ fixture . componentInstance . text = text ;
78+ fixture . detectChanges ( ) ;
6079
61- it . each `
62- text | translation
63- ${ 'A' } | ${ 'Ich wohne in einem Haus.' }
64- ${ 'B' } | ${ 'Ich wohne in einem Hotel.' }
65- ${ 'C' } | ${ 'Ich wohne in einem Keller.' }
66- ${ 'D' } | ${ 'Ich wohne in einem Garten.' }
67- ${ 'E' } | ${ 'Ich wohne in einem Garten.' }
68- ` ( 'should translate select correctly with $text' , ( { text, translation } ) => {
69- fixture . componentInstance . text = text ;
70- fixture . detectChanges ( ) ;
80+ expect (
81+ fixture . debugElement . nativeElement . querySelector ( '#select' )
82+ . textContent ,
83+ ) . toBe ( translation ) ;
84+ } ,
85+ ) ;
7186
72- expect (
73- fixture . debugElement . nativeElement . querySelector ( '#select' ) . textContent ,
74- ) . toBe ( translation ) ;
75- } ) ;
87+ it . each `
88+ num | translation
89+ ${ 0 } | ${ 'Gib mir Kein Bier' }
90+ ${ 1 } | ${ 'Gib mir Ein Bier' }
91+ ${ 2 } | ${ 'Gib mir Zwei Bier' }
92+ ${ 3 } | ${ 'Gib mir mehr Bier' }
93+ ${ 4 } | ${ 'Gib mir mehr Bier' }
94+ ` ( 'should translate plural correctly with $num' , ( { num, translation } ) => {
95+ fixture . componentInstance . num = num ;
96+ fixture . detectChanges ( ) ;
7697
77- it . each `
78- num | translation
79- ${ 0 } | ${ 'Gib mir Kein Bier' }
80- ${ 1 } | ${ 'Gib mir Ein Bier' }
81- ${ 2 } | ${ 'Gib mir Zwei Bier' }
82- ${ 3 } | ${ 'Gib mir mehr Bier' }
83- ${ 4 } | ${ 'Gib mir mehr Bier' }
84- ` ( 'should translate plural correctly with $num' , ( { num, translation } ) => {
85- fixture . componentInstance . num = num ;
86- fixture . detectChanges ( ) ;
98+ expect (
99+ fixture . debugElement . nativeElement . querySelector ( '#plural' ) . textContent ,
100+ ) . toBe ( translation ) ;
101+ } ) ;
87102
88- expect (
89- fixture . debugElement . nativeElement . querySelector ( '#plural' ) . textContent ,
90- ) . toBe ( translation ) ;
91- } ) ;
103+ it ( 'should support deep' , ( ) => {
104+ expect (
105+ fixture . debugElement . nativeElement . querySelector ( '#deep' ) . textContent ,
106+ ) . toBe ( 'deep test' ) ;
107+ } ) ;
92108
93- it ( 'should support deep' , ( ) => {
94- expect (
95- fixture . debugElement . nativeElement . querySelector ( '#deep' ) . textContent ,
96- ) . toBe ( 'deep test' ) ;
109+ it ( 'should support html' , ( ) => {
110+ expect (
111+ fixture . debugElement . nativeElement . querySelector ( '#html > h1' )
112+ . textContent ,
113+ ) . toBe ( 'Headline' ) ;
114+ } ) ;
97115 } ) ;
98116
99- it ( 'should support html' , ( ) => {
100- expect (
101- fixture . debugElement . nativeElement . querySelector ( '#html > h1' )
102- . textContent ,
103- ) . toBe ( 'Headline' ) ;
117+ describe ( 'should compile' , ( ) => {
118+ it . each `
119+ text | translation
120+ ${ 'A' } | ${ 'Ich wohne in einem Haus.' }
121+ ${ 'B' } | ${ 'Ich wohne in einem Hotel.' }
122+ ${ 'C' } | ${ 'Ich wohne in einem Keller.' }
123+ ${ 'D' } | ${ 'Ich wohne in einem Garten.' }
124+ ${ 'E' } | ${ 'Ich wohne in einem Garten.' }
125+ ` (
126+ 'should translate select correctly with $text' ,
127+ ( { text, translation } ) => {
128+ expect ( ( compiler . compile ( SELECT_TEXT , 'de' ) as any ) ( { text } ) ) . toBe (
129+ translation ,
130+ ) ;
131+ } ,
132+ ) ;
133+
134+ it . each `
135+ num | translation
136+ ${ 0 } | ${ 'Gib mir Kein Bier' }
137+ ${ 1 } | ${ 'Gib mir Ein Bier' }
138+ ${ 2 } | ${ 'Gib mir Zwei Bier' }
139+ ${ 3 } | ${ 'Gib mir mehr Bier' }
140+ ${ 4 } | ${ 'Gib mir mehr Bier' }
141+ ` ( 'should translate plural correctly with $num' , ( { num, translation } ) => {
142+ expect ( ( compiler . compile ( PLURAL_TEXT , 'de' ) as any ) ( { num } ) ) . toBe (
143+ translation ,
144+ ) ;
145+ } ) ;
104146 } ) ;
105147} ) ;
0 commit comments