Skip to content

Commit

Permalink
test(ivy): add root cause analysis for the remaining projection test (a…
Browse files Browse the repository at this point in the history
…ngular#28152)

Initial thinking was that the bug is in the content projection logic but
it turned out to be a wrong assumption - hence adding a test to illustrate
that basic content projection of view containers works correctly.

What fails in the marked test is the logic quering debug nodes - content
peojection is fine but we never create the 'B' text node since we call
show() method on the "wrong" directive instance.

PR Close angular#28152
  • Loading branch information
pkozlowski-opensource authored and ngfelixl committed Jan 27, 2019
1 parent e26eeb1 commit 4f487a2
Showing 1 changed file with 55 additions and 29 deletions.
84 changes: 55 additions & 29 deletions packages/core/test/linker/projection_integration_spec.ts
Expand Up @@ -543,48 +543,74 @@ describe('projection', () => {
expect(main.nativeElement).toHaveText('B(A)');
});

fixmeIvy('unknown').it('should project filled view containers into a view container', () => {
it('should project view containers', () => {
TestBed.configureTestingModule(
{declarations: [ConditionalContentComponent, ManualViewportDirective]});
{declarations: [SingleContentTagComponent, ManualViewportDirective]});
TestBed.overrideComponent(MainComp, {
set: {
template: '<conditional-content>' +
'<div class="left">A</div>' +
'<ng-template manual class="left">B</ng-template>' +
'<div class="left">C</div>' +
'<div>D</div>' +
'</conditional-content>'
template: '<single-content-tag>' +
'<div class="target">A</div>' +
'<ng-template manual class="target">B</ng-template>' +
'<div class="target">C</div>' +
'</single-content-tag>'
}
});
const main = TestBed.createComponent(MainComp);

const conditionalComp = main.debugElement.query(By.directive(ConditionalContentComponent));

const viewViewportDir =
conditionalComp.queryAllNodes(By.directive(ManualViewportDirective))[0].injector.get(
const main = TestBed.createComponent(MainComp);
const manualDirective =
main.debugElement.queryAllNodes(By.directive(ManualViewportDirective))[0].injector.get(
ManualViewportDirective);

expect(main.nativeElement).toHaveText('(, D)');
expect(main.nativeElement).toHaveText('(, D)');
expect(main.nativeElement).toHaveText('AC');

viewViewportDir.show();
manualDirective.show();
main.detectChanges();
expect(main.nativeElement).toHaveText('(AC, D)');
expect(main.nativeElement).toHaveText('ABC');
});

const contentViewportDir =
conditionalComp.queryAllNodes(By.directive(ManualViewportDirective))[1].injector.get(
ManualViewportDirective);
fixmeIvy('FW-869: debugElement.queryAllNodes returns nodes in the wrong order')
.it('should project filled view containers into a view container', () => {
TestBed.configureTestingModule(
{declarations: [ConditionalContentComponent, ManualViewportDirective]});
TestBed.overrideComponent(MainComp, {
set: {
template: '<conditional-content>' +
'<div class="left">A</div>' +
'<ng-template manual class="left">B</ng-template>' +
'<div class="left">C</div>' +
'<div>D</div>' +
'</conditional-content>'
}
});
const main = TestBed.createComponent(MainComp);

contentViewportDir.show();
main.detectChanges();
expect(main.nativeElement).toHaveText('(ABC, D)');
const conditionalComp = main.debugElement.query(By.directive(ConditionalContentComponent));

// hide view viewport, and test that it also hides
// the content viewport's views
viewViewportDir.hide();
main.detectChanges();
expect(main.nativeElement).toHaveText('(, D)');
});
const viewViewportDir =
conditionalComp.queryAllNodes(By.directive(ManualViewportDirective))[0].injector.get(
ManualViewportDirective);

expect(main.nativeElement).toHaveText('(, D)');
expect(main.nativeElement).toHaveText('(, D)');

viewViewportDir.show();
main.detectChanges();
expect(main.nativeElement).toHaveText('(AC, D)');

const contentViewportDir =
conditionalComp.queryAllNodes(By.directive(ManualViewportDirective))[1].injector.get(
ManualViewportDirective);

contentViewportDir.show();
main.detectChanges();
expect(main.nativeElement).toHaveText('(ABC, D)');

// hide view viewport, and test that it also hides
// the content viewport's views
viewViewportDir.hide();
main.detectChanges();
expect(main.nativeElement).toHaveText('(, D)');
});
});

@Component({selector: 'main', template: ''})
Expand Down

0 comments on commit 4f487a2

Please sign in to comment.