Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck committed Aug 4, 2020
1 parent 4ac2740 commit a79903a
Showing 1 changed file with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,15 @@ describe('get mapbox color expression (via internal _getMbColor)', () => {
});

describe('custom color ramp', () => {
const dynamicStyleOptions = {
type: COLOR_MAP_TYPE.ORDINAL,
useCustomColorRamp: true,
customColorRamp: [
{ stop: 10, color: '#f7faff' },
{ stop: 100, color: '#072f6b' },
],
};

test('should return null when customColorRamp is not provided', async () => {
const dynamicStyleOptions = {
type: COLOR_MAP_TYPE.ORDINAL,
Expand All @@ -362,15 +371,7 @@ describe('get mapbox color expression (via internal _getMbColor)', () => {
expect(colorProperty._getMbColor()).toBeNull();
});

test('should return mapbox expression for custom color ramp', async () => {
const dynamicStyleOptions = {
type: COLOR_MAP_TYPE.ORDINAL,
useCustomColorRamp: true,
customColorRamp: [
{ stop: 10, color: '#f7faff' },
{ stop: 100, color: '#072f6b' },
],
};
test('should use `feature-state` by default', async () => {
const colorProperty = makeProperty(dynamicStyleOptions);
expect(colorProperty._getMbColor()).toEqual([
'step',
Expand All @@ -382,6 +383,23 @@ describe('get mapbox color expression (via internal _getMbColor)', () => {
'#072f6b',
]);
});

test('should use `get` when source cannot return raw geojson', async () => {
const field = Object.create(mockField);
field.canReadFromGeoJson = function () {
return false;
};
const colorProperty = makeProperty(dynamicStyleOptions, undefined, field);
expect(colorProperty._getMbColor()).toEqual([
'step',
['coalesce', ['get', 'foobar'], 9],
'rgba(0,0,0,0)',
10,
'#f7faff',
100,
'#072f6b',
]);
});
});
});

Expand Down

0 comments on commit a79903a

Please sign in to comment.