1 | import {createExpression, StyleExpression, ZoomConstantExpression} from '../style-spec/expression';
|
2 | import EvaluationContext from '../style-spec/expression/evaluation_context';
|
3 | import properties from './style_layer/symbol_style_layer_properties.g';
|
4 | import {PossiblyEvaluatedPropertyValue} from './properties';
|
5 | import FormatSectionOverride from './format_section_override';
|
6 | import EvaluationParameters from './evaluation_parameters';
|
7 | import {FormattedSection} from '../style-spec/expression/types/formatted';
|
8 |
|
9 | describe('evaluate', () => {
|
10 |
|
11 | test('override constant', () => {
|
12 | const defaultColor = {'r': 0, 'g': 1, 'b': 0, 'a': 1};
|
13 | const overridenColor = {'r': 1, 'g': 0, 'b': 0, 'a': 1};
|
14 | const overriden = new PossiblyEvaluatedPropertyValue(
|
15 | properties.paint.properties['text-color'],
|
16 | {kind: 'constant', value: defaultColor},
|
17 | {zoom: 0, zoomHistory: {}} as EvaluationParameters
|
18 | );
|
19 |
|
20 | const override = new FormatSectionOverride(overriden);
|
21 | const ctx = new EvaluationContext();
|
22 | ctx.feature = {} as any;
|
23 | ctx.featureState = {};
|
24 | expect(override.evaluate(ctx)).toEqual(defaultColor);
|
25 |
|
26 | ctx.formattedSection = {textColor: overridenColor} as FormattedSection;
|
27 | expect(override.evaluate(ctx)).toEqual(overridenColor);
|
28 |
|
29 | });
|
30 |
|
31 | test('override expression', () => {
|
32 | const warn = console.warn;
|
33 | console.warn = (_) => {};
|
34 | const defaultColor = {'r': 0, 'g': 0, 'b': 0, 'a': 1};
|
35 | const propertyColor = {'r': 1, 'g': 0, 'b': 0, 'a': 1};
|
36 | const overridenColor = {'r': 0, 'g': 0, 'b': 1, 'a': 1};
|
37 | const styleExpr = createExpression(
|
38 | ['get', 'color'],
|
39 | properties.paint.properties['text-color'].specification);
|
40 |
|
41 | const sourceExpr = new ZoomConstantExpression('source', styleExpr.value as StyleExpression);
|
42 | const overriden = new PossiblyEvaluatedPropertyValue(
|
43 | properties.paint.properties['text-color'],
|
44 | sourceExpr,
|
45 | {zoom: 0, zoomHistory: {}} as EvaluationParameters
|
46 | );
|
47 |
|
48 | const override = new FormatSectionOverride(overriden);
|
49 | const ctx = new EvaluationContext();
|
50 | ctx.feature = {properties: {}} as any;
|
51 | ctx.featureState = {};
|
52 |
|
53 | expect(override.evaluate(ctx)).toEqual(defaultColor);
|
54 |
|
55 | ctx.feature.properties.color = 'red';
|
56 | expect(override.evaluate(ctx)).toEqual(propertyColor);
|
57 |
|
58 | ctx.formattedSection = {textColor: overridenColor} as FormattedSection;
|
59 | expect(override.evaluate(ctx)).toEqual(overridenColor);
|
60 |
|
61 | console.warn = warn;
|
62 | });
|
63 |
|
64 | });
|