mirror of
https://github.com/maputnik/editor.git
synced 2026-12-04 15:54:24 +00:00
Fixes #805. The Data Sources editor had no way to set `generateId` or `promoteId`, so these had to be added by hand in the style JSON. This adds a `SourceFeatureIdFields` block under the existing fields for GeoJSON and vector sources: - GeoJSON (inline and URL): a **Generate feature IDs** checkbox and a **Feature ID property** field. As the issue points out, the two are mutually exclusive, so turning one on clears the other. - Vector (TileJSON, tile URLs and PMTiles): a **Feature ID property** field for a single property, and a **Feature ID properties by source layer** JSON field for the per-layer form (`{"roads": "road_id"}`). An object that doesn't map names to strings shows an error and isn't saved. Edits keep the rest of the source configuration. | Before | After | |---|---| |  |  | Both show the Data Sources modal with an inline GeoJSON source and a vector tile source, in Chromium. **Open question:** the issue asked how the UI should look, and nobody had decided yet. For vector sources I used two fields because `promoteId` can be either a string or an object. Setting the single property replaces a per-layer mapping, and the other way round. If you'd prefer one field, for example a single JSON field, I can change that. **Performance:** none. The fields only render inside the Data Sources modal, for GeoJSON and vector sources. ## Launch Checklist - [x] Briefly describe the changes in this PR. - [x] Link to related issues: fixes #805. - [x] Include before/after visuals or gifs if this PR includes visual changes. - [x] Write tests for all new functionality: three e2e tests in `modals.spec.ts` (generate IDs for a new GeoJSON source, set a vector source's ID property, save a per-layer mapping). I ran the GeoJSON one against `main` and it fails; the other two look for fields that don't exist on `main`. - [x] Add an entry to `CHANGELOG.md` under the `## main` section. Tested locally: `npm run lint` clean, `npx tsc --noEmit` clean, `npx vitest run` (57 passed) and `npx playwright test e2e/modals.spec.ts` (64 passed). I also checked that focusing and leaving the empty "Feature ID property" field keeps an existing per-layer mapping. I didn't run the full e2e suite locally (it times out on Windows with several workers); it passes in CI on this PR. Assisted-By: Claude Opus 5.5 (Claude Code). It helped write the change, the tests and this description. I've reviewed and tested the change and can answer questions about it.
713 lines
26 KiB
TypeScript
713 lines
26 KiB
TypeScript
import { test, expect, describe, beforeEach } from "./utils/fixtures";
|
|
import { MaputnikDriver } from "./maputnik-driver";
|
|
import tokens from "../src/config/tokens.json" with { type: "json" };
|
|
|
|
describe("modals", () => {
|
|
const { given, get, when, then } = new MaputnikDriver();
|
|
|
|
beforeEach(async () => {
|
|
await given.setupMockBackedResponses();
|
|
await when.setStyle("both");
|
|
await when.setStyle("");
|
|
});
|
|
|
|
describe("open", () => {
|
|
beforeEach(async () => {
|
|
await when.click("nav:open");
|
|
});
|
|
|
|
test("close", async () => {
|
|
await when.modal.close("modal:open");
|
|
await then(get.elementByTestId("modal:open")).shouldNotExist();
|
|
});
|
|
|
|
test("upload", async () => {
|
|
await when.chooseExampleFile();
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude(get.fixture("example-style.json"));
|
|
});
|
|
|
|
test("upload via drag and drop", async () => {
|
|
await when.dropExampleFile();
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude(get.fixture("example-style.json"));
|
|
});
|
|
|
|
describe("when click open url", () => {
|
|
beforeEach(async () => {
|
|
const styleFileUrl = get.exampleFileUrl();
|
|
|
|
await when.setValue("modal:open.url.input", styleFileUrl);
|
|
await when.click("modal:open.url.button");
|
|
await when.wait(200);
|
|
});
|
|
test("load from url", async () => {
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude(get.responseBody("example-style.json"));
|
|
});
|
|
});
|
|
|
|
describe("without the File System Access API", () => {
|
|
test("upload via the file chooser", async () => {
|
|
await given.noFileSystemAccessApi();
|
|
await when.setStyle("");
|
|
await when.click("nav:open");
|
|
await when.chooseExampleFileFromPicker();
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude(get.fixture("example-style.json"));
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("shortcuts", () => {
|
|
test("open/close", async () => {
|
|
await when.setStyle("");
|
|
await when.typeKeys("?");
|
|
await when.modal.close("modal:shortcuts");
|
|
await then(get.elementByTestId("modal:shortcuts")).shouldNotExist();
|
|
});
|
|
});
|
|
|
|
describe("debug", () => {
|
|
beforeEach(async () => {
|
|
await when.setStyle("zoom_7_center_0_51");
|
|
await then(get.locationHash()).shouldInclude("#7/51/0");
|
|
await when.typeKeys("!");
|
|
});
|
|
|
|
test("max zoom is empty until the user sets it", async () => {
|
|
await then(get.elementByTestId("modal:debug.max-zoom")).shouldHaveValue("");
|
|
});
|
|
|
|
test("lowering the max zoom zooms the map out to it", async () => {
|
|
await when.setValue("modal:debug.max-zoom", "3");
|
|
await then(get.locationHash()).shouldInclude("#3/51/0");
|
|
});
|
|
|
|
test("typing a multi-digit max zoom keeps the map in place", async () => {
|
|
await when.type("modal:debug.max-zoom", "{selectall}{backspace}22");
|
|
// Let the debounced update reach the map
|
|
await when.wait(1000);
|
|
await then(get.locationHash()).shouldInclude("#7/51/0");
|
|
});
|
|
});
|
|
|
|
describe("debug with a renderer other than mlgljs or ol", () => {
|
|
test("shows the map options", async () => {
|
|
await when.setStyle("mbgljs_renderer");
|
|
await when.typeKeys("!");
|
|
await then(get.elementByTestId("modal:debug.max-zoom")).shouldBeVisible();
|
|
});
|
|
});
|
|
|
|
describe("export", () => {
|
|
beforeEach(async () => {
|
|
await when.click("nav:export");
|
|
});
|
|
|
|
test("close", async () => {
|
|
await when.modal.close("modal:export");
|
|
await then(get.elementByTestId("modal:export")).shouldNotExist();
|
|
});
|
|
|
|
test("download HTML and save the style", async () => {
|
|
// Generate the standalone HTML export (triggers a file download).
|
|
await when.modal.exportCreateHtml();
|
|
await then(get.elementByTestId("modal:export")).shouldExist();
|
|
|
|
// Saving the style closes the export modal.
|
|
await when.modal.exportSaveStyle();
|
|
await then(get.elementByTestId("modal:export")).shouldNotExist();
|
|
});
|
|
});
|
|
|
|
describe("sources", () => {
|
|
beforeEach(async () => {
|
|
await when.setStyle("layer");
|
|
await when.click("nav:sources");
|
|
});
|
|
|
|
test("active sources are listed and can be deleted", async () => {
|
|
await when.setStyle("both");
|
|
await when.click("nav:sources");
|
|
const before = Object.keys(get.fixture("geojson-raster-style.json").sources).length;
|
|
await when.modal.deleteFirstActiveSource();
|
|
await then(
|
|
get.styleFromLocalStorage().then((style) => Object.keys(style.sources).length)
|
|
).shouldEqual(before - 1);
|
|
});
|
|
|
|
test("public source", async () => {
|
|
await when.modal.addPublicSource();
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
sources: {
|
|
openmaptiles: {
|
|
type: "vector",
|
|
url: `https://api.maptiler.com/tiles/v3-openmaptiles/tiles.json?key=${tokens.openmaptiles}`,
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
test("add new source", async () => {
|
|
const sourceId = "n1z2v3r";
|
|
await when.setValue("modal:sources.add.source_id", sourceId);
|
|
await when.select("modal:sources.add.source_type", "tile_vector");
|
|
await when.select("modal:sources.add.scheme_type", "tms");
|
|
await when.click("modal:sources.add.add_source");
|
|
await when.wait(200);
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
sources: { [sourceId]: { scheme: "tms" } },
|
|
});
|
|
});
|
|
|
|
test("add new pmtiles source", async () => {
|
|
const sourceId = "pmtilestest";
|
|
await when.setValue("modal:sources.add.source_id", sourceId);
|
|
await when.select("modal:sources.add.source_type", "pmtiles_vector");
|
|
await when.setValue(
|
|
"modal:sources.add.source_url",
|
|
"https://data.source.coop/protomaps/openstreetmap/v4.pmtiles"
|
|
);
|
|
await when.click("modal:sources.add.add_source");
|
|
await when.click("modal:sources.add.add_source");
|
|
await when.wait(200);
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
sources: {
|
|
pmtilestest: {
|
|
type: "vector",
|
|
url: "pmtiles://https://data.source.coop/protomaps/openstreetmap/v4.pmtiles",
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
test("add new raster source", async () => {
|
|
const sourceId = "rastertest";
|
|
await when.setValue("modal:sources.add.source_id", sourceId);
|
|
await when.select("modal:sources.add.source_type", "tile_raster");
|
|
await when.select("modal:sources.add.scheme_type", "xyz");
|
|
await when.setValue("modal:sources.add.tile_size", "128");
|
|
await when.click("modal:sources.add.add_source");
|
|
await when.wait(200);
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
sources: { [sourceId]: { tileSize: 128 } },
|
|
});
|
|
});
|
|
|
|
test("add new geojson url source", async () => {
|
|
await when.modal.addSource("geojsonurl", "geojson_url");
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
sources: {
|
|
geojsonurl: { type: "geojson", data: "http://localhost:3000/geojson.json" },
|
|
},
|
|
});
|
|
});
|
|
|
|
test("add new geojson json source", async () => {
|
|
await when.modal.addSource("geojsonjson", "geojson_json");
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
sources: {
|
|
geojsonjson: { type: "geojson", cluster: false, data: "" },
|
|
},
|
|
});
|
|
});
|
|
|
|
test("generate feature IDs for a GeoJSON source", async () => {
|
|
const sourceId = "generated-feature-ids";
|
|
await when.setValue("modal:sources.add.source_id", sourceId);
|
|
await when.select("modal:sources.add.source_type", "geojson_url");
|
|
await when.modal.enableGeneratedFeatureIds();
|
|
await when.click("modal:sources.add.add_source");
|
|
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
sources: { [sourceId]: { type: "geojson", generateId: true } },
|
|
});
|
|
});
|
|
|
|
test("promote a vector source feature property to its ID", async () => {
|
|
const sourceId = "promoted-feature-ids";
|
|
await when.modal.addSource(sourceId, "tilejson_vector");
|
|
await when.modal.setFeatureIdProperty(sourceId, "feature_id");
|
|
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
sources: { [sourceId]: { type: "vector", promoteId: "feature_id" } },
|
|
});
|
|
});
|
|
|
|
test("promote different ID properties for different vector source layers", async () => {
|
|
const sourceId = "layer-feature-ids";
|
|
await when.setValue("modal:sources.add.source_id", sourceId);
|
|
await when.select("modal:sources.add.source_type", "tilejson_vector");
|
|
await when.modal.setNewSourceFeatureIdMapping({ roads: "road_id", places: "place_id" });
|
|
await when.click("modal:sources.add.add_source");
|
|
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
sources: { [sourceId]: { type: "vector", promoteId: { roads: "road_id", places: "place_id" } } },
|
|
});
|
|
});
|
|
|
|
test("add new tilejson vector source", async () => {
|
|
await when.modal.addSource("tilejsonvector", "tilejson_vector");
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
sources: {
|
|
tilejsonvector: { type: "vector", url: "http://localhost:3000/tilejson.json" },
|
|
},
|
|
});
|
|
});
|
|
|
|
test("add new tilejson raster source", async () => {
|
|
await when.modal.addSource("tilejsonraster", "tilejson_raster");
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
sources: {
|
|
tilejsonraster: { type: "raster", url: "http://localhost:3000/tilejson.json" },
|
|
},
|
|
});
|
|
});
|
|
|
|
test("add new tilejson raster-dem source", async () => {
|
|
await when.modal.addSource("tilejsonrasterdem", "tilejson_raster-dem");
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
sources: {
|
|
tilejsonrasterdem: { type: "raster-dem", url: "http://localhost:3000/tilejson.json" },
|
|
},
|
|
});
|
|
});
|
|
|
|
test("add new tile xyz raster-dem source", async () => {
|
|
await when.modal.addSource("tilexyzrasterdem", "tilexyz_raster-dem");
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
sources: {
|
|
tilexyzrasterdem: {
|
|
type: "raster-dem",
|
|
tiles: ["http://localhost:3000/{x}/{y}/{z}.png"],
|
|
minzoom: 0,
|
|
maxzoom: 14,
|
|
tileSize: 512,
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
test("add new image source", async () => {
|
|
await when.modal.addSource("imagesource", "image");
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
sources: {
|
|
imagesource: {
|
|
type: "image",
|
|
url: "http://localhost:3000/image.png",
|
|
coordinates: [[0, 0], [0, 0], [0, 0], [0, 0]],
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
test("add new video source", async () => {
|
|
await when.modal.addSource("videosource", "video");
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
sources: {
|
|
videosource: {
|
|
type: "video",
|
|
urls: ["http://localhost:3000/movie.mp4"],
|
|
coordinates: [[0, 0], [0, 0], [0, 0], [0, 0]],
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
test("edit the corner coordinates of an image source", async () => {
|
|
const sourceId = "imagecoords";
|
|
await when.setValue("modal:sources.add.source_id", sourceId);
|
|
await when.select("modal:sources.add.source_type", "image");
|
|
// The first corner is the first two number boxes of the coordinate arrays.
|
|
await when.modal.setCoordinateValue(0, "1");
|
|
await when.modal.setCoordinateValue(1, "2");
|
|
await when.click("modal:sources.add.add_source");
|
|
await when.wait(200);
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
sources: {
|
|
[sourceId]: { type: "image", coordinates: [[1, 2], [0, 0], [0, 0], [0, 0]] },
|
|
},
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("inspect", () => {
|
|
test("toggle", async () => {
|
|
// There is no assertion in this test
|
|
await when.setStyle("geojson");
|
|
await when.select("maputnik-select", "inspect");
|
|
});
|
|
});
|
|
|
|
describe("style settings", () => {
|
|
beforeEach(async () => {
|
|
await when.click("nav:settings");
|
|
});
|
|
|
|
describe("when click name filed spec information", () => {
|
|
beforeEach(async () => {
|
|
await when.click("field-doc-button-Name");
|
|
});
|
|
|
|
test("should show the spec information", async () => {
|
|
await then(get.elementsText("spec-field-doc")).shouldInclude("name for the style");
|
|
});
|
|
});
|
|
|
|
describe("when set name and click owner", () => {
|
|
beforeEach(async () => {
|
|
await when.setValue("modal:settings.name", "foobar");
|
|
await when.click("modal:settings.owner");
|
|
await when.wait(200);
|
|
});
|
|
|
|
test("show name specifications", async () => {
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
name: "foobar",
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("when set owner and click name", () => {
|
|
beforeEach(async () => {
|
|
await when.setValue("modal:settings.owner", "foobar");
|
|
await when.click("modal:settings.name");
|
|
await when.wait(200);
|
|
});
|
|
test("should update owner in local storage", async () => {
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
owner: "foobar",
|
|
});
|
|
});
|
|
});
|
|
|
|
test("sprite url", async () => {
|
|
await when.setTextInJsonEditor('"http://example.com"');
|
|
await when.click("modal:settings.name");
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
sprite: "http://example.com",
|
|
});
|
|
});
|
|
|
|
test("sprite object", async () => {
|
|
await when.setTextInJsonEditor(JSON.stringify([{ id: "1", url: "2" }]));
|
|
|
|
await when.click("modal:settings.name");
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
sprite: [{ id: "1", url: "2" }],
|
|
});
|
|
});
|
|
|
|
test("glyphs url", async () => {
|
|
const glyphsUrl = "http://example.com/{fontstack}/{range}.pbf";
|
|
await when.setValue("modal:settings.glyphs", glyphsUrl);
|
|
await when.click("modal:settings.name");
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
glyphs: glyphsUrl,
|
|
});
|
|
});
|
|
|
|
test("font faces", async () => {
|
|
const fontFaces = { "Noto Sans Regular": [{ url: "http://example.com/font.ttf", "unicode-range": ["U+1780-17FF"] }] };
|
|
await when.setTextInJsonEditor(JSON.stringify(fontFaces), "modal:settings.font-faces");
|
|
await when.click("modal:settings.name");
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
"font-faces": fontFaces,
|
|
});
|
|
});
|
|
|
|
test("unset font faces show an empty editor without errors", async () => {
|
|
await when.wait(1000);
|
|
await then(get.jsonEditorErrors("modal:settings.font-faces")).shouldNotExist();
|
|
|
|
await when.setTextInJsonEditor(JSON.stringify({ Font: "http://example.com/font.ttf" }), "modal:settings.font-faces");
|
|
await when.click("modal:settings.name");
|
|
await when.setTextInJsonEditor("", "modal:settings.font-faces");
|
|
await when.typeKeys("{backspace}");
|
|
await when.click("modal:settings.name");
|
|
await when.wait(1000);
|
|
await then(get.jsonEditorErrors("modal:settings.font-faces")).shouldNotExist();
|
|
await then(get.styleFromLocalStorage()).shouldNotHaveProperty("font-faces");
|
|
});
|
|
|
|
test("maptiler access token", async () => {
|
|
const apiKey = "testing123";
|
|
await when.setValue("modal:settings.maputnik:openmaptiles_access_token", apiKey);
|
|
await when.click("modal:settings.name");
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
metadata: { "maputnik:openmaptiles_access_token": apiKey },
|
|
});
|
|
});
|
|
|
|
test("thunderforest access token", async () => {
|
|
const apiKey = "testing123";
|
|
await when.setValue("modal:settings.maputnik:thunderforest_access_token", apiKey);
|
|
await when.click("modal:settings.name");
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
metadata: { "maputnik:thunderforest_access_token": apiKey },
|
|
});
|
|
});
|
|
|
|
test("stadia access token", async () => {
|
|
const apiKey = "testing123";
|
|
await when.setValue("modal:settings.maputnik:stadia_access_token", apiKey);
|
|
await when.click("modal:settings.name");
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
metadata: { "maputnik:stadia_access_token": apiKey },
|
|
});
|
|
});
|
|
|
|
test("locationiq access token", async () => {
|
|
const apiKey = "testing123";
|
|
await when.setValue("modal:settings.maputnik:locationiq_access_token", apiKey);
|
|
await when.click("modal:settings.name");
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
metadata: { "maputnik:locationiq_access_token": apiKey },
|
|
});
|
|
});
|
|
|
|
test("map view defaults", async () => {
|
|
await when.setValue("modal:settings.zoom", "4");
|
|
await when.setValue("modal:settings.bearing", "12");
|
|
await when.setValue("modal:settings.pitch", "30");
|
|
await when.setValue("modal:settings.roll", "15");
|
|
await when.setValue("modal:settings.center-altitude", "100");
|
|
await when.click("modal:settings.name");
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
zoom: 4,
|
|
bearing: 12,
|
|
pitch: 30,
|
|
roll: 15,
|
|
centerAltitude: 100,
|
|
});
|
|
});
|
|
|
|
test("sky and fog blends", async () => {
|
|
await when.setValue("modal:settings.sky-horizon-blend", "0.3");
|
|
await when.setValue("modal:settings.fog-ground-blend", "0.2");
|
|
await when.click("modal:settings.name");
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
sky: { "sky-horizon-blend": 0.3, "fog-ground-blend": 0.2 },
|
|
});
|
|
});
|
|
|
|
test("light intensity", async () => {
|
|
await when.setValue("modal:settings.light-intensity", "0.7");
|
|
await when.click("modal:settings.name");
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
light: { intensity: 0.7 },
|
|
});
|
|
});
|
|
|
|
test("terrain source and exaggeration", async () => {
|
|
await when.setValue("modal:settings.maputnik:terrain_source", "terrain");
|
|
await when.setValue("modal:settings.terrain-exaggeration", "1.5");
|
|
await when.click("modal:settings.name");
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
terrain: { source: "terrain", exaggeration: 1.5 },
|
|
});
|
|
});
|
|
|
|
test("transition delay and duration", async () => {
|
|
await when.setValue("modal:settings.transition-delay", "100");
|
|
await when.setValue("modal:settings.transition-duration", "500");
|
|
await when.click("modal:settings.name");
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
transition: { delay: 100, duration: 500 },
|
|
});
|
|
});
|
|
|
|
test("style projection mercator", async () => {
|
|
await when.select("modal:settings.projection", "mercator");
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
projection: { type: "mercator" },
|
|
});
|
|
});
|
|
|
|
test("style projection globe", async () => {
|
|
await when.select("modal:settings.projection", "globe");
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
projection: { type: "globe" },
|
|
});
|
|
});
|
|
|
|
test("style projection vertical-perspective", async () => {
|
|
await when.select("modal:settings.projection", "vertical-perspective");
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
projection: { type: "vertical-perspective" },
|
|
});
|
|
});
|
|
|
|
test("style renderer", async () => {
|
|
await when.select("modal:settings.maputnik:renderer", "ol");
|
|
await then(get.inputValue("modal:settings.maputnik:renderer")).shouldEqual("ol");
|
|
|
|
await when.click("modal:settings.name");
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
metadata: { "maputnik:renderer": "ol" },
|
|
});
|
|
});
|
|
|
|
test("include API key when change renderer", async () => {
|
|
await when.click("modal:settings.close-modal");
|
|
await when.click("nav:open");
|
|
|
|
await when.clickByAttribute("aria-label", "MapTiler Basic");
|
|
await when.wait(1000);
|
|
await when.click("nav:settings");
|
|
|
|
await when.select("modal:settings.maputnik:renderer", "mlgljs");
|
|
await then(get.inputValue("modal:settings.maputnik:renderer")).shouldEqual("mlgljs");
|
|
|
|
await when.select("modal:settings.maputnik:renderer", "ol");
|
|
await then(get.inputValue("modal:settings.maputnik:renderer")).shouldEqual("ol");
|
|
|
|
await given.intercept(
|
|
/https:\/\/api\.maptiler\.com\/tiles\/v3-openmaptiles\/tiles\.json\?key=.*/,
|
|
"tileRequest",
|
|
"GET"
|
|
);
|
|
|
|
await when.select("modal:settings.maputnik:renderer", "mlgljs");
|
|
await then(get.inputValue("modal:settings.maputnik:renderer")).shouldEqual("mlgljs");
|
|
|
|
const request = await when.waitForResponse("tileRequest");
|
|
expect(request.url()).toContain(
|
|
`https://api.maptiler.com/tiles/v3-openmaptiles/tiles.json?key=${tokens.openmaptiles}`
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("add layer", () => {
|
|
beforeEach(async () => {
|
|
await when.setStyle("layer");
|
|
await when.modal.open();
|
|
});
|
|
|
|
test("shows duplicate id error", async () => {
|
|
await when.setValue("add-layer.layer-id.input", "background");
|
|
await when.click("add-layer");
|
|
await then(get.elementByTestId("modal:add-layer")).shouldExist();
|
|
await then(get.element(".maputnik-modal-error")).shouldContainText("Layer ID already exists");
|
|
});
|
|
});
|
|
|
|
describe("global state", () => {
|
|
beforeEach(async () => {
|
|
await when.click("nav:global-state");
|
|
});
|
|
|
|
test("add variable", async () => {
|
|
await when.wait(100);
|
|
await when.click("global-state-add-variable");
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
state: { key1: { default: "value" } },
|
|
});
|
|
});
|
|
|
|
test("add multiple variables", async () => {
|
|
await when.click("global-state-add-variable");
|
|
await when.click("global-state-add-variable");
|
|
await when.click("global-state-add-variable");
|
|
await when.wait(100);
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
state: { key1: { default: "value" }, key2: { default: "value" }, key3: { default: "value" } },
|
|
});
|
|
});
|
|
|
|
test("remove variable", async () => {
|
|
await when.click("global-state-add-variable");
|
|
await when.click("global-state-add-variable");
|
|
await when.click("global-state-add-variable");
|
|
await when.click("global-state-remove-variable", 0);
|
|
await when.wait(100);
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
state: { key2: { default: "value" }, key3: { default: "value" } },
|
|
});
|
|
});
|
|
|
|
test("edit variable key", async () => {
|
|
await when.click("global-state-add-variable");
|
|
await when.wait(100);
|
|
await when.setValue("global-state-variable-key:0", "mykey");
|
|
await when.typeKeys("{enter}");
|
|
await when.wait(100);
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
state: { mykey: { default: "value" } },
|
|
});
|
|
});
|
|
|
|
test("edit variable value", async () => {
|
|
await when.click("global-state-add-variable");
|
|
await when.wait(100);
|
|
await when.setValue("global-state-variable-value:0", "myvalue");
|
|
await when.typeKeys("{enter}");
|
|
await when.wait(100);
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
state: { key1: { default: "myvalue" } },
|
|
});
|
|
});
|
|
|
|
test("edit variable value as number", async () => {
|
|
await when.click("global-state-add-variable");
|
|
await when.wait(100);
|
|
await when.setValue("global-state-variable-value:0", "9");
|
|
await when.typeKeys("{enter}");
|
|
await when.wait(100);
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
state: { key1: { default: 9 } },
|
|
});
|
|
});
|
|
|
|
test("edit variable value as array", async () => {
|
|
await when.click("global-state-add-variable");
|
|
await when.wait(100);
|
|
await when.setValue("global-state-variable-value:0", "[\"CCS\",\"Type2\"]");
|
|
await when.typeKeys("{enter}");
|
|
await when.wait(100);
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
state: { key1: { default: ["CCS", "Type2"] } },
|
|
});
|
|
});
|
|
|
|
test("edit variable value as quoted string", async () => {
|
|
await when.click("global-state-add-variable");
|
|
await when.wait(100);
|
|
await when.setValue("global-state-variable-value:0", "\"9\"");
|
|
await when.typeKeys("{enter}");
|
|
await when.wait(100);
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
|
state: { key1: { default: "9" } },
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("error panel", () => {
|
|
test("not visible when no errors", async () => {
|
|
await then(get.element("maputnik-message-panel-error")).shouldNotExist();
|
|
});
|
|
|
|
test("visible on style error", async () => {
|
|
await when.modal.open();
|
|
await when.modal.fillLayers({
|
|
type: "circle",
|
|
layer: "invalid",
|
|
});
|
|
await then(get.element(".maputnik-message-panel-error")).shouldBeVisible();
|
|
});
|
|
});
|
|
|
|
describe("Handle localStorage QuotaExceededError", () => {
|
|
test("handles quota exceeded error when opening style from URL", async () => {
|
|
// Clear localStorage to start fresh
|
|
await when.clearLocalStorage();
|
|
await when.fillLocalStorage();
|
|
|
|
// Open the style via URL input
|
|
await when.click("nav:open");
|
|
await when.setValue("modal:open.url.input", get.exampleFileUrl());
|
|
await when.click("modal:open.url.button");
|
|
|
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude(get.responseBody("example-style.json"));
|
|
await then(get.styleFromLocalStorage()).shouldExist();
|
|
});
|
|
});
|
|
});
|