refactor(ivy): simplify walkTNodeTree
method for readability (#31065)
PR Close #31065
This commit is contained in:

committed by
Andrew Kushnir

parent
4bbf16e654
commit
994264c0ba
@ -770,7 +770,7 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => {
|
||||
@Component({
|
||||
selector: 'my-app',
|
||||
template: `
|
||||
<my-cmp i18n="test">{
|
||||
<my-cmp i18n="test" *ngIf="condition">{
|
||||
count,
|
||||
plural,
|
||||
=1 {ONE}
|
||||
@ -780,6 +780,7 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => {
|
||||
})
|
||||
class App {
|
||||
count = 1;
|
||||
condition = true;
|
||||
}
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
@ -788,25 +789,40 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => {
|
||||
const fixture = TestBed.createComponent(App);
|
||||
fixture.detectChanges();
|
||||
expect(fixture.debugElement.nativeElement.innerHTML)
|
||||
.toBe('<my-cmp><div>ONE<!--ICU 13--></div><!--container--></my-cmp>');
|
||||
.toContain('<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>');
|
||||
.toContain('<my-cmp><div>OTHER<!--ICU 13--></div><!--container--></my-cmp>');
|
||||
|
||||
// destroy component
|
||||
fixture.componentInstance.condition = false;
|
||||
fixture.detectChanges();
|
||||
expect(fixture.debugElement.nativeElement.textContent).toBe('');
|
||||
|
||||
// render it again and also change ICU case
|
||||
fixture.componentInstance.condition = true;
|
||||
fixture.componentInstance.count = 1;
|
||||
fixture.detectChanges();
|
||||
expect(fixture.debugElement.nativeElement.innerHTML)
|
||||
.toContain('<my-cmp><div>ONE<!--ICU 13--></div><!--container--></my-cmp>');
|
||||
});
|
||||
|
||||
it('with nested ICU expression and inside a container when creating a view via vcr.createEmbeddedView',
|
||||
() => {
|
||||
let dir: Dir|null = null;
|
||||
@Directive({
|
||||
selector: '[someDir]',
|
||||
})
|
||||
class Dir {
|
||||
constructor(
|
||||
private readonly viewContainerRef: ViewContainerRef,
|
||||
private readonly templateRef: TemplateRef<any>) {}
|
||||
private readonly templateRef: TemplateRef<any>) {
|
||||
dir = this;
|
||||
}
|
||||
|
||||
ngOnInit() { this.viewContainerRef.createEmbeddedView(this.templateRef); }
|
||||
attachEmbeddedView() { this.viewContainerRef.createEmbeddedView(this.templateRef); }
|
||||
}
|
||||
|
||||
@Component({
|
||||
@ -845,6 +861,11 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => {
|
||||
const fixture = TestBed.createComponent(App);
|
||||
fixture.componentRef.instance.count = 2;
|
||||
fixture.detectChanges();
|
||||
expect(fixture.debugElement.nativeElement.innerHTML)
|
||||
.toBe('<my-cmp><!--container--></my-cmp>');
|
||||
|
||||
dir !.attachEmbeddedView();
|
||||
fixture.detectChanges();
|
||||
expect(fixture.debugElement.nativeElement.innerHTML)
|
||||
.toBe(
|
||||
'<my-cmp><div>2 animals<!--nested ICU 0-->!<!--ICU 15--></div><!--container--></my-cmp>');
|
||||
@ -1520,6 +1541,51 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement.innerHTML).toEqual(`<child><div>Contenu enfant</div></child>`);
|
||||
});
|
||||
|
||||
it('should display/destroy projected i18n content', () => {
|
||||
|
||||
@Component({
|
||||
selector: 'app',
|
||||
template: `
|
||||
<ng-container>(<ng-content></ng-content>)</ng-container>
|
||||
`
|
||||
})
|
||||
class MyContentApp {
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'my-app',
|
||||
template: `
|
||||
<app i18n *ngIf="condition">{type, select, A {A} B {B} other {other}}</app>
|
||||
`
|
||||
})
|
||||
class MyApp {
|
||||
type = 'A';
|
||||
condition = true;
|
||||
}
|
||||
|
||||
TestBed.configureTestingModule({declarations: [MyApp, MyContentApp]});
|
||||
|
||||
const fixture = TestBed.createComponent(MyApp);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(fixture.nativeElement.textContent).toContain('(A)');
|
||||
|
||||
// change `condition` to remove <app>
|
||||
fixture.componentInstance.condition = false;
|
||||
fixture.detectChanges();
|
||||
|
||||
// should not contain 'A'
|
||||
expect(fixture.nativeElement.textContent).toBe('');
|
||||
|
||||
// display <app> again
|
||||
fixture.componentInstance.type = 'B';
|
||||
fixture.componentInstance.condition = true;
|
||||
fixture.detectChanges();
|
||||
|
||||
// expect that 'B' is now displayed
|
||||
expect(fixture.nativeElement.textContent).toContain('(B)');
|
||||
});
|
||||
});
|
||||
|
||||
describe('queries', () => {
|
||||
|
@ -149,9 +149,6 @@
|
||||
{
|
||||
"name": "__self"
|
||||
},
|
||||
{
|
||||
"name": "__values"
|
||||
},
|
||||
{
|
||||
"name": "__window"
|
||||
},
|
||||
@ -317,9 +314,6 @@
|
||||
{
|
||||
"name": "getElementDepthCount"
|
||||
},
|
||||
{
|
||||
"name": "getHighestElementOrICUContainer"
|
||||
},
|
||||
{
|
||||
"name": "getHostNative"
|
||||
},
|
||||
|
@ -131,9 +131,6 @@
|
||||
{
|
||||
"name": "__self"
|
||||
},
|
||||
{
|
||||
"name": "__values"
|
||||
},
|
||||
{
|
||||
"name": "__window"
|
||||
},
|
||||
@ -254,9 +251,6 @@
|
||||
{
|
||||
"name": "getDirectiveDef"
|
||||
},
|
||||
{
|
||||
"name": "getHighestElementOrICUContainer"
|
||||
},
|
||||
{
|
||||
"name": "getHostNative"
|
||||
},
|
||||
|
@ -317,9 +317,6 @@
|
||||
{
|
||||
"name": "__spread"
|
||||
},
|
||||
{
|
||||
"name": "__values"
|
||||
},
|
||||
{
|
||||
"name": "__window"
|
||||
},
|
||||
@ -464,9 +461,24 @@
|
||||
{
|
||||
"name": "appendChild"
|
||||
},
|
||||
{
|
||||
"name": "applyContainer"
|
||||
},
|
||||
{
|
||||
"name": "applyNodes"
|
||||
},
|
||||
{
|
||||
"name": "applyProjectionRecursive"
|
||||
},
|
||||
{
|
||||
"name": "applyStyling"
|
||||
},
|
||||
{
|
||||
"name": "applyToElementOrContainer"
|
||||
},
|
||||
{
|
||||
"name": "applyView"
|
||||
},
|
||||
{
|
||||
"name": "assertTemplate"
|
||||
},
|
||||
@ -620,24 +632,6 @@
|
||||
{
|
||||
"name": "enterView"
|
||||
},
|
||||
{
|
||||
"name": "executeActionOnContainer"
|
||||
},
|
||||
{
|
||||
"name": "executeActionOnElementContainerOrIcuContainer"
|
||||
},
|
||||
{
|
||||
"name": "executeActionOnElementOrContainer"
|
||||
},
|
||||
{
|
||||
"name": "executeActionOnNode"
|
||||
},
|
||||
{
|
||||
"name": "executeActionOnProjection"
|
||||
},
|
||||
{
|
||||
"name": "executeActionOnView"
|
||||
},
|
||||
{
|
||||
"name": "executeContentQueries"
|
||||
},
|
||||
@ -773,9 +767,6 @@
|
||||
{
|
||||
"name": "getGuardMask"
|
||||
},
|
||||
{
|
||||
"name": "getHighestElementOrICUContainer"
|
||||
},
|
||||
{
|
||||
"name": "getHostNative"
|
||||
},
|
||||
|
Reference in New Issue
Block a user