Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
bbecquet committed Sep 1, 2022
1 parent 0417ea1 commit db60905
Showing 1 changed file with 55 additions and 3 deletions.
58 changes: 55 additions & 3 deletions packages/react-core/__tests__/filters/tileFeatures.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { TILE_FORMATS } from '@deck.gl/carto';
import { geojsonToBinary } from '@loaders.gl/gis';
import { PagesSharp } from '@material-ui/icons';
import { tileFeatures } from '../../src';
import * as transformToTileCoords from '../../src/utils/transformToTileCoords';

Expand Down Expand Up @@ -350,7 +351,58 @@ describe('viewport features with binary mode', () => {
});

describe('uniqueIdProperty is undefined', () => {
describe('dataset has cartodb_id field', () => {
describe('tiles provide unique id field', () => {
test('linestrings', () => {
const linestrings = [...Array(3)].map((_, i) => ({
type: 'Feature',
geometry: {
type: 'LineString',
// prettier-ignore
coordinates: [[0, 0], [0, 1], [1, 2]]
},
properties: {
other_prop: i
}
}));

// Two tiles, linestrings[0] is present in both
const binaryData1 = geojsonToBinary([linestrings[0], linestrings[1]]);
// @ts-ignore
binaryData1.lines.fields = [{ id: 100 }, { id: 101 }];

const binaryData2 = geojsonToBinary([linestrings[0], linestrings[2]]);
// @ts-ignore
binaryData2.lines.fields = [{ id: 100 }, { id: 102 }];

const mockedTiles = [
{
isVisible: true,
data: binaryData1,
bbox: { west, east, north, south }
},
{
isVisible: true,
data: binaryData2,
bbox: { west, east, north, south }
}
];

const properties = tileFeatures({
tiles: mockedTiles,
viewport,
uniqueIdProperty: undefined
});

// prettier-ignore
expect(properties).toEqual([
{ 'other_prop': 0 },
{ 'other_prop': 1 },
{ 'other_prop': 2 }
]);
});
});

describe('features have cartodb_id field', () => {
test('points', () => {
const points = [...Array(3)].map((_, i) => ({
type: 'Feature',
Expand Down Expand Up @@ -386,7 +438,7 @@ describe('viewport features with binary mode', () => {
});
});

describe('dataset has geoid field', () => {
describe('features have geoid field', () => {
test('points', () => {
const points = [...Array(3)].map((_, i) => ({
type: 'Feature',
Expand Down Expand Up @@ -422,7 +474,7 @@ describe('viewport features with binary mode', () => {
});
});

describe('dataset has no cartodb_id or geoid fields', () => {
describe('no explicit id field', () => {
test('points', () => {
const points = [...Array(3)].map((_, i) => ({
type: 'Feature',
Expand Down

0 comments on commit db60905

Please sign in to comment.