Browse Source

Add and test getStyleFromLayers

up-style-manager
Artur Arseniev 5 years ago
parent
commit
84c1375dde
  1. 42
      src/style_manager/model/PropertyStack.js
  2. 9
      test/specs/style_manager/model/Properties.js

42
src/style_manager/model/PropertyStack.js

@ -20,9 +20,12 @@ export default Property.extend({
// Array of layers (which contain properties)
layers: [],
// The separator used to join layer values
// The separator used to split layer values
layerSeparator: ', ',
// The separator used to join layer values
layerJoin: ', ',
// Prepend new layers in the list
prepend: 0,
@ -74,6 +77,7 @@ export default Property.extend({
},
__upTargetsStyleProps(opts = {}) {
// TODO same as getStyleFromLayers
if (!this.isDetached()) {
const style = this.getProperties().reduce((acc, prop) => {
acc[prop.getName()] = '';
@ -269,8 +273,9 @@ export default Property.extend({
},
/**
* Get style object from layer values
* Get style object from layer
* @param {[Layer]} layer
* @returns {Object} Style object
*/
getStyleFromLayer(layer, opts = {}) {
const sep = this.get('separator');
@ -298,6 +303,39 @@ export default Property.extend({
: style;
},
/**
* Get style object from current layers
* @returns {Object} Style object
*/
getStyleFromLayers() {
let result = {};
const layers = this.getLayers();
const styles = layers.map(l => this.getStyleFromLayer(l));
styles.forEach(style => {
keys(style).map(key => {
if (!result[key]) result[key] = [];
result[key].push(style[key]);
});
});
keys(result).map(key => {
result[key] = result[key].join(this.__getJoinLayers());
});
if (!this.isDetached()) {
const style = this.getProperties().reduce((acc, prop) => {
acc[prop.getName()] = '';
return acc;
}, {});
result = { ...result, ...style };
}
return result;
},
__getJoinLayers() {
return this.get('layerJoin');
},
__getFullValue() {
if (this.get('detached')) return '';
const name = this.getName();

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

@ -178,6 +178,15 @@ describe('StyleManager properties logic', () => {
]);
});
test('getStyleFromLayers', () => {
expect(compTypeProp.getStyleFromLayers()).toEqual({
[propTest]: 'valueA-1 valueB-1 valueC-1-ext, valueA-2 valueB-2 valueC-2-ext',
[propATest]: '',
[propBTest]: '',
[propCTest]: '',
});
});
test('Layers has the right values', () => {
expect(compTypeProp.getLayer(0).getValues()).toEqual({
[propATest]: 'valueA-1',

Loading…
Cancel
Save