test(PropertySetterFactory): add more tests
There are upcoming changes to the way we generate and verify setters so more test are needed to cover all the corner cases that are being handled today. Closes #2559
This commit is contained in:
parent
bc9e482b39
commit
7a41b19e58
|
@ -14,9 +14,10 @@ import {PropertySetterFactory} from 'angular2/src/render/dom/view/property_sette
|
||||||
import {DOM} from 'angular2/src/dom/dom_adapter';
|
import {DOM} from 'angular2/src/dom/dom_adapter';
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
var div, setterFactory;
|
var div, input, setterFactory;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
div = el('<div></div>');
|
div = el('<div></div>');
|
||||||
|
input = el('<input>');
|
||||||
setterFactory = new PropertySetterFactory();
|
setterFactory = new PropertySetterFactory();
|
||||||
});
|
});
|
||||||
describe('property setter factory', () => {
|
describe('property setter factory', () => {
|
||||||
|
@ -66,6 +67,40 @@ export function main() {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('non-standard property setters', () => {
|
||||||
|
|
||||||
|
it('should map readonly name to readOnly property', () => {
|
||||||
|
var setterFn = setterFactory.createSetter(input, false, 'readonly');
|
||||||
|
expect(input.readOnly).toBeFalsy();
|
||||||
|
setterFn(input, true);
|
||||||
|
expect(input.readOnly).toBeTruthy();
|
||||||
|
|
||||||
|
var otherSetterFn = setterFactory.createSetter(input, false, 'readonly');
|
||||||
|
expect(setterFn).toBe(otherSetterFn);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return a setter for innerHtml', () => {
|
||||||
|
var setterFn = setterFactory.createSetter(div, false, 'innerHtml');
|
||||||
|
setterFn(div, '<span></span>');
|
||||||
|
expect(DOM.getInnerHTML(div)).toEqual('<span></span>');
|
||||||
|
|
||||||
|
var otherSetterFn = setterFactory.createSetter(div, false, 'innerHtml');
|
||||||
|
expect(setterFn).toBe(otherSetterFn);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return a setter for tabIndex', () => {
|
||||||
|
var setterFn = setterFactory.createSetter(div, false, 'tabindex');
|
||||||
|
setterFn(div, 1);
|
||||||
|
expect(div.tabIndex).toEqual(1);
|
||||||
|
|
||||||
|
var otherSetterFn = setterFactory.createSetter(div, false, 'tabindex');
|
||||||
|
expect(setterFn).toBe(otherSetterFn);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('attribute setters', () => {
|
||||||
|
|
||||||
it('should return a setter for an attribute', () => {
|
it('should return a setter for an attribute', () => {
|
||||||
var setterFn = setterFactory.createSetter(div, false, 'attr.role');
|
var setterFn = setterFactory.createSetter(div, false, 'attr.role');
|
||||||
setterFn(div, 'button');
|
setterFn(div, 'button');
|
||||||
|
@ -79,6 +114,18 @@ export function main() {
|
||||||
expect(setterFn).toBe(otherSetterFn);
|
expect(setterFn).toBe(otherSetterFn);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should de-normalize attribute names', () => {
|
||||||
|
var setterFn = setterFactory.createSetter(div, false, 'attr.ariaLabel');
|
||||||
|
setterFn(div, 'fancy button');
|
||||||
|
expect(DOM.getAttribute(div, 'aria-label')).toEqual('fancy button');
|
||||||
|
|
||||||
|
var otherSetterFn = setterFactory.createSetter(div, false, 'attr.ariaLabel');
|
||||||
|
expect(setterFn).toBe(otherSetterFn);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('classList setters', () => {
|
||||||
|
|
||||||
it('should return a setter for a class', () => {
|
it('should return a setter for a class', () => {
|
||||||
var setterFn = setterFactory.createSetter(div, false, 'class.active');
|
var setterFn = setterFactory.createSetter(div, false, 'class.active');
|
||||||
setterFn(div, true);
|
setterFn(div, true);
|
||||||
|
@ -90,6 +137,20 @@ export function main() {
|
||||||
expect(setterFn).toBe(otherSetterFn);
|
expect(setterFn).toBe(otherSetterFn);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should de-normalize class names', () => {
|
||||||
|
var setterFn = setterFactory.createSetter(div, false, 'class.veryActive');
|
||||||
|
setterFn(div, true);
|
||||||
|
expect(DOM.hasClass(div, 'very-active')).toEqual(true);
|
||||||
|
setterFn(div, false);
|
||||||
|
expect(DOM.hasClass(div, 'very-active')).toEqual(false);
|
||||||
|
|
||||||
|
var otherSetterFn = setterFactory.createSetter(div, false, 'class.veryActive');
|
||||||
|
expect(setterFn).toBe(otherSetterFn);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('style setters', () => {
|
||||||
|
|
||||||
it('should return a setter for a style', () => {
|
it('should return a setter for a style', () => {
|
||||||
var setterFn = setterFactory.createSetter(div, false, 'style.width');
|
var setterFn = setterFactory.createSetter(div, false, 'style.width');
|
||||||
setterFn(div, '40px');
|
setterFn(div, '40px');
|
||||||
|
@ -101,6 +162,17 @@ export function main() {
|
||||||
expect(setterFn).toBe(otherSetterFn);
|
expect(setterFn).toBe(otherSetterFn);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should de-normalize style names', () => {
|
||||||
|
var setterFn = setterFactory.createSetter(div, false, 'style.textAlign');
|
||||||
|
setterFn(div, 'right');
|
||||||
|
expect(DOM.getStyle(div, 'text-align')).toEqual('right');
|
||||||
|
setterFn(div, null);
|
||||||
|
expect(DOM.getStyle(div, 'text-align')).toEqual('');
|
||||||
|
|
||||||
|
var otherSetterFn = setterFactory.createSetter(div, false, 'style.textAlign');
|
||||||
|
expect(setterFn).toBe(otherSetterFn);
|
||||||
|
});
|
||||||
|
|
||||||
it('should return a setter for a style with a unit', () => {
|
it('should return a setter for a style with a unit', () => {
|
||||||
var setterFn = setterFactory.createSetter(div, false, 'style.height.px');
|
var setterFn = setterFactory.createSetter(div, false, 'style.height.px');
|
||||||
setterFn(div, 40);
|
setterFn(div, 40);
|
||||||
|
@ -112,13 +184,6 @@ export function main() {
|
||||||
expect(setterFn).toBe(otherSetterFn);
|
expect(setterFn).toBe(otherSetterFn);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a setter for innerHtml', () => {
|
|
||||||
var setterFn = setterFactory.createSetter(div, false, 'innerHtml');
|
|
||||||
setterFn(div, '<span></span>');
|
|
||||||
expect(DOM.getInnerHTML(div)).toEqual('<span></span>');
|
|
||||||
|
|
||||||
var otherSetterFn = setterFactory.createSetter(div, false, 'innerHtml');
|
|
||||||
expect(setterFn).toBe(otherSetterFn);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue