fix(animations): make sure @.disabled respects disabled parent/sub animation sequences (#18715)

Prior to this fix if @parent and @child animations ran at the same
time within a disabled region then there was a chance that a @child
sub animation would never complete. This would cause *directives to
never close a removal when a @child trigger was placed on them. This
patch fixes this issue.

PR Close #18715
This commit is contained in:
Matias Niemelä
2017-08-04 15:10:47 -07:00
committed by Miško Hevery
parent 5d68c830d2
commit c3dcbf9cb3
2 changed files with 84 additions and 3 deletions

View File

@ -2635,6 +2635,76 @@ export function main() {
fixture.detectChanges();
expect(getLog().length).toEqual(0);
});
it('should respect parent/sub animations when the respective area in the DOM is disabled',
fakeAsync(() => {
@Component({
selector: 'parent-cmp',
animations: [
trigger(
'parent',
[
transition(
'* => empty',
[
style({opacity: 0}),
query(
'@child',
[
animateChild(),
]),
animate('1s', style({opacity: 1})),
]),
]),
trigger(
'child',
[
transition(
':leave',
[
animate('1s', style({opacity: 0})),
]),
]),
],
template: `
<div [@.disabled]="disableExp" #container>
<div [@parent]="exp" (@parent.done)="onDone($event)">
<div class="item" *ngFor="let item of items" @child (@child.done)="onDone($event)"></div>
</div>
</div>
`
})
class Cmp {
@ViewChild('container') public container: any;
disableExp = false;
exp = '';
items: any[] = [];
doneLog: any[] = [];
onDone(event: any) { this.doneLog.push(event); }
}
TestBed.configureTestingModule({declarations: [Cmp]});
const engine = TestBed.get(ɵAnimationEngine);
const fixture = TestBed.createComponent(Cmp);
const cmp = fixture.componentInstance;
cmp.disableExp = true;
cmp.items = [0, 1, 2, 3, 4];
fixture.detectChanges();
flushMicrotasks();
cmp.exp = 'empty';
cmp.items = [];
cmp.doneLog = [];
fixture.detectChanges();
flushMicrotasks();
const elms = cmp.container.nativeElement.querySelectorAll('.item');
expect(elms.length).toEqual(0);
expect(cmp.doneLog.length).toEqual(6);
}));
});
});