-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Maps] Add XYZTMSSource and TileLayer unit test suites (#58567)
- Loading branch information
1 parent
853b2a5
commit 827b83d
Showing
10 changed files
with
177 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* 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 { ILayerDescriptor } from '../../common/descriptor_types'; | ||
import { ISource } from './sources/source'; | ||
|
||
export interface ILayer { | ||
getDisplayName(): Promise<string>; | ||
} | ||
|
||
export interface ILayerArguments { | ||
layerDescriptor: ILayerDescriptor; | ||
source: ISource; | ||
} | ||
|
||
export class AbstractLayer implements ILayer { | ||
constructor(layerArguments: ILayerArguments); | ||
getDisplayName(): Promise<string>; | ||
} |
19 changes: 19 additions & 0 deletions
19
x-pack/legacy/plugins/maps/public/layers/sources/source.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* 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 { ISourceDescriptor } from '../../../common/descriptor_types'; | ||
import { ILayer } from '../layer'; | ||
|
||
export interface ISource { | ||
createDefaultLayer(): ILayer; | ||
getDisplayName(): Promise<string>; | ||
} | ||
|
||
export class AbstractSource implements ISource { | ||
constructor(sourceDescriptor: ISourceDescriptor, inspectorAdapters: object); | ||
createDefaultLayer(): ILayer; | ||
getDisplayName(): Promise<string>; | ||
} |
15 changes: 15 additions & 0 deletions
15
x-pack/legacy/plugins/maps/public/layers/sources/tms_source.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* 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 { AbstractSource, ISource } from './source'; | ||
|
||
export interface ITMSSource extends ISource { | ||
getUrlTemplate(): Promise<string>; | ||
} | ||
|
||
export class AbstractTMSSource extends AbstractSource implements ITMSSource { | ||
getUrlTemplate(): Promise<string>; | ||
} |
11 changes: 11 additions & 0 deletions
11
x-pack/legacy/plugins/maps/public/layers/sources/xyz_tms_source.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* 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 { AbstractTMSSource } from './tms_source'; | ||
import { IXYZTMSSourceDescriptor } from '../../../common/descriptor_types'; | ||
|
||
export class XYZTMSSource extends AbstractTMSSource { | ||
constructor(sourceDescriptor: IXYZTMSSourceDescriptor, inspectorAdapters: unknown); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
x-pack/legacy/plugins/maps/public/layers/sources/xyz_tms_source.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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 { XYZTMSSource } from './xyz_tms_source'; | ||
import { ILayer } from '../layer'; | ||
import { TileLayer } from '../tile_layer'; | ||
import { EMS_XYZ } from '../../../common/constants'; | ||
import { IXYZTMSSourceDescriptor } from '../../../common/descriptor_types'; | ||
|
||
const descriptor: IXYZTMSSourceDescriptor = { | ||
type: EMS_XYZ, | ||
urlTemplate: 'https://example.com/{x}/{y}/{z}.png', | ||
id: 'foobar', | ||
}; | ||
describe('xyz Tilemap Source', () => { | ||
it('should create a tile-layer', () => { | ||
const source = new XYZTMSSource(descriptor, null); | ||
const layer: ILayer = source.createDefaultLayer(); | ||
expect(layer instanceof TileLayer).toEqual(true); | ||
}); | ||
|
||
it('should echo url template for url template', async () => { | ||
const source = new XYZTMSSource(descriptor, null); | ||
const template = await source.getUrlTemplate(); | ||
expect(template).toEqual(descriptor.urlTemplate); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* 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 { AbstractLayer, ILayerArguments } from './layer'; | ||
import { ITMSSource } from './sources/tms_source'; | ||
import { ILayerDescriptor } from '../../common/descriptor_types'; | ||
|
||
interface ITileLayerArguments extends ILayerArguments { | ||
source: ITMSSource; | ||
layerDescriptor: ILayerDescriptor; | ||
} | ||
|
||
export class TileLayer extends AbstractLayer { | ||
constructor(args: ITileLayerArguments); | ||
} |
55 changes: 55 additions & 0 deletions
55
x-pack/legacy/plugins/maps/public/layers/tile_layer.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('TileLayer', () => { | ||
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()); | ||
}); | ||
}); |