|
| 1 | +// eslint-disable-next-line @typescript-eslint/ban-ts-comment |
| 2 | +// @ts-nocheck |
| 3 | +import {describe, test, expect, waitFor} from '../../util/vitest'; |
| 4 | +import {mockFetch} from '../../util/network'; |
| 5 | +import Tiled3DModelSource from '../../../3d-style/source/tiled_3d_model_source'; |
| 6 | +import {Evented} from '../../../src/util/evented'; |
| 7 | +import {RequestManager} from '../../../src/util/mapbox'; |
| 8 | +import sourceFixture from '../../fixtures/source.json'; |
| 9 | + |
| 10 | +const wrapDispatcher = (dispatcher) => { |
| 11 | + return { |
| 12 | + getActor() { |
| 13 | + return dispatcher; |
| 14 | + }, |
| 15 | + ready: true |
| 16 | + }; |
| 17 | +}; |
| 18 | + |
| 19 | +const mockDispatcher = wrapDispatcher({ |
| 20 | + send() {} |
| 21 | +}); |
| 22 | + |
| 23 | +function createSource(options) { |
| 24 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument |
| 25 | + const source = new Tiled3DModelSource('id', options, mockDispatcher, new Evented()); |
| 26 | + |
| 27 | + source.onAdd({ |
| 28 | + getWorldview() { }, |
| 29 | + _getMapId: () => 1, |
| 30 | + _requestManager: new RequestManager(), |
| 31 | + _language: null, |
| 32 | + style: { |
| 33 | + clearSource: () => {} |
| 34 | + } |
| 35 | + }); |
| 36 | + |
| 37 | + source.on('error', (e) => { |
| 38 | + throw e.error; |
| 39 | + }); |
| 40 | + |
| 41 | + return source; |
| 42 | +} |
| 43 | + |
| 44 | +describe('Tiled3DModelSource', () => { |
| 45 | + test('can be constructed from TileJSON', async () => { |
| 46 | + const source = createSource({ |
| 47 | + type: 'batched-model', |
| 48 | + minzoom: 1, |
| 49 | + maxzoom: 10, |
| 50 | + attribution: "Mapbox", |
| 51 | + tiles: ["http://example.com/{z}/{x}/{y}.glb"] |
| 52 | + }); |
| 53 | + |
| 54 | + const e = await waitFor(source, "data"); |
| 55 | + if (e.sourceDataType === 'metadata') { |
| 56 | + expect(source.tiles).toEqual(["http://example.com/{z}/{x}/{y}.glb"]); |
| 57 | + expect(source.minzoom).toEqual(1); |
| 58 | + expect(source.maxzoom).toEqual(10); |
| 59 | + expect(source.attribution).toEqual("Mapbox"); |
| 60 | + } |
| 61 | + }); |
| 62 | + |
| 63 | + test('can be constructed from a TileJSON URL', async () => { |
| 64 | + mockFetch({ |
| 65 | + '/source.json': () => new Response(JSON.stringify(sourceFixture)) |
| 66 | + }); |
| 67 | + |
| 68 | + const source = createSource({ |
| 69 | + type: 'batched-model', |
| 70 | + url: "/source.json" |
| 71 | + }); |
| 72 | + |
| 73 | + const e = await waitFor(source, "data"); |
| 74 | + if (e.sourceDataType === 'metadata') { |
| 75 | + expect(source.tiles).toEqual(["http://example.com/{z}/{x}/{y}.png"]); |
| 76 | + expect(source.minzoom).toEqual(1); |
| 77 | + expect(source.maxzoom).toEqual(10); |
| 78 | + expect(source.attribution).toEqual("Mapbox"); |
| 79 | + } |
| 80 | + }); |
| 81 | +}); |
0 commit comments