-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test for FormatSectionOverride expression
- Loading branch information
1 parent
e72fc5c
commit 4958eac
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { test } from 'mapbox-gl-js-test'; | ||
import { createExpression, ZoomConstantExpression } from '../../../src/style-spec/expression'; | ||
import EvaluationContext from '../../../src/style-spec/expression/evaluation_context'; | ||
import properties from '../../../src/style/style_layer/symbol_style_layer_properties'; | ||
import {PossiblyEvaluatedPropertyValue} from '../../../src/style/properties'; | ||
import FormatSectionOverride from '../../../src/style-spec/expression/definitions/format_section_override'; | ||
|
||
test('evaluate', (t) => { | ||
|
||
t.test('override constant', (t) => { | ||
const defaultColor = { "r": 0, "g": 1, "b": 0, "a": 1 }; | ||
const overridenColor = { "r": 1, "g": 0, "b": 0, "a": 1 }; | ||
const overriden = new PossiblyEvaluatedPropertyValue( | ||
properties.paint.properties['text-color'], | ||
{ kind: 'constant', value: defaultColor }, | ||
{zoom: 0, zoomHistory: {}} | ||
); | ||
|
||
const override = new FormatSectionOverride(overriden); | ||
const ctx = new EvaluationContext(); | ||
ctx.feature = {}; | ||
ctx.featureState = {}; | ||
t.deepEqual(override.evaluate(ctx), defaultColor); | ||
|
||
ctx.formattedSection = {textColor: overridenColor}; | ||
t.deepEqual(override.evaluate(ctx), overridenColor); | ||
|
||
t.end(); | ||
}); | ||
|
||
t.test('override expression', (t) => { | ||
const warn = console.warn; | ||
console.warn = (_) => {}; | ||
const defaultColor = { "r": 0, "g": 0, "b": 0, "a": 1 }; | ||
const propertyColor = { "r": 1, "g": 0, "b": 0, "a": 1 }; | ||
const overridenColor = { "r": 0, "g": 0, "b": 1, "a": 1 }; | ||
const styleExpr = createExpression( | ||
["get", "color"], | ||
properties.paint.properties['text-color'].specification); | ||
|
||
const sourceExpr = new ZoomConstantExpression('source', styleExpr.value); | ||
const overriden = new PossiblyEvaluatedPropertyValue( | ||
properties.paint.properties['text-color'], | ||
sourceExpr, | ||
{zoom: 0, zoomHistory: {}} | ||
); | ||
|
||
const override = new FormatSectionOverride(overriden); | ||
const ctx = new EvaluationContext(); | ||
ctx.feature = { properties: {}}; | ||
ctx.featureState = {}; | ||
|
||
t.deepEqual(override.evaluate(ctx), defaultColor); | ||
|
||
ctx.feature.properties.color = "red"; | ||
t.deepEqual(override.evaluate(ctx), propertyColor); | ||
|
||
ctx.formattedSection = {textColor: overridenColor}; | ||
t.deepEqual(override.evaluate(ctx), overridenColor); | ||
|
||
console.warn = warn; | ||
t.end(); | ||
}); | ||
|
||
t.end(); | ||
}); |