Browse Source

Update Sorter tests

pull/36/head
Artur Arseniev 11 years ago
parent
commit
79ddb05ae6
  1. 1
      src/style_manager/model/Layers.js
  2. 1
      src/style_manager/view/LayerView.js
  3. 9
      src/utils/Sorter.js
  4. 7
      test/specs/style_manager/model/Models.js
  5. 17
      test/specs/style_manager/view/LayerView.js
  6. 66
      test/specs/utils/Sorter.js

1
src/style_manager/model/Layers.js

@ -12,7 +12,6 @@ define([ 'backbone', './Layer'],
}, },
onAdd: function(model, c, opts){ onAdd: function(model, c, opts){
//console.log(opts);
if(!opts.noIncrement) if(!opts.noIncrement)
model.set('index', this.idx++); model.set('index', this.idx++);
}, },

1
src/style_manager/view/LayerView.js

@ -162,7 +162,6 @@ define(['backbone', 'text!./../templates/layer.html'],
}, },
render : function(){ render : function(){
var i = this.getIndex();
this.$el.html( this.template({ this.$el.html( this.template({
label: 'Layer ' + this.model.get('index'), label: 'Layer ' + this.model.get('index'),
pfx: this.pfx, pfx: this.pfx,

9
src/utils/Sorter.js

@ -356,12 +356,9 @@ define(['backbone'],
/** /**
* Move component to new position * Move component to new position
* @param {Object} Component to move * @param {HTMLElement} dst Destination target
* @param {Object} Target component * @param {HTMLElement} src Element to move
* @param {Integer} Indicates the position inside the collection * @param {Object} pos Object with position coordinates
* @param {String} Before of after component
*
* @return void
* */ * */
move: function(dst, src, pos){ move: function(dst, src, pos){
var index = pos.index; var index = pos.index;

7
test/specs/style_manager/model/Models.js

@ -163,6 +163,13 @@ define([path + 'Sector',
model3.get('index').should.equal(3); model3.get('index').should.equal(3);
}); });
it('Reset index on reset', function() {
var model = obj.add({});
var model2 = obj.add({});
obj.reset();
obj.idx.should.equal(1);
});
}); });
} }

17
test/specs/style_manager/view/LayerView.js

@ -54,24 +54,17 @@ define([path + 'LayerView', 'StyleManager/model/Layers'],
view.getIndex().should.equal(0); view.getIndex().should.equal(0);
}); });
it('Destroy element', function() {
view.model.destroy();
});
it('No preview', function() { it('No preview', function() {
var style = view.el.querySelector('#preview').style; var style = view.el.querySelector('#preview').style;
style.cssText.should.be.empty; style.cssText.should.be.empty;
}); });
it.skip('Changes on valuePreview update preview box', function() { it('Changes on value trigger onPreview', function() {
var layerProp = 'color'; var called = 0;
var layerPrevValue = 'red'; view.onPreview = function(){called = 1};
view.model.set('preview', true); view.model.set('preview', true);
view.model.set('propertyPreview', layerProp); view.model.set('value', 'test');
view.model.set('valuePreview', layerPrevValue); called.should.equal(1);
var preview = view.el.querySelector('#preview');
var style = preview.style;
style[layerProp].should.equal(layerPrevValue);
}); });
it('Update props', function() { it('Update props', function() {

66
test/specs/utils/Sorter.js

@ -6,17 +6,28 @@ define([path + 'Sorter',],
run : function(){ run : function(){
describe('Sorter', function() { describe('Sorter', function() {
var fixtures;
var fixture;
var obj; var obj;
var parent; var parent;
var plh;
before(function () {
fixture = $('<div class="sorter-fixture"></div>').get(0);
});
beforeEach(function () { beforeEach(function () {
parent = document.createElement('div'); parent = document.createElement('div');
parent.setAttribute('class', 'parent1'); parent.setAttribute('class', 'parent1');
plh = document.createElement('div');
document.body.appendChild(parent); document.body.appendChild(parent);
obj = new Sorter({container: '.parent1'}); obj = new Sorter({container: '.parent1'});
document.body.appendChild(fixture);
fixture.appendChild(parent);
}); });
afterEach(function () { afterEach(function () {
document.body.removeChild(fixture);
delete obj; delete obj;
}); });
@ -84,6 +95,7 @@ define([path + 'Sorter',],
describe('With elements', function() { describe('With elements', function() {
var vertDims;
var parent2; var parent2;
var parent3; var parent3;
var sib1; var sib1;
@ -121,20 +133,30 @@ define([path + 'Sorter',],
el.appendChild(sib2); el.appendChild(sib2);
el.appendChild(sib3); el.appendChild(sib3);
el.appendChild(sib4); el.appendChild(sib4);
vertDims = [
[0, 0, 50, 100, true],
[50, 0, 50, 100, true],
[100, 0, 50, 100, true],
[150, 0, 50, 70, true],
];
}); });
it('startSort inits correctly inits', function() { it('startSort inits correctly inits', function() {
obj.startSort(el); obj.startSort(el);
obj.moved.should.equal(0);
obj.plh.style.display.should.equal('none'); obj.plh.style.display.should.equal('none');
}); });
it.skip('onMove', function() { it('onMove', function() {
var target = document.createElement('div');
obj.startSort(el); obj.startSort(el);
obj.onMove({ obj.onMove({
pageX: 0, pageX: 0,
pageY: 0, pageY: 0,
target: target
}); });
obj.plh.style.display.should.equal('block'); obj.moved.should.equal(1);
}); });
it('getDim from element', function() { it('getDim from element', function() {
@ -230,15 +252,7 @@ define([path + 'Sorter',],
describe('findPosition', function() { describe('findPosition', function() {
var dimsTree;
beforeEach(function () { beforeEach(function () {
vertDims = [
[0, 0, 50, 100, true],
[50, 0, 50, 100, true],
[100, 0, 50, 100, true],
[150, 0, 50, 70, true],
];
}); });
it('Vertical dimensions', function() { it('Vertical dimensions', function() {
@ -264,11 +278,35 @@ define([path + 'Sorter',],
}); });
it.skip('movePlaceholder', function() { describe('movePlaceholder', function() {
});
beforeEach(function () {
vertDims = [
[0, 10, 50, 100, true],
[50, 20, 50, 70, true],
[100, 30, 50, 100, true],
[150, 40, 50, 70, true],
];
});
it('Vertical dimensions with before position', function() {
var pos = {index: 2, method: 'before'};
obj.movePlaceholder(plh, vertDims, pos);
var style = plh.style;
style.top.should.equal('100px');
style.left.should.equal('30px');
style.width.should.equal('100px');
});
it('Vertical dimensions with after position', function() {
var pos = {index: 1, method: 'after'};
obj.movePlaceholder(plh, vertDims, pos);
var style = plh.style;
style.top.should.equal('100px');
style.left.should.equal('20px');
style.width.should.equal('70px');
});
it.skip('move', function() {
obj.move(el).should.equal('test');
}); });
}); });

Loading…
Cancel
Save