test(compiler): add additional i18n serialization tests (#38484)

The addiational tests check that ICUs containing interpolations
are serialized correctly.

PR Close #38484
This commit is contained in:
Pete Bacon Darwin 2020-08-14 12:20:32 +01:00 committed by Andrew Scott
parent cb05c0102f
commit be96510ce9
1 changed files with 28 additions and 2 deletions

View File

@ -415,7 +415,7 @@ describe('serializeI18nMessageForLocalize', () => {
}); });
it('should serialize ICU with nested HTML for `$localize()`', () => { it('should serialize ICU with embedded HTML for `$localize()`', () => {
expect(serialize('{age, plural, 10 {<b>ten</b>} other {<div class="A">other</div>}}')).toEqual({ expect(serialize('{age, plural, 10 {<b>ten</b>} other {<div class="A">other</div>}}')).toEqual({
messageParts: [ messageParts: [
'{VAR_PLURAL, plural, 10 {{START_BOLD_TEXT}ten{CLOSE_BOLD_TEXT}} other {{START_TAG_DIV}other{CLOSE_TAG_DIV}}}' '{VAR_PLURAL, plural, 10 {{START_BOLD_TEXT}ten{CLOSE_BOLD_TEXT}} other {{START_TAG_DIV}other{CLOSE_TAG_DIV}}}'
@ -424,6 +424,15 @@ describe('serializeI18nMessageForLocalize', () => {
}); });
}); });
it('should serialize ICU with embedded interpolation for `$localize()`', () => {
expect(serialize('{age, plural, 10 {<b>ten</b>} other {{{age}} years old}}')).toEqual({
messageParts: [
'{VAR_PLURAL, plural, 10 {{START_BOLD_TEXT}ten{CLOSE_BOLD_TEXT}} other {{INTERPOLATION} years old}}'
],
placeHolders: []
});
});
it('should serialize ICU with nested HTML containing further ICUs for `$localize()`', () => { it('should serialize ICU with nested HTML containing further ICUs for `$localize()`', () => {
expect( expect(
serialize( serialize(
@ -433,6 +442,18 @@ describe('serializeI18nMessageForLocalize', () => {
placeHolders: ['ICU', 'START_TAG_DIV', 'ICU', 'CLOSE_TAG_DIV'] placeHolders: ['ICU', 'START_TAG_DIV', 'ICU', 'CLOSE_TAG_DIV']
}); });
}); });
it('should serialize nested ICUs with embedded interpolation for `$localize()`', () => {
expect(
serialize(
'{age, plural, 10 {ten {size, select, 1 {{{ varOne }}} 2 {{{ varTwo }}} other {2+}}} other {other}}'))
.toEqual({
messageParts: [
'{VAR_PLURAL, plural, 10 {ten {VAR_SELECT, select, 1 {{INTERPOLATION}} 2 {{INTERPOLATION_1}} other {2+}}} other {other}}'
],
placeHolders: []
});
});
}); });
describe('serializeIcuNode', () => { describe('serializeIcuNode', () => {
@ -447,7 +468,7 @@ describe('serializeIcuNode', () => {
.toEqual('{VAR_PLURAL, plural, 10 {ten} other {other}}'); .toEqual('{VAR_PLURAL, plural, 10 {ten} other {other}}');
}); });
it('should serialize a next ICU', () => { it('should serialize a nested ICU', () => {
expect(serialize( expect(serialize(
'{age, plural, 10 {ten {size, select, 1 {one} 2 {two} other {2+}}} other {other}}')) '{age, plural, 10 {ten {size, select, 1 {one} 2 {two} other {2+}}} other {other}}'))
.toEqual( .toEqual(
@ -459,4 +480,9 @@ describe('serializeIcuNode', () => {
.toEqual( .toEqual(
'{VAR_PLURAL, plural, 10 {{START_BOLD_TEXT}ten{CLOSE_BOLD_TEXT}} other {{START_TAG_DIV}other{CLOSE_TAG_DIV}}}'); '{VAR_PLURAL, plural, 10 {{START_BOLD_TEXT}ten{CLOSE_BOLD_TEXT}} other {{START_TAG_DIV}other{CLOSE_TAG_DIV}}}');
}); });
it('should serialize an ICU with embedded interpolations', () => {
expect(serialize('{age, select, 10 {ten} other {{{age}} years old}}'))
.toEqual('{VAR_SELECT, select, 10 {ten} other {{INTERPOLATION} years old}}');
});
}); });