|
5 | 5 | * Use of this source code is governed by an MIT-style license that can be |
6 | 6 | * found in the LICENSE file at https://angular.io/license |
7 | 7 | */ |
8 | | -import {animate, animateChild, AnimationPlayer, AUTO_STYLE, group, query, sequence, stagger, state, style, transition, trigger, ɵAnimationGroupPlayer as AnimationGroupPlayer} from '@angular/animations'; |
| 8 | +import {animate, animateChild, AnimationEvent, AnimationPlayer, AUTO_STYLE, group, query, sequence, stagger, state, style, transition, trigger, ɵAnimationGroupPlayer as AnimationGroupPlayer} from '@angular/animations'; |
9 | 9 | import {AnimationDriver, ɵAnimationEngine, ɵnormalizeKeyframes as normalizeKeyframes} from '@angular/animations/browser'; |
10 | 10 | import {TransitionAnimationPlayer} from '@angular/animations/browser/src/render/transition_animation_engine'; |
11 | 11 | import {ENTER_CLASSNAME, LEAVE_CLASSNAME} from '@angular/animations/browser/src/util'; |
12 | 12 | import {MockAnimationDriver, MockAnimationPlayer} from '@angular/animations/browser/testing'; |
13 | 13 | import {CommonModule} from '@angular/common'; |
14 | | -import {Component, HostBinding, ViewChild} from '@angular/core'; |
| 14 | +import {Component, HostBinding, ViewChild, ViewEncapsulation} from '@angular/core'; |
15 | 15 | import {fakeAsync, flushMicrotasks, TestBed} from '@angular/core/testing'; |
16 | 16 | import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; |
17 | 17 |
|
@@ -2832,6 +2832,64 @@ describe('animation query tests', function() { |
2832 | 2832 | ]); |
2833 | 2833 | })); |
2834 | 2834 |
|
| 2835 | + it(`should emulate a leave animation on a child elements when a parent component using shadowDom leaves the DOM`, |
| 2836 | + fakeAsync(() => { |
| 2837 | + let childLeaveLog = 0; |
| 2838 | + |
| 2839 | + @Component({ |
| 2840 | + selector: 'ani-host', |
| 2841 | + template: `<ani-parent *ngIf="exp"></ani-parent>`, |
| 2842 | + }) |
| 2843 | + class HostCmp { |
| 2844 | + public exp: boolean = false; |
| 2845 | + } |
| 2846 | + |
| 2847 | + @Component({ |
| 2848 | + selector: 'ani-parent', |
| 2849 | + encapsulation: ViewEncapsulation.ShadowDom, |
| 2850 | + template: ` |
| 2851 | + <div @childAnimation (@childAnimation.start)="logChildLeave($event)"></div> |
| 2852 | + `, |
| 2853 | + animations: [ |
| 2854 | + trigger( |
| 2855 | + 'childAnimation', |
| 2856 | + [ |
| 2857 | + transition(':leave', []), |
| 2858 | + ]), |
| 2859 | + ] |
| 2860 | + }) |
| 2861 | + class ParentCmp { |
| 2862 | + logChildLeave(event: AnimationEvent) { |
| 2863 | + if (event.toState === 'void') { |
| 2864 | + childLeaveLog++; |
| 2865 | + } |
| 2866 | + } |
| 2867 | + } |
| 2868 | + |
| 2869 | + TestBed.configureTestingModule({declarations: [ParentCmp, HostCmp]}); |
| 2870 | + |
| 2871 | + const fixture = TestBed.createComponent(HostCmp); |
| 2872 | + const cmp = fixture.componentInstance; |
| 2873 | + |
| 2874 | + const updateExpAndFlush = (value: boolean) => { |
| 2875 | + cmp.exp = value; |
| 2876 | + fixture.detectChanges(); |
| 2877 | + flushMicrotasks(); |
| 2878 | + }; |
| 2879 | + |
| 2880 | + updateExpAndFlush(true); |
| 2881 | + expect(childLeaveLog).toEqual(0); |
| 2882 | + |
| 2883 | + updateExpAndFlush(false); |
| 2884 | + expect(childLeaveLog).toEqual(1); |
| 2885 | + |
| 2886 | + updateExpAndFlush(true); |
| 2887 | + expect(childLeaveLog).toEqual(1); |
| 2888 | + |
| 2889 | + updateExpAndFlush(false); |
| 2890 | + expect(childLeaveLog).toEqual(2); |
| 2891 | + })); |
| 2892 | + |
2835 | 2893 | it('should build, but not run sub triggers when a parent animation is scheduled', () => { |
2836 | 2894 | @Component({ |
2837 | 2895 | selector: 'parent-cmp', |
|
0 commit comments