mirror of
https://github.com/maputnik/editor.git
synced 2025-12-05 22:00:00 +00:00
This is in order to reduce warnings in the console for React 19 usage. This removes the deprecated defaultProp and also move all the store initialization logic out of the App.tsx file, keeping it a lot more clean. It removes the `debug` flag from the supported urls along with the `localport` and `localhost`, which I'm not sure if and how they were ever used. The tests are using the `style` url, so I think it is covered in terms of tests. It also improves some typings along the project. It removes some callbacks from the code and moves to use promises. ## Launch Checklist - [x] Briefly describe the changes in this PR. - [x] Include before/after visuals or gifs if this PR includes visual changes. - [x] Write tests for all new functionality. - [ ] Add an entry to `CHANGELOG.md` under the `## main` section. Before: <img width="1263" height="439" alt="image" src="https://github.com/user-attachments/assets/1988c4f7-39de-4fd2-b6da-b4736abc0441" /> After: <img width="1263" height="203" alt="image" src="https://github.com/user-attachments/assets/28079e6d-9de7-40a1-9869-01a0876ca79f" /> --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Bart Louwers <bart.louwers@gmail.com>
189 lines
5.6 KiB
TypeScript
189 lines
5.6 KiB
TypeScript
/// <reference types="cypress-plugin-tab" />
|
|
|
|
import { CypressHelper } from "@shellygo/cypress-test-utils";
|
|
import { Assertable, then } from "@shellygo/cypress-test-utils/assertable";
|
|
import MaputnikCypressHelper from "./maputnik-cypress-helper";
|
|
import ModalDriver from "./modal-driver";
|
|
const baseUrl = "http://localhost:8888/";
|
|
|
|
const styleFromWindow = (win: Window) => {
|
|
const styleId = win.localStorage.getItem("maputnik:latest_style");
|
|
const styleItemKey = `maputnik:style:${styleId}`;
|
|
const styleItem = win.localStorage.getItem(styleItemKey);
|
|
if (!styleItem) throw new Error("Could not get styleItem from localStorage");
|
|
const obj = JSON.parse(styleItem);
|
|
return obj;
|
|
};
|
|
|
|
export class MaputnikAssertable<T> extends Assertable<T> {
|
|
shouldEqualToStoredStyle = () =>
|
|
then(
|
|
new CypressHelper().get.window().then((win: Window) => {
|
|
const style = styleFromWindow(win);
|
|
then(this.chainable).shouldDeepNestedInclude(style);
|
|
})
|
|
);
|
|
}
|
|
|
|
export class MaputnikDriver {
|
|
private helper = new MaputnikCypressHelper();
|
|
private modalDriver = new ModalDriver();
|
|
|
|
public beforeAndAfter = () => {
|
|
beforeEach(() => {
|
|
this.given.setupMockBackedResponses();
|
|
this.when.setStyle("both");
|
|
});
|
|
};
|
|
|
|
public then = (chainable: Cypress.Chainable<any>) =>
|
|
new MaputnikAssertable(chainable);
|
|
|
|
public given = {
|
|
...this.helper.given,
|
|
setupMockBackedResponses: () => {
|
|
this.helper.given.interceptAndMockResponse({
|
|
method: "GET",
|
|
url: baseUrl + "example-style.json",
|
|
response: {
|
|
fixture: "example-style.json",
|
|
},
|
|
alias: "example-style.json",
|
|
});
|
|
this.helper.given.interceptAndMockResponse({
|
|
method: "GET",
|
|
url: baseUrl + "example-layer-style.json",
|
|
response: {
|
|
fixture: "example-layer-style.json",
|
|
},
|
|
});
|
|
this.helper.given.interceptAndMockResponse({
|
|
method: "GET",
|
|
url: baseUrl + "geojson-style.json",
|
|
response: {
|
|
fixture: "geojson-style.json",
|
|
},
|
|
});
|
|
this.helper.given.interceptAndMockResponse({
|
|
method: "GET",
|
|
url: baseUrl + "raster-style.json",
|
|
response: {
|
|
fixture: "raster-style.json",
|
|
},
|
|
});
|
|
this.helper.given.interceptAndMockResponse({
|
|
method: "GET",
|
|
url: baseUrl + "geojson-raster-style.json",
|
|
response: {
|
|
fixture: "geojson-raster-style.json",
|
|
},
|
|
});
|
|
this.helper.given.interceptAndMockResponse({
|
|
method: "GET",
|
|
url: "*example.local/*",
|
|
response: [],
|
|
});
|
|
this.helper.given.interceptAndMockResponse({
|
|
method: "GET",
|
|
url: "*example.com/*",
|
|
response: [],
|
|
});
|
|
},
|
|
};
|
|
|
|
public when = {
|
|
...this.helper.when,
|
|
modal: this.modalDriver.when,
|
|
within: (selector: string, fn: () => void) => {
|
|
this.helper.when.within(fn, selector);
|
|
},
|
|
tab: () => this.helper.get.element("body").tab(),
|
|
waitForExampleFileResponse: () => {
|
|
this.helper.when.waitForResponse("example-style.json");
|
|
},
|
|
chooseExampleFile: () => {
|
|
this.helper.get
|
|
.bySelector("type", "file")
|
|
.selectFile("cypress/fixtures/example-style.json", { force: true });
|
|
},
|
|
setStyle: (
|
|
styleProperties: "geojson" | "raster" | "both" | "layer" | "",
|
|
zoom?: number
|
|
) => {
|
|
const url = new URL(baseUrl);
|
|
switch (styleProperties) {
|
|
case "geojson":
|
|
url.searchParams.set("style", baseUrl + "geojson-style.json");
|
|
break;
|
|
case "raster":
|
|
url.searchParams.set("style", baseUrl + "raster-style.json");
|
|
break;
|
|
case "both":
|
|
url.searchParams.set("style", baseUrl + "geojson-raster-style.json");
|
|
break;
|
|
case "layer":
|
|
url.searchParams.set("style", baseUrl + "example-layer-style.json");
|
|
break;
|
|
}
|
|
if (zoom) {
|
|
url.hash = `${zoom}/41.3805/2.1635`;
|
|
}
|
|
this.helper.when.visit(url.toString());
|
|
if (styleProperties) {
|
|
this.helper.when.acceptConfirm();
|
|
}
|
|
// when methods should not include assertions
|
|
const toolbarLink = this.helper.get.elementByTestId("toolbar:link")
|
|
toolbarLink.scrollIntoView();
|
|
toolbarLink.should("be.visible");
|
|
},
|
|
|
|
typeKeys: (keys: string) => this.helper.get.element("body").type(keys),
|
|
|
|
clickZoomIn: () => {
|
|
this.helper.get.element(".maplibregl-ctrl-zoom-in").click();
|
|
},
|
|
|
|
selectWithin: (selector: string, value: string) => {
|
|
this.when.within(selector, () => {
|
|
this.helper.get.element("select").select(value);
|
|
});
|
|
},
|
|
|
|
select: (selector: string, value: string) => {
|
|
this.helper.get.elementByTestId(selector).select(value);
|
|
},
|
|
|
|
focus: (selector: string) => {
|
|
this.helper.when.focus(selector);
|
|
},
|
|
|
|
setValue: (selector: string, text: string) => {
|
|
this.helper.get
|
|
.elementByTestId(selector)
|
|
.clear()
|
|
.type(text, { parseSpecialCharSequences: false });
|
|
},
|
|
};
|
|
|
|
public get = {
|
|
...this.helper.get,
|
|
isMac: () => {
|
|
return Cypress.platform === "darwin";
|
|
},
|
|
|
|
styleFromLocalStorage: () =>
|
|
this.helper.get.window().then((win) => styleFromWindow(win)),
|
|
|
|
exampleFileUrl: () => {
|
|
return baseUrl + "example-style.json";
|
|
},
|
|
skipTargetLayerList: () =>
|
|
this.helper.get.elementByTestId("skip-target-layer-list"),
|
|
skipTargetLayerEditor: () =>
|
|
this.helper.get.elementByTestId("skip-target-layer-editor"),
|
|
canvas: () => this.helper.get.element("canvas"),
|
|
searchControl: () => this.helper.get.element('.maplibregl-ctrl-geocoder')
|
|
};
|
|
}
|