fix(ivy): reprojected ICU expression nodes when creating embedded views (#30979)
When using `createEmbeddedView` after the creation of an ICU expression, the nodes for the current selected case were not reprojected (only the anchor comment node was moved to the new location). Now we reproject correctly all the child nodes of an ICU expression when an anchor comment node is projected. FW-1372 #resolve PR Close #30979
This commit is contained in:

committed by
Andrew Kushnir

parent
57c4788bc7
commit
65544ac742
@ -661,6 +661,117 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => {
|
||||
const element = fixture.nativeElement;
|
||||
expect(element).toHaveText('other');
|
||||
});
|
||||
|
||||
it('inside a container when creating a view via vcr.createEmbeddedView', () => {
|
||||
@Directive({
|
||||
selector: '[someDir]',
|
||||
})
|
||||
class Dir {
|
||||
constructor(
|
||||
private readonly viewContainerRef: ViewContainerRef,
|
||||
private readonly templateRef: TemplateRef<any>) {}
|
||||
|
||||
ngOnInit() { this.viewContainerRef.createEmbeddedView(this.templateRef); }
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'my-cmp',
|
||||
template: `
|
||||
<div *someDir>
|
||||
<ng-content></ng-content>
|
||||
</div>
|
||||
`,
|
||||
})
|
||||
class Cmp {
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'my-app',
|
||||
template: `
|
||||
<my-cmp i18n="test">{
|
||||
count,
|
||||
plural,
|
||||
=1 {ONE}
|
||||
other {OTHER}
|
||||
}</my-cmp>
|
||||
`,
|
||||
})
|
||||
class App {
|
||||
count = 1;
|
||||
}
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [App, Cmp, Dir],
|
||||
});
|
||||
const fixture = TestBed.createComponent(App);
|
||||
fixture.detectChanges();
|
||||
expect(fixture.debugElement.nativeElement.innerHTML)
|
||||
.toBe('<my-cmp><div>ONE<!--ICU 13--></div><!--container--></my-cmp>');
|
||||
|
||||
fixture.componentRef.instance.count = 2;
|
||||
fixture.detectChanges();
|
||||
expect(fixture.debugElement.nativeElement.innerHTML)
|
||||
.toBe('<my-cmp><div>OTHER<!--ICU 13--></div><!--container--></my-cmp>');
|
||||
});
|
||||
|
||||
it('with nested ICU expression and inside a container when creating a view via vcr.createEmbeddedView',
|
||||
() => {
|
||||
@Directive({
|
||||
selector: '[someDir]',
|
||||
})
|
||||
class Dir {
|
||||
constructor(
|
||||
private readonly viewContainerRef: ViewContainerRef,
|
||||
private readonly templateRef: TemplateRef<any>) {}
|
||||
|
||||
ngOnInit() { this.viewContainerRef.createEmbeddedView(this.templateRef); }
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'my-cmp',
|
||||
template: `
|
||||
<div *someDir>
|
||||
<ng-content></ng-content>
|
||||
</div>
|
||||
`,
|
||||
})
|
||||
class Cmp {
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'my-app',
|
||||
template: `
|
||||
<my-cmp i18n="test">{
|
||||
count,
|
||||
plural,
|
||||
=1 {ONE}
|
||||
other {{{count}} {name, select,
|
||||
cat {cats}
|
||||
dog {dogs}
|
||||
other {animals}
|
||||
}!}
|
||||
}</my-cmp>
|
||||
`,
|
||||
})
|
||||
class App {
|
||||
count = 1;
|
||||
}
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [App, Cmp, Dir],
|
||||
});
|
||||
const fixture = TestBed.createComponent(App);
|
||||
fixture.componentRef.instance.count = 2;
|
||||
fixture.detectChanges();
|
||||
expect(fixture.debugElement.nativeElement.innerHTML)
|
||||
.toBe(
|
||||
'<my-cmp><div>2 animals<!--nested ICU 0-->!<!--ICU 15--></div><!--container--></my-cmp>');
|
||||
|
||||
fixture.componentRef.instance.count = 1;
|
||||
fixture.detectChanges();
|
||||
expect(fixture.debugElement.nativeElement.innerHTML)
|
||||
.toBe('<my-cmp><div>ONE<!--ICU 15--></div><!--container--></my-cmp>');
|
||||
});
|
||||
});
|
||||
|
||||
describe('should support attributes', () => {
|
||||
|
Reference in New Issue
Block a user