|
9 | 9 | import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, Component, ContentChild, ContentChildren, Directive, QueryList, TemplateRef, Type, ViewChild, ViewChildren, ViewContainerRef, asNativeElements} from '@angular/core';
|
10 | 10 | import {ComponentFixture, TestBed, async} from '@angular/core/testing';
|
11 | 11 | import {expect} from '@angular/platform-browser/testing/src/matchers';
|
12 |
| -import {fixmeIvy, ivyEnabled, modifiedInIvy} from '@angular/private/testing'; |
| 12 | +import {fixmeIvy, ivyEnabled, modifiedInIvy, onlyInIvy} from '@angular/private/testing'; |
13 | 13 | import {Subject} from 'rxjs';
|
14 | 14 |
|
15 | 15 | import {stringify} from '../../src/util/stringify';
|
@@ -570,7 +570,7 @@ describe('Query API', () => {
|
570 | 570 | });
|
571 | 571 |
|
572 | 572 | // Note: this test is just document our current behavior, which we do for performance reasons.
|
573 |
| - fixmeIvy('FW-853: Query results are cleared if embedded views are detached / moved') |
| 573 | + modifiedInIvy('Query results from views are reported upon view insert / detach') |
574 | 574 | .it('should not affect queries for projected templates if views are detached or moved',
|
575 | 575 | () => {
|
576 | 576 | const template = `<manual-projecting #q>
|
@@ -600,6 +600,41 @@ describe('Query API', () => {
|
600 | 600 | expect(q.query.map((d: TextDirective) => d.text)).toEqual(['1', '2']);
|
601 | 601 | });
|
602 | 602 |
|
| 603 | + onlyInIvy('Query results from views are reported upon view insert / detach') |
| 604 | + .it('should update queries when a view is detached and re-inserted', () => { |
| 605 | + const template = `<manual-projecting #q> |
| 606 | + <ng-template let-x="x"> |
| 607 | + <div [text]="x"></div> |
| 608 | + </ng-template> |
| 609 | + </manual-projecting>`; |
| 610 | + const view = createTestCmpAndDetectChanges(MyComp0, template); |
| 611 | + const q = view.debugElement.children[0].references !['q'] as ManualProjecting; |
| 612 | + expect(q.query.length).toBe(0); |
| 613 | + |
| 614 | + const view1 = q.vc.createEmbeddedView(q.template, {'x': '1'}); |
| 615 | + const view2 = q.vc.createEmbeddedView(q.template, {'x': '2'}); |
| 616 | + |
| 617 | + // 2 views were created and inserted so we've got 2 matching results |
| 618 | + view.detectChanges(); |
| 619 | + expect(q.query.map((d: TextDirective) => d.text)).toEqual(['1', '2']); |
| 620 | + |
| 621 | + q.vc.detach(1); |
| 622 | + q.vc.detach(0); |
| 623 | + |
| 624 | + // both views were detached so query results from those views should not be reported |
| 625 | + view.detectChanges(); |
| 626 | + expect(q.query.map((d: TextDirective) => d.text)).toEqual([]); |
| 627 | + |
| 628 | + q.vc.insert(view2); |
| 629 | + q.vc.insert(view1); |
| 630 | + |
| 631 | + // previously detached views are re-inserted in the different order so: |
| 632 | + // - query results from the inserted views are reported again |
| 633 | + // - the order results from views reflects orders of views |
| 634 | + view.detectChanges(); |
| 635 | + expect(q.query.map((d: TextDirective) => d.text)).toEqual(['2', '1']); |
| 636 | + }); |
| 637 | + |
603 | 638 | fixmeIvy('FW-920: Queries in nested views are not destroyed properly')
|
604 | 639 | .it('should remove manually projected templates if their parent view is destroyed', () => {
|
605 | 640 | const template = `
|
|
0 commit comments