@@ -1094,6 +1094,110 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => {
1094
1094
fixture . detectChanges ( ) ;
1095
1095
expect ( fixture . debugElement . nativeElement . innerHTML ) . toContain ( 'plus d\'un' ) ;
1096
1096
} ) ;
1097
+
1098
+ it ( 'should support ICUs without "other" cases' , ( ) => {
1099
+ loadTranslations ( {
1100
+ idA : '{VAR_SELECT, select, 1 {un (select)} 2 {deux (select)}}' ,
1101
+ idB : '{VAR_PLURAL, plural, =1 {un (plural)} =2 {deux (plural)}}' ,
1102
+ } ) ;
1103
+
1104
+ @Component ( {
1105
+ selector : 'app' ,
1106
+ template : `
1107
+ <div i18n="@@idA">{count, select, 1 {one (select)} 2 {two (select)}}</div> -
1108
+ <div i18n="@@idB">{count, plural, =1 {one (plural)} =2 {two (plural)}}</div>
1109
+ `
1110
+ } )
1111
+ class AppComponent {
1112
+ count = 1 ;
1113
+ }
1114
+
1115
+ TestBed . configureTestingModule ( { declarations : [ AppComponent ] } ) ;
1116
+
1117
+ const fixture = TestBed . createComponent ( AppComponent ) ;
1118
+ fixture . detectChanges ( ) ;
1119
+ expect ( fixture . nativeElement . textContent ) . toBe ( 'un (select) - un (plural)' ) ;
1120
+
1121
+ fixture . componentInstance . count = 3 ;
1122
+ fixture . detectChanges ( ) ;
1123
+ // there is no ICU case for count=3
1124
+ expect ( fixture . nativeElement . textContent . trim ( ) ) . toBe ( '-' ) ;
1125
+
1126
+ fixture . componentInstance . count = 4 ;
1127
+ fixture . detectChanges ( ) ;
1128
+ // there is no ICU case for count=4, making sure content is still empty
1129
+ expect ( fixture . nativeElement . textContent . trim ( ) ) . toBe ( '-' ) ;
1130
+
1131
+ fixture . componentInstance . count = 2 ;
1132
+ fixture . detectChanges ( ) ;
1133
+ // check switching to an existing case after processing an ICU without matching case
1134
+ expect ( fixture . nativeElement . textContent . trim ( ) ) . toBe ( 'deux (select) - deux (plural)' ) ;
1135
+
1136
+ fixture . componentInstance . count = 1 ;
1137
+ fixture . detectChanges ( ) ;
1138
+ // check that we can go back to the first ICU case
1139
+ expect ( fixture . nativeElement . textContent ) . toBe ( 'un (select) - un (plural)' ) ;
1140
+ } ) ;
1141
+
1142
+ it ( 'should support nested ICUs without "other" cases' , ( ) => {
1143
+ loadTranslations ( {
1144
+ idA : '{VAR_SELECT_1, select, A {{VAR_SELECT, select, ' +
1145
+ '1 {un (select)} 2 {deux (select)}}} other {}}' ,
1146
+ idB : '{VAR_SELECT, select, A {{VAR_PLURAL, plural, ' +
1147
+ '=1 {un (plural)} =2 {deux (plural)}}} other {}}' ,
1148
+ } ) ;
1149
+
1150
+ @Component ( {
1151
+ selector : 'app' ,
1152
+ template : `
1153
+ <div i18n="@@idA">{
1154
+ type, select,
1155
+ A {{count, select, 1 {one (select)} 2 {two (select)}}}
1156
+ other {}
1157
+ }</div> -
1158
+ <div i18n="@@idB">{
1159
+ type, select,
1160
+ A {{count, plural, =1 {one (plural)} =2 {two (plural)}}}
1161
+ other {}
1162
+ }</div>
1163
+ `
1164
+ } )
1165
+ class AppComponent {
1166
+ type = 'A' ;
1167
+ count = 1 ;
1168
+ }
1169
+
1170
+ TestBed . configureTestingModule ( { declarations : [ AppComponent ] } ) ;
1171
+
1172
+ const fixture = TestBed . createComponent ( AppComponent ) ;
1173
+ fixture . detectChanges ( ) ;
1174
+ expect ( fixture . nativeElement . textContent ) . toBe ( 'un (select) - un (plural)' ) ;
1175
+
1176
+ fixture . componentInstance . count = 3 ;
1177
+ fixture . detectChanges ( ) ;
1178
+ // there is no case for count=3 in nested ICU
1179
+ expect ( fixture . nativeElement . textContent . trim ( ) ) . toBe ( '-' ) ;
1180
+
1181
+ fixture . componentInstance . count = 4 ;
1182
+ fixture . detectChanges ( ) ;
1183
+ // there is no case for count=4 in nested ICU, making sure content is still empty
1184
+ expect ( fixture . nativeElement . textContent . trim ( ) ) . toBe ( '-' ) ;
1185
+
1186
+ fixture . componentInstance . count = 2 ;
1187
+ fixture . detectChanges ( ) ;
1188
+ // check switching to an existing case after processing nested ICU without matching case
1189
+ expect ( fixture . nativeElement . textContent . trim ( ) ) . toBe ( 'deux (select) - deux (plural)' ) ;
1190
+
1191
+ fixture . componentInstance . count = 1 ;
1192
+ fixture . detectChanges ( ) ;
1193
+ // check that we can go back to the first case in nested ICU
1194
+ expect ( fixture . nativeElement . textContent ) . toBe ( 'un (select) - un (plural)' ) ;
1195
+
1196
+ fixture . componentInstance . type = 'B' ;
1197
+ fixture . detectChanges ( ) ;
1198
+ // check that nested ICU is removed if root ICU case has changed
1199
+ expect ( fixture . nativeElement . textContent . trim ( ) ) . toBe ( '-' ) ;
1200
+ } ) ;
1097
1201
} ) ;
1098
1202
1099
1203
describe ( 'should support attributes' , ( ) => {
0 commit comments