From 5ce84d4876245cc0c906d4ccae41bb706c09da67 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Mon, 13 Dec 2021 16:23:26 +0100 Subject: [PATCH] Test custom fromStyle --- src/style_manager/model/PropertyStack.js | 6 +++--- test/specs/style_manager/model/Properties.js | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/style_manager/model/PropertyStack.js b/src/style_manager/model/PropertyStack.js index 37ba9a937..1b346c2e4 100644 --- a/src/style_manager/model/PropertyStack.js +++ b/src/style_manager/model/PropertyStack.js @@ -168,12 +168,12 @@ export default Property.extend({ if (!hasProps) { return []; } else { + const sep = this.getLayerSeparator(); + const sepParts = this.getPartsSeparator(); const fromStyle = this.get('fromStyle'); - let result = fromStyle ? fromStyle(style, { property: this }) : []; + let result = fromStyle ? fromStyle(style, { property: this, separatorLayers: sep }) : []; if (!fromStyle) { - const sep = this.getLayerSeparator(); - const sepParts = this.getPartsSeparator(); // Get layers from the main property const layers = splitStyleName(style, name, sep) .map(value => value.split(sepParts)) diff --git a/test/specs/style_manager/model/Properties.js b/test/specs/style_manager/model/Properties.js index 711de73cf..0546fb8e7 100644 --- a/test/specs/style_manager/model/Properties.js +++ b/test/specs/style_manager/model/Properties.js @@ -159,6 +159,25 @@ describe('StyleManager properties logic', () => { ]); }); + test('Custom fromStyle', () => { + compTypeProp.set('fromStyle', (style, { separatorLayers }) => { + const layerValues = style[propTest].split(separatorLayers); + return layerValues.map(value => ({ value })); + }); + expect( + compTypeProp.__getLayersFromStyle({ + [propTest]: 'rgba(valueA-1, valueB-1), rgba(valueA-2, valueB-2)', + }) + ).toEqual([ + { + value: 'rgba(valueA-1, valueB-1)', + }, + { + value: 'rgba(valueA-2, valueB-2)', + }, + ]); + }); + test('Layers has the right values', () => { expect(compTypeProp.getLayer(0).getValues()).toEqual({ [propATest]: 'valueA-1',