|
| 1 | +import {describe, test, expect, vi} from 'vitest'; |
| 2 | +import {type LayerSpecification} from '@maplibre/maplibre-gl-style-spec'; |
| 3 | +import {createStyleLayer} from '../create_style_layer'; |
| 4 | +import {extend} from '../../util/util'; |
| 5 | + |
| 6 | +function createLayerSpec(properties?): LayerSpecification { |
| 7 | + return extend({ |
| 8 | + type: 'raster', |
| 9 | + id: 'raster', |
| 10 | + source: 'rasterSource' |
| 11 | + }, properties); |
| 12 | +} |
| 13 | + |
| 14 | +describe('RasterStyleLayer correctly handles "resampling" and "raster-resampling" paint properties', () => { |
| 15 | + |
| 16 | + test('"raster-resampling" is undefined when instantiated with "resampling"', () => { |
| 17 | + const layerSpec = createLayerSpec(); |
| 18 | + const layer = createStyleLayer(layerSpec, {}); |
| 19 | + |
| 20 | + const rasterResampling = layer.getPaintProperty('raster-resampling'); |
| 21 | + expect(rasterResampling).toEqual(undefined); |
| 22 | + }); |
| 23 | + |
| 24 | + test('"resampling" is undefined when instantiated with "raster-resampling"', () => { |
| 25 | + const layerSpec = createLayerSpec(); |
| 26 | + const layer = createStyleLayer(layerSpec, {}); |
| 27 | + |
| 28 | + const resampling = layer.getPaintProperty('resampling'); |
| 29 | + expect(resampling).toEqual(undefined); |
| 30 | + }); |
| 31 | + |
| 32 | + test('warns when both "resampling" and "raster-resampling" are specified upon instantiation', () => { |
| 33 | + const originalWarn = console.warn; |
| 34 | + console.warn = vi.fn(); |
| 35 | + |
| 36 | + const layerSpec = createLayerSpec({ |
| 37 | + paint: { |
| 38 | + resampling: 'nearest', |
| 39 | + 'raster-resampling': 'nearest', |
| 40 | + } |
| 41 | + }); |
| 42 | + createStyleLayer(layerSpec, {}); |
| 43 | + expect(console.warn).toHaveBeenCalledTimes(1); |
| 44 | + console.warn = originalWarn; |
| 45 | + }); |
| 46 | + |
| 47 | +}); |
0 commit comments