Skip to content

Commit

Permalink
move test
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck committed Feb 26, 2020
1 parent 050ef14 commit 0fb3a68
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 9 deletions.
1 change: 1 addition & 0 deletions x-pack/legacy/plugins/maps/common/descriptor_types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ export interface IXYZTMSSourceDescriptor extends ISourceDescriptor {
export interface ILayerDescriptor {
sourceDescriptor: ISourceDescriptor;
id: string;
label?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,4 @@ describe('xyz Tilemap Source', () => {
const template = await source.getUrlTemplate();
expect(template).toEqual(descriptor.urlTemplate);
});

it('should echo url for diplay-name', async () => {
const source = new XYZTMSSource(descriptor, null);
const displayName = await source.getDisplayName();
expect(displayName).toEqual(descriptor.urlTemplate);

const layer: ILayer = source.createDefaultLayer();
expect(await layer.getDisplayName()).toEqual(await source.getDisplayName());
});
});
55 changes: 55 additions & 0 deletions x-pack/legacy/plugins/maps/public/layers/tile_layer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { TileLayer } from './tile_layer';
import { EMS_XYZ } from '../../common/constants';
import { IXYZTMSSourceDescriptor } from '../../common/descriptor_types';
import { ITMSSource } from './sources/tms_source';
import { ILayer } from './layer';

const sourceDescriptor: IXYZTMSSourceDescriptor = {
type: EMS_XYZ,
urlTemplate: 'https://example.com/{x}/{y}/{z}.png',
id: 'foobar',
};

class MockTileSource implements ITMSSource {
private _descriptor: IXYZTMSSourceDescriptor;
constructor(descriptor: IXYZTMSSourceDescriptor) {
this._descriptor = descriptor;
}
createDefaultLayer(): ILayer {
throw new Error('not implemented');
}

async getDisplayName(): Promise<string> {
return this._descriptor.urlTemplate;
}

async getUrlTemplate(): Promise<string> {
return 'template/{x}/{y}/{z}.png';
}
}

describe('xyz Tilemap Source', () => {
it('should use display-label from source', async () => {
const source = new MockTileSource(sourceDescriptor);
const layer: ILayer = new TileLayer({
source,
layerDescriptor: { id: 'layerid', sourceDescriptor },
});
expect(await source.getDisplayName()).toEqual(await layer.getDisplayName());
});

it('should override with custom display-label if present', async () => {
const source = new MockTileSource(sourceDescriptor);
const layer: ILayer = new TileLayer({
source,
layerDescriptor: { id: 'layerid', sourceDescriptor, label: 'custom' },
});
expect('custom').toEqual(await layer.getDisplayName());
});
});

0 comments on commit 0fb3a68

Please sign in to comment.