-
Notifications
You must be signed in to change notification settings - Fork 25.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(animations): ensure the web-animations driver converts style prop…
…s to camel-case The web animations API now requires that all styles are converted to camel case. Chrome has already made this breaking change and hyphenated styles are not functional anymore. Closes #9111 Closes #9112
- Loading branch information
Showing
4 changed files
with
166 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
modules/@angular/platform-browser/test/dom/web_animations_driver_spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal'; | ||
import {el} from '@angular/platform-browser/testing'; | ||
|
||
import {AnimationKeyframe, AnimationStyles} from '../../core_private'; | ||
import {DomAnimatePlayer} from '../../src/dom/dom_animate_player'; | ||
import {WebAnimationsDriver} from '../../src/dom/web_animations_driver'; | ||
import {MockDomAnimatePlayer} from '../../testing/mock_dom_animate_player'; | ||
|
||
class ExtendedWebAnimationsDriver extends WebAnimationsDriver { | ||
public log: {[key: string]: any}[] = []; | ||
|
||
constructor() { super(); } | ||
|
||
_triggerWebAnimation(elm: any, keyframes: any[], options: any): DomAnimatePlayer { | ||
this.log.push({'elm': elm, 'keyframes': keyframes, 'options': options}); | ||
return new MockDomAnimatePlayer(); | ||
} | ||
} | ||
|
||
function _makeStyles(styles: {[key: string]: string | number}): AnimationStyles { | ||
return new AnimationStyles([styles]); | ||
} | ||
|
||
function _makeKeyframe( | ||
offset: number, styles: {[key: string]: string | number}): AnimationKeyframe { | ||
return new AnimationKeyframe(offset, _makeStyles(styles)); | ||
} | ||
|
||
export function main() { | ||
describe('WebAnimationsDriver', () => { | ||
var driver: ExtendedWebAnimationsDriver; | ||
var elm: HTMLElement; | ||
beforeEach(() => { | ||
driver = new ExtendedWebAnimationsDriver(); | ||
elm = el('<div></div>'); | ||
}); | ||
|
||
it('should convert all styles to camelcase', () => { | ||
var startingStyles = _makeStyles({'border-top-right': '40px'}); | ||
var styles = [ | ||
_makeKeyframe(0, {'max-width': '100px', 'height': '200px'}), | ||
_makeKeyframe(1, {'font-size': '555px'}) | ||
]; | ||
|
||
driver.animate(elm, startingStyles, styles, 0, 0, 'linear'); | ||
var details = driver.log.pop(); | ||
var startKeyframe = details['keyframes'][0]; | ||
var firstKeyframe = details['keyframes'][1]; | ||
var lastKeyframe = details['keyframes'][2]; | ||
|
||
expect(startKeyframe['borderTopRight']).toEqual('40px'); | ||
|
||
expect(firstKeyframe['maxWidth']).toEqual('100px'); | ||
expect(firstKeyframe['max-width']).toBeFalsy(); | ||
expect(firstKeyframe['height']).toEqual('200px'); | ||
|
||
expect(lastKeyframe['fontSize']).toEqual('555px'); | ||
expect(lastKeyframe['font-size']).toBeFalsy(); | ||
}); | ||
|
||
it('should auto prefix numeric properties with a `px` value', () => { | ||
var startingStyles = _makeStyles({'borderTopWidth': 40}); | ||
var styles = [_makeKeyframe(0, {'font-size': 100}), _makeKeyframe(1, {'height': '555em'})]; | ||
|
||
driver.animate(elm, startingStyles, styles, 0, 0, 'linear'); | ||
var details = driver.log.pop(); | ||
var startKeyframe = details['keyframes'][0]; | ||
var firstKeyframe = details['keyframes'][1]; | ||
var lastKeyframe = details['keyframes'][2]; | ||
|
||
expect(startKeyframe['borderTopWidth']).toEqual('40px'); | ||
|
||
expect(firstKeyframe['fontSize']).toEqual('100px'); | ||
|
||
expect(lastKeyframe['height']).toEqual('555em'); | ||
}); | ||
}); | ||
} |
35 changes: 1 addition & 34 deletions
35
modules/@angular/platform-browser/test/dom/web_animations_player_spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
modules/@angular/platform-browser/testing/mock_dom_animate_player.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import {DomAnimatePlayer} from '../src/dom/dom_animate_player'; | ||
import {isPresent} from '../src/facade/lang'; | ||
|
||
export class MockDomAnimatePlayer implements DomAnimatePlayer { | ||
public captures: {[key: string]: any[]} = {}; | ||
private _position: number = 0; | ||
private _onfinish: Function = () => {}; | ||
public currentTime: number; | ||
|
||
/** @internal */ | ||
_capture(method: string, data: any): void { | ||
if (!isPresent(this.captures[method])) { | ||
this.captures[method] = []; | ||
} | ||
this.captures[method].push(data); | ||
} | ||
|
||
cancel(): void { this._capture('cancel', null); } | ||
play(): void { this._capture('play', null); } | ||
pause(): void { this._capture('pause', null); } | ||
finish(): void { | ||
this._capture('finish', null); | ||
this._onfinish(); | ||
} | ||
set onfinish(fn: Function) { | ||
this._capture('onfinish', fn); | ||
this._onfinish = fn; | ||
} | ||
get onfinish(): Function { return this._onfinish; } | ||
set position(val: number) { | ||
this._capture('position', val); | ||
this._position = val; | ||
} | ||
get position(): number { return this._position; } | ||
} |