diff --git a/x-pack/legacy/plugins/maps/common/descriptor_types.d.ts b/x-pack/legacy/plugins/maps/common/descriptor_types.d.ts index afab0f83905708..e3738454e7e473 100644 --- a/x-pack/legacy/plugins/maps/common/descriptor_types.d.ts +++ b/x-pack/legacy/plugins/maps/common/descriptor_types.d.ts @@ -20,4 +20,5 @@ export interface IXYZTMSSourceDescriptor extends ISourceDescriptor { export interface ILayerDescriptor { sourceDescriptor: ISourceDescriptor; id: string; + label?: string; } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/xyz_tms_source.test.ts b/x-pack/legacy/plugins/maps/public/layers/sources/xyz_tms_source.test.ts index 5e7feb8a81b66b..5de85adde158ff 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/xyz_tms_source.test.ts +++ b/x-pack/legacy/plugins/maps/public/layers/sources/xyz_tms_source.test.ts @@ -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()); - }); }); diff --git a/x-pack/legacy/plugins/maps/public/layers/tile_layer.test.ts b/x-pack/legacy/plugins/maps/public/layers/tile_layer.test.ts new file mode 100644 index 00000000000000..f2b725ea132dde --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/tile_layer.test.ts @@ -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 { + return this._descriptor.urlTemplate; + } + + async getUrlTemplate(): Promise { + 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()); + }); +});