mirror of
https://github.com/maputnik/editor.git
synced 2026-07-15 02:17:27 +00:00
f14eeae38b
## Launch Checklist This PR increases coverage by adding unit tests to lib folde, replace the skipped end to end placeholder with actual tests and adds more end to end tests. This was mostly done by AI (Claude opus 4.8) and I reviewed it and requested changes where needed. - [x] Briefly describe the changes in this PR. - [x] Link to related issues. - [x] Include before/after visuals or gifs if this PR includes visual changes. - [x] Write tests for all new functionality. - [x] Add an entry to `CHANGELOG.md` under the `## main` section. --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
import { describe, it, expect, vi } from "vitest";
|
|
import { LayerWatcher } from "./layerwatcher";
|
|
import type { Map } from "maplibre-gl";
|
|
|
|
function mockMap(): Map {
|
|
return {
|
|
style: {
|
|
tileManagers: {
|
|
vector: { _source: { vectorLayerIds: ["water", "roads"] } },
|
|
},
|
|
},
|
|
querySourceFeatures: () => [
|
|
{ properties: { class: "river", name: "A" } },
|
|
{ properties: { class: "canal" } },
|
|
],
|
|
} as unknown as Map;
|
|
}
|
|
|
|
describe("LayerWatcher", () => {
|
|
it("reports sources discovered on the map", () => {
|
|
const onSourcesChange = vi.fn();
|
|
const watcher = new LayerWatcher({ onSourcesChange });
|
|
|
|
watcher.analyzeMap(mockMap());
|
|
expect(onSourcesChange).toHaveBeenCalledOnce();
|
|
expect(watcher.sources).toEqual({ vector: ["water", "roads"] });
|
|
|
|
// Re-analyzing the same sources does not fire the callback again.
|
|
watcher.analyzeMap(mockMap());
|
|
expect(onSourcesChange).toHaveBeenCalledOnce();
|
|
});
|
|
|
|
it("collects vector layer field values from source features", () => {
|
|
const onVectorLayersChange = vi.fn();
|
|
const watcher = new LayerWatcher({ onVectorLayersChange });
|
|
|
|
const map = mockMap();
|
|
watcher.analyzeMap(map); // populates _sources
|
|
watcher.analyzeVectorLayerFields(map);
|
|
|
|
expect(onVectorLayersChange).toHaveBeenCalled();
|
|
expect(watcher.vectorLayers.water.class).toHaveProperty("river");
|
|
expect(watcher.vectorLayers.water.class).toHaveProperty("canal");
|
|
expect(watcher.vectorLayers.water.name).toHaveProperty("A");
|
|
});
|
|
});
|