Skip to content

Commit

Permalink
test: style_guesser
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKreil committed Nov 27, 2023
1 parent df24dd4 commit 6e83505
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/lib/style_guesser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* eslint-disable @typescript-eslint/naming-convention */
import guessStyle from './style_guesser.js';
import type { VectorLayer } from './types.ts';

describe('guessStyle', () => {
const tiles = ['https://example.com/tiles/{z}/{x}/{y}'];

it('should build raster styles', () => {
const type = 'raster';
const format = 'avif';
expect(guessStyle({ type, tiles, format }))
.toStrictEqual({
version: 8,
sources: { rasterSource: { format, tilejson: '3.0.0', tiles, type } },
layers: [{ id: 'raster', source: 'rasterSource', type }],
});
});

it('should build vector styles', () => {
const type = 'vector';
const format = 'pbf';
const vector_layers: VectorLayer[] = [{ id: 'geometry', fields: { label: 'String', height: 'Number' } }];
expect(guessStyle({ type, tiles, format, vector_layers }))
.toStrictEqual({
version: 8,
sources: { vectorSource: { format, tilejson: '3.0.0', tiles, type, vector_layers } },
layers: [
{
id: 'background',
type: 'background',
paint: { 'background-color': '#fff' },
},
{
id: 'vectorSource-geometry-fill',
type: 'fill',
source: 'vectorSource',
'source-layer': 'geometry',
filter: ['==', '$type', 'Polygon'],
paint: { 'fill-antialias': true, 'fill-color': 'hsla(7,57%,56%,0.6)', 'fill-opacity': 0.3, 'fill-outline-color': 'hsla(7,57%,56%,0.6)' },
},
{
id: 'vectorSource-geometry-line',
type: 'line',
source: 'vectorSource',
'source-layer': 'geometry',
filter: ['==', '$type', 'LineString'],
layout: { 'line-cap': 'round', 'line-join': 'round' },
paint: { 'line-color': 'hsla(7,57%,56%,0.6)' },
},
{
id: 'vectorSource-geometry-circle',
type: 'circle',
source: 'vectorSource',
'source-layer': 'geometry',
filter: ['==', '$type', 'Point'],
paint: { 'circle-color': 'hsla(7,57%,56%,0.6)', 'circle-radius': 2 },
},
],
});
});
});

0 comments on commit 6e83505

Please sign in to comment.