Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck committed Mar 9, 2021
1 parent e919bf2 commit 62743ff
Showing 1 changed file with 52 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ const defaultConfig = {

function createLayer(
layerOptions: Partial<VectorLayerDescriptor> = {},
sourceOptions: Partial<TiledSingleLayerVectorSourceDescriptor> = {}
sourceOptions: Partial<TiledSingleLayerVectorSourceDescriptor> = {},
isTimeAware: boolean = false
): TiledVectorLayer {
const sourceDescriptor: TiledSingleLayerVectorSourceDescriptor = {
type: SOURCE_TYPES.MVT_SINGLE_LAYER,
Expand All @@ -47,6 +48,14 @@ function createLayer(
...sourceOptions,
};
const mvtSource = new MVTSingleLayerVectorSource(sourceDescriptor);
if (isTimeAware) {
mvtSource.isTimeAware = async () => {
return true;
};
mvtSource.getApplyGlobalTime = () => {
return true;
};
}

const defaultLayerOptions = {
...layerOptions,
Expand Down Expand Up @@ -130,13 +139,49 @@ describe('syncData', () => {
sinon.assert.notCalled(syncContext2.stopLoading);
});

it('Should resync when changes to syncContext', async () => {
const layer1: TiledVectorLayer = createLayer({}, {}, true);
const syncContext1 = new MockSyncContext({
dataFilters: {
timeFilters: {
from: 'now',
to: '15m',
mode: 'relative',
},
},
});

await layer1.syncData(syncContext1);

const dataRequestDescriptor: DataRequestDescriptor = {
data: { ...defaultConfig },
dataId: 'source',
};
const layer2: TiledVectorLayer = createLayer(
{
__dataRequests: [dataRequestDescriptor],
},
{},
true
);
const syncContext2 = new MockSyncContext({
dataFilters: {
timeFilters: {
from: 'now',
to: '30m',
mode: 'relative',
},
},
});
await layer2.syncData(syncContext2);
// @ts-expect-error
sinon.assert.calledOnce(syncContext2.startLoading);
// @ts-expect-error
sinon.assert.calledOnce(syncContext2.stopLoading);
});

describe('Should resync when changes to source params: ', () => {
[
{ layerName: 'barfoo' },
{ urlTemplate: 'https://sub.example.com/{z}/{x}/{y}.pbf' },
{ minSourceZoom: 1 },
{ maxSourceZoom: 12 },
].forEach((changes) => {
[{ layerName: 'barfoo' }, { minSourceZoom: 1 }, { maxSourceZoom: 12 }].forEach((changes) => {
it(`change in ${Object.keys(changes).join(',')}`, async () => {
const layer1: TiledVectorLayer = createLayer({}, {});
const syncContext1 = new MockSyncContext({ dataFilters: {} });
Expand Down

0 comments on commit 62743ff

Please sign in to comment.