|
|
|
@ -1,4 +1,3 @@ |
|
|
|
import Backbone from 'backbone'; |
|
|
|
import PropertyNumberView from 'style_manager/view/PropertyNumberView'; |
|
|
|
import PropertyNumber from 'style_manager/model/PropertyNumber'; |
|
|
|
import Component from 'dom_components/model/Component'; |
|
|
|
@ -14,12 +13,10 @@ describe('PropertyNumberView', () => { |
|
|
|
var target; |
|
|
|
var model; |
|
|
|
var view; |
|
|
|
var propTarget; |
|
|
|
var propName = 'testprop'; |
|
|
|
var intValue = '55'; |
|
|
|
var unitValue = 'px'; |
|
|
|
var propValue = intValue + unitValue; |
|
|
|
var defValue = 'test2value'; |
|
|
|
var units = ['px', '%', 'em']; |
|
|
|
var minValue = -15; |
|
|
|
var maxValue = 75; |
|
|
|
@ -29,18 +26,16 @@ describe('PropertyNumberView', () => { |
|
|
|
em = new Editor({}); |
|
|
|
dcomp = new DomComponents(); |
|
|
|
compOpts = { em, componentTypes: dcomp.componentTypes }; |
|
|
|
propTarget = { ...Backbone.Events }; |
|
|
|
target = new Component({}, compOpts); |
|
|
|
component = new Component({}, compOpts); |
|
|
|
model = new PropertyNumber({ |
|
|
|
units, |
|
|
|
property: propName, |
|
|
|
}); |
|
|
|
propTarget.model = component; |
|
|
|
view = new PropertyNumberView({ |
|
|
|
model, |
|
|
|
propTarget, |
|
|
|
}); |
|
|
|
model = new PropertyNumber( |
|
|
|
{ |
|
|
|
units, |
|
|
|
property: propName, |
|
|
|
}, |
|
|
|
{ em } |
|
|
|
); |
|
|
|
view = new PropertyNumberView({ model }); |
|
|
|
document.body.innerHTML = '<div id="fixtures"></div>'; |
|
|
|
fixtures = document.body.firstChild; |
|
|
|
view.render(); |
|
|
|
@ -72,19 +67,18 @@ describe('PropertyNumberView', () => { |
|
|
|
|
|
|
|
test('Units rendered', () => { |
|
|
|
var select = view.el.querySelector(unitsElSel); |
|
|
|
expect(select.children.length).toEqual(units.length); |
|
|
|
expect(select.children.length).toEqual(units.length + 1); // (+ hidden option)
|
|
|
|
}); |
|
|
|
|
|
|
|
test('Units rendered correctly', () => { |
|
|
|
var children = view.el.querySelector(unitsElSel).children; |
|
|
|
expect(children[0].textContent).toEqual(units[0]); |
|
|
|
expect(children[1].textContent).toEqual(units[1]); |
|
|
|
expect(children[2].textContent).toEqual(units[2]); |
|
|
|
expect(children[1].textContent).toEqual(units[0]); |
|
|
|
expect(children[2].textContent).toEqual(units[1]); |
|
|
|
expect(children[3].textContent).toEqual(units[2]); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Inputs should exist', () => { |
|
|
|
expect(view.input).toBeTruthy(); |
|
|
|
expect(view.unit).toBeTruthy(); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Input value is empty', () => { |
|
|
|
@ -95,78 +89,39 @@ describe('PropertyNumberView', () => { |
|
|
|
view.setValue(intValue + unitValue); |
|
|
|
expect(view.model.get('value')).toEqual(parseFloat(intValue)); |
|
|
|
expect(view.model.get('unit')).toEqual(unitValue); |
|
|
|
expect(view.getInputValue()).toEqual(intValue); |
|
|
|
expect(view.unit.value).toEqual(unitValue); |
|
|
|
expect(view.getInputEl().value).toEqual(intValue); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Update model on input change', () => { |
|
|
|
view.$input.val(123).trigger('change'); |
|
|
|
view.inputInst.inputEl.val(123).trigger('change'); |
|
|
|
expect(view.model.get('value')).toEqual(123); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Update model on unit change', () => { |
|
|
|
view.$unit.val(units[1]).trigger('change'); |
|
|
|
view.inputInst.unitEl.value = units[1]; |
|
|
|
view.inputInst.handleUnitChange({ stopPropagation() {} }); |
|
|
|
expect(view.model.get('unit')).toEqual(units[1]); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Update input on value change', () => { |
|
|
|
view.model.set('value', intValue); |
|
|
|
expect(view.getInputValue()).toEqual(intValue); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Update target on value change', () => { |
|
|
|
const val = `${intValue}%`; |
|
|
|
view.model.setValue(val); |
|
|
|
expect(view.getTargetValue()).toEqual(val); |
|
|
|
}); |
|
|
|
|
|
|
|
describe('With target setted', () => { |
|
|
|
beforeEach(() => { |
|
|
|
target.model = component; |
|
|
|
view = new PropertyNumberView({ |
|
|
|
model, |
|
|
|
propTarget: target, |
|
|
|
}); |
|
|
|
fixtures.innerHTML = ''; |
|
|
|
view.render(); |
|
|
|
fixtures.appendChild(view.el); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Update value and input on target swap', () => { |
|
|
|
var style = {}; |
|
|
|
style[propName] = propValue; |
|
|
|
component.set('style', style); |
|
|
|
view.propTarget.trigger('update'); |
|
|
|
expect(view.model.get('value')).toEqual(parseFloat(intValue)); |
|
|
|
expect(view.getInputValue()).toEqual(intValue); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Update value after multiple swaps', () => { |
|
|
|
var style = {}; |
|
|
|
style[propName] = propValue; |
|
|
|
component.set('style', style); |
|
|
|
view.propTarget.trigger('update'); |
|
|
|
style[propName] = '20em'; |
|
|
|
component.set('style', style); |
|
|
|
view.propTarget.trigger('update'); |
|
|
|
expect(view.model.get('value')).toEqual(20); |
|
|
|
expect(view.model.get('unit')).toEqual('em'); |
|
|
|
expect(view.getInputValue()).toEqual('20'); |
|
|
|
expect(view.$unit.val()).toEqual('em'); |
|
|
|
}); |
|
|
|
expect(view.getInputEl().value).toEqual(intValue); |
|
|
|
}); |
|
|
|
|
|
|
|
describe('Init property', () => { |
|
|
|
beforeEach(() => { |
|
|
|
component = new Component(); |
|
|
|
model = new PropertyNumber({ |
|
|
|
units, |
|
|
|
property: propName, |
|
|
|
defaults: intValue, |
|
|
|
min: minValue, |
|
|
|
max: maxValue, |
|
|
|
unit: units[1], |
|
|
|
}); |
|
|
|
model = new PropertyNumber( |
|
|
|
{ |
|
|
|
units, |
|
|
|
property: propName, |
|
|
|
defaults: intValue, |
|
|
|
min: minValue, |
|
|
|
max: maxValue, |
|
|
|
unit: units[1], |
|
|
|
}, |
|
|
|
{ em } |
|
|
|
); |
|
|
|
view = new PropertyNumberView({ |
|
|
|
model, |
|
|
|
}); |
|
|
|
@ -181,20 +136,20 @@ describe('PropertyNumberView', () => { |
|
|
|
}); |
|
|
|
|
|
|
|
test('Input value is as default', () => { |
|
|
|
expect(view.getInputValue()).toEqual(intValue); |
|
|
|
expect(view.$unit.val()).toEqual(units[1]); |
|
|
|
expect(view.getInputEl().value).toEqual(intValue); |
|
|
|
expect(view.inputInst.unitEl.value).toEqual(units[1]); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Input follows min', () => { |
|
|
|
view.$input.val(minValue - 50).trigger('change'); |
|
|
|
view.inputInst.inputEl.val(minValue - 50).trigger('change'); |
|
|
|
expect(view.model.get('value')).toEqual(minValue); |
|
|
|
expect(view.getInputValue()).toEqual(minValue + ''); |
|
|
|
expect(view.getInputEl().value).toEqual(minValue + ''); |
|
|
|
}); |
|
|
|
|
|
|
|
test('Input follows max', () => { |
|
|
|
view.$input.val(maxValue + 50).trigger('change'); |
|
|
|
view.inputInst.inputEl.val(maxValue + 50).trigger('change'); |
|
|
|
expect(view.model.get('value')).toEqual(maxValue); |
|
|
|
expect(view.getInputValue()).toEqual(maxValue + ''); |
|
|
|
expect(view.getInputEl().value).toEqual(maxValue + ''); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|