Browse Source

Add stack test for update

up-style-manager
Artur Arseniev 5 years ago
parent
commit
b185efc32a
  1. 11
      src/style_manager/model/PropertyStack.js
  2. 19
      test/specs/style_manager/model/Properties.js

11
src/style_manager/model/PropertyStack.js

@ -166,6 +166,15 @@ export default Property.extend({
return this.set('selectedLayer', layer, { __select: true });
},
/**
* Select layer at index
* @param {Number} index Index of the layer to select
*/
selectLayerAt(index = 0) {
const layer = this.getLayer(index);
return layer && this.selectLayer(layer);
},
/**
* Get selected layer
* @returns {[Layer] | null}
@ -222,7 +231,7 @@ export default Property.extend({
},
getLayer(index = 0) {
return this.getLayers().at(index);
return this.getLayers().at(index) || null;
},
getCurrentLayer() {

19
test/specs/style_manager/model/Properties.js

@ -93,13 +93,14 @@ describe('StyleManager properties logic', () => {
const propATest = `${propTest}-a`;
const propBTest = `${propTest}-b`;
const propCTest = `${propTest}-c`;
const propStyleValue = 'valueA-1 valueB-1 valueC-1, valueA-2 valueB-2 valueC-2';
let compTypeProp;
let compTypePropInn;
beforeEach(() => {
rule1 = cssc.addRules(`
.cls {
${propTest}: valueA-1 valueB-1 valueC-1, valueA-2 valueB-2 valueC-2;
${propTest}: ${propStyleValue};
}
`)[0];
obj.addSector(sectorTest, {
@ -127,6 +128,10 @@ describe('StyleManager properties logic', () => {
expect(compTypeProp.getLayers().length).toBe(2);
});
test('Has no selected layer', () => {
expect(compTypeProp.getSelectedLayer()).toBe(null);
});
test('Layers has the right values', () => {
expect(compTypeProp.getLayer(0).getValues()).toEqual({
[propATest]: 'valueA-1',
@ -139,5 +144,17 @@ describe('StyleManager properties logic', () => {
[propCTest]: 'valueC-2',
});
});
test('Updating inner property, it reflects on the rule', () => {
expect(rule1.getStyle()).toEqual({ [propTest]: propStyleValue });
compTypeProp.selectLayerAt(0);
compTypeProp.getProperty(propBTest).upValue('valueB-1-mod');
compTypeProp.selectLayerAt(1);
compTypeProp.getProperty(propCTest).upValue('valueC-2-mod');
expect(rule1.getStyle()).toEqual({
__p: false,
[propTest]: 'valueA-1 valueB-1-mod valueC-1, valueA-2 valueB-2 valueC-2-mod',
});
});
});
});

Loading…
Cancel
Save