|
6 | 6 | * found in the LICENSE file at https://angular.io/license
|
7 | 7 | */
|
8 | 8 |
|
| 9 | +import {state, style, trigger} from '@angular/animations'; |
9 | 10 | import {Component, ContentChildren, Directive, EventEmitter, HostBinding, HostListener, Input, OnChanges, Output, QueryList, ViewChildren} from '@angular/core';
|
10 | 11 | import {ivyEnabled} from '@angular/core/src/ivy_switch';
|
11 | 12 | import {getDirectiveDef} from '@angular/core/src/render3/definition';
|
12 | 13 | import {TestBed} from '@angular/core/testing';
|
13 | 14 | import {By} from '@angular/platform-browser';
|
| 15 | +import {NoopAnimationsModule} from '@angular/platform-browser/animations'; |
14 | 16 | import {onlyInIvy} from '@angular/private/testing';
|
15 | 17 |
|
16 | 18 | describe('inheritance', () => {
|
@@ -4132,6 +4134,99 @@ describe('inheritance', () => {
|
4132 | 4134 | });
|
4133 | 4135 | });
|
4134 | 4136 |
|
| 4137 | + describe('animations', () => { |
| 4138 | + onlyInIvy('View Engine does not inherit `host` metadata from superclass') |
| 4139 | + .it('should work with inherited host bindings and animations', () => { |
| 4140 | + @Component({ |
| 4141 | + selector: 'super-comp', |
| 4142 | + template: '<div>super-comp</div>', |
| 4143 | + host: { |
| 4144 | + '[@animation]': 'colorExp', |
| 4145 | + }, |
| 4146 | + animations: [ |
| 4147 | + trigger('animation', [state('color', style({color: 'red'}))]), |
| 4148 | + ], |
| 4149 | + }) |
| 4150 | + class SuperComponent { |
| 4151 | + colorExp = 'color'; |
| 4152 | + } |
| 4153 | + |
| 4154 | + @Component({ |
| 4155 | + selector: 'my-comp', |
| 4156 | + template: `<div>my-comp</div>`, |
| 4157 | + }) |
| 4158 | + class MyComponent extends SuperComponent { |
| 4159 | + } |
| 4160 | + |
| 4161 | + @Component({ |
| 4162 | + template: '<my-comp>app</my-comp>', |
| 4163 | + }) |
| 4164 | + class App { |
| 4165 | + } |
| 4166 | + |
| 4167 | + TestBed.configureTestingModule({ |
| 4168 | + declarations: [App, MyComponent, SuperComponent], |
| 4169 | + imports: [NoopAnimationsModule], |
| 4170 | + }); |
| 4171 | + const fixture = TestBed.createComponent(App); |
| 4172 | + fixture.detectChanges(); |
| 4173 | + const queryResult = fixture.debugElement.query(By.css('my-comp')); |
| 4174 | + |
| 4175 | + expect(queryResult.nativeElement.style.color).toBe('red'); |
| 4176 | + }); |
| 4177 | + |
| 4178 | + onlyInIvy('View Engine does not inherit `host` metadata from superclass') |
| 4179 | + .it('should compose animations (from super class)', () => { |
| 4180 | + @Component({ |
| 4181 | + selector: 'super-comp', |
| 4182 | + template: '...', |
| 4183 | + animations: [ |
| 4184 | + trigger('animation1', [state('color', style({color: 'red'}))]), |
| 4185 | + trigger('animation2', [state('opacity', style({opacity: '0.5'}))]), |
| 4186 | + ], |
| 4187 | + }) |
| 4188 | + class SuperComponent { |
| 4189 | + } |
| 4190 | + |
| 4191 | + @Component({ |
| 4192 | + selector: 'my-comp', |
| 4193 | + template: '<div>my-comp</div>', |
| 4194 | + host: { |
| 4195 | + '[@animation1]': 'colorExp', |
| 4196 | + '[@animation2]': 'opacityExp', |
| 4197 | + '[@animation3]': 'bgExp', |
| 4198 | + }, |
| 4199 | + animations: [ |
| 4200 | + trigger('animation1', [state('color', style({color: 'blue'}))]), |
| 4201 | + trigger('animation3', [state('bg', style({backgroundColor: 'green'}))]), |
| 4202 | + ], |
| 4203 | + }) |
| 4204 | + class MyComponent extends SuperComponent { |
| 4205 | + colorExp = 'color'; |
| 4206 | + opacityExp = 'opacity'; |
| 4207 | + bgExp = 'bg'; |
| 4208 | + } |
| 4209 | + |
| 4210 | + @Component({ |
| 4211 | + template: '<my-comp>app</my-comp>', |
| 4212 | + }) |
| 4213 | + class App { |
| 4214 | + } |
| 4215 | + |
| 4216 | + TestBed.configureTestingModule({ |
| 4217 | + declarations: [App, MyComponent, SuperComponent], |
| 4218 | + imports: [NoopAnimationsModule], |
| 4219 | + }); |
| 4220 | + const fixture = TestBed.createComponent(App); |
| 4221 | + fixture.detectChanges(); |
| 4222 | + const queryResult = fixture.debugElement.query(By.css('my-comp')); |
| 4223 | + |
| 4224 | + expect(queryResult.nativeElement.style.color).toBe('blue'); |
| 4225 | + expect(queryResult.nativeElement.style.opacity).toBe('0.5'); |
| 4226 | + expect(queryResult.nativeElement.style.backgroundColor).toBe('green'); |
| 4227 | + }); |
| 4228 | + }); |
| 4229 | + |
4135 | 4230 | describe('host bindings (style related)', () => {
|
4136 | 4231 | // TODO: sub and super HostBinding same property but different bindings
|
4137 | 4232 | // TODO: sub and super HostBinding same binding on two different properties
|
@@ -4819,6 +4914,70 @@ describe('inheritance', () => {
|
4819 | 4914 | });
|
4820 | 4915 | });
|
4821 | 4916 |
|
| 4917 | + describe('animations', () => { |
| 4918 | + onlyInIvy('View Engine does not inherit `host` metadata from superclass') |
| 4919 | + .it('should compose animations across multiple inheritance levels', () => { |
| 4920 | + @Component({ |
| 4921 | + selector: 'super-comp', |
| 4922 | + template: '...', |
| 4923 | + host: { |
| 4924 | + '[@animation1]': 'colorExp', |
| 4925 | + '[@animation2]': 'opacityExp', |
| 4926 | + }, |
| 4927 | + animations: [ |
| 4928 | + trigger('animation1', [state('color', style({color: 'red'}))]), |
| 4929 | + trigger('animation2', [state('opacity', style({opacity: '0.5'}))]), |
| 4930 | + ], |
| 4931 | + }) |
| 4932 | + class SuperComponent { |
| 4933 | + colorExp = 'color'; |
| 4934 | + opacityExp = 'opacity'; |
| 4935 | + } |
| 4936 | + |
| 4937 | + @Component({ |
| 4938 | + selector: 'intermediate-comp', |
| 4939 | + template: '...', |
| 4940 | + }) |
| 4941 | + class IntermediateComponent extends SuperComponent { |
| 4942 | + } |
| 4943 | + |
| 4944 | + @Component({ |
| 4945 | + selector: 'my-comp', |
| 4946 | + template: '<div>my-comp</div>', |
| 4947 | + host: { |
| 4948 | + '[@animation1]': 'colorExp', |
| 4949 | + '[@animation3]': 'bgExp', |
| 4950 | + }, |
| 4951 | + animations: [ |
| 4952 | + trigger('animation1', [state('color', style({color: 'blue'}))]), |
| 4953 | + trigger('animation3', [state('bg', style({backgroundColor: 'green'}))]), |
| 4954 | + ], |
| 4955 | + }) |
| 4956 | + class MyComponent extends IntermediateComponent { |
| 4957 | + colorExp = 'color'; |
| 4958 | + opacityExp = 'opacity'; |
| 4959 | + bgExp = 'bg'; |
| 4960 | + } |
| 4961 | + |
| 4962 | + @Component({ |
| 4963 | + template: '<my-comp>app</my-comp>', |
| 4964 | + }) |
| 4965 | + class App { |
| 4966 | + } |
| 4967 | + |
| 4968 | + TestBed.configureTestingModule({ |
| 4969 | + declarations: [App, MyComponent, IntermediateComponent, SuperComponent], |
| 4970 | + imports: [NoopAnimationsModule], |
| 4971 | + }); |
| 4972 | + const fixture = TestBed.createComponent(App); |
| 4973 | + fixture.detectChanges(); |
| 4974 | + const queryResult = fixture.debugElement.query(By.css('my-comp')); |
| 4975 | + |
| 4976 | + expect(queryResult.nativeElement.style.color).toBe('blue'); |
| 4977 | + expect(queryResult.nativeElement.style.opacity).toBe('0.5'); |
| 4978 | + expect(queryResult.nativeElement.style.backgroundColor).toBe('green'); |
| 4979 | + }); |
| 4980 | + }); |
4822 | 4981 | describe('host bindings (style related)', () => {
|
4823 | 4982 | // TODO: sub and super HostBinding same property but different bindings
|
4824 | 4983 | // TODO: sub and super HostBinding same binding on two different properties
|
|
0 commit comments