diff --git a/src/style_manager/model/PropertyStack.js b/src/style_manager/model/PropertyStack.js index 89057440e..5ba998321 100644 --- a/src/style_manager/model/PropertyStack.js +++ b/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() { diff --git a/test/specs/style_manager/model/Properties.js b/test/specs/style_manager/model/Properties.js index 87772eeda..3521d4758 100644 --- a/test/specs/style_manager/model/Properties.js +++ b/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', + }); + }); }); });