mirror of
https://github.com/maputnik/editor.git
synced 2026-04-01 15:10:00 +00:00
fix failing tests
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import { then } from "@shellygo/cypress-test-utils/assertable";
|
|
||||||
import { v1 as uuid } from "uuid";
|
import { v1 as uuid } from "uuid";
|
||||||
import MaputnikDriver from "./maputnik-driver";
|
import { MaputnikDriver, then } from "./maputnik-driver";
|
||||||
|
|
||||||
describe("layers", () => {
|
describe("layers", () => {
|
||||||
let { beforeAndAfter, get, when, should } = new MaputnikDriver();
|
let { beforeAndAfter, get, when, should } = new MaputnikDriver();
|
||||||
@@ -19,14 +18,16 @@ describe("layers", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should update layers in local storage", () => {
|
it("should update layers in local storage", () => {
|
||||||
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
|
then(get.maputnikStyleFromLocalStorage()).shouldIncludeLocalStrorageStyle(
|
||||||
layers: [
|
{
|
||||||
{
|
layers: [
|
||||||
id: id,
|
{
|
||||||
type: "background",
|
id: id,
|
||||||
},
|
type: "background",
|
||||||
],
|
},
|
||||||
});
|
],
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when clicking delete", () => {
|
describe("when clicking delete", () => {
|
||||||
@@ -34,7 +35,9 @@ describe("layers", () => {
|
|||||||
when.click("layer-list-item:" + id + ":delete");
|
when.click("layer-list-item:" + id + ":delete");
|
||||||
});
|
});
|
||||||
it("should empty layers in local storage", () => {
|
it("should empty layers in local storage", () => {
|
||||||
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
|
then(
|
||||||
|
get.maputnikStyleFromLocalStorage()
|
||||||
|
).shouldIncludeLocalStrorageStyle({
|
||||||
layers: [],
|
layers: [],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -45,7 +48,9 @@ describe("layers", () => {
|
|||||||
when.click("layer-list-item:" + id + ":copy");
|
when.click("layer-list-item:" + id + ":copy");
|
||||||
});
|
});
|
||||||
it("should add copy layer in local storage", () => {
|
it("should add copy layer in local storage", () => {
|
||||||
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
|
then(
|
||||||
|
get.maputnikStyleFromLocalStorage()
|
||||||
|
).shouldIncludeLocalStrorageStyle({
|
||||||
layers: [
|
layers: [
|
||||||
{
|
{
|
||||||
id: id + "-copy",
|
id: id + "-copy",
|
||||||
@@ -66,7 +71,9 @@ describe("layers", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should update visibility to none in local storage", () => {
|
it("should update visibility to none in local storage", () => {
|
||||||
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
|
then(
|
||||||
|
get.maputnikStyleFromLocalStorage()
|
||||||
|
).shouldIncludeLocalStrorageStyle({
|
||||||
layers: [
|
layers: [
|
||||||
{
|
{
|
||||||
id: id,
|
id: id,
|
||||||
@@ -82,11 +89,12 @@ describe("layers", () => {
|
|||||||
describe("when clicking show", () => {
|
describe("when clicking show", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
when.click("layer-list-item:" + id + ":toggle-visibility");
|
when.click("layer-list-item:" + id + ":toggle-visibility");
|
||||||
when.wait(200);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should update visibility to visible in local storage", () => {
|
it("should update visibility to visible in local storage", () => {
|
||||||
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
|
then(
|
||||||
|
get.maputnikStyleFromLocalStorage()
|
||||||
|
).shouldIncludeLocalStrorageStyle({
|
||||||
layers: [
|
layers: [
|
||||||
{
|
{
|
||||||
id: id,
|
id: id,
|
||||||
@@ -174,7 +182,9 @@ describe("layers", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should update min-zoom in local storage", () => {
|
it("should update min-zoom in local storage", () => {
|
||||||
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
|
then(
|
||||||
|
get.maputnikStyleFromLocalStorage()
|
||||||
|
).shouldIncludeLocalStrorageStyle({
|
||||||
layers: [
|
layers: [
|
||||||
{
|
{
|
||||||
id: "background:" + bgId,
|
id: "background:" + bgId,
|
||||||
@@ -188,7 +198,9 @@ describe("layers", () => {
|
|||||||
it("when clicking next layer should update style on local storage", () => {
|
it("when clicking next layer should update style on local storage", () => {
|
||||||
when.type("min-zoom.input-text", "{backspace}");
|
when.type("min-zoom.input-text", "{backspace}");
|
||||||
when.click("max-zoom.input-text");
|
when.click("max-zoom.input-text");
|
||||||
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
|
then(
|
||||||
|
get.maputnikStyleFromLocalStorage()
|
||||||
|
).shouldIncludeLocalStrorageStyle({
|
||||||
layers: [
|
layers: [
|
||||||
{
|
{
|
||||||
id: "background:" + bgId,
|
id: "background:" + bgId,
|
||||||
@@ -208,11 +220,10 @@ describe("layers", () => {
|
|||||||
when.click("layer-list-item:background:" + bgId);
|
when.click("layer-list-item:background:" + bgId);
|
||||||
when.setValue("max-zoom.input-text", "1");
|
when.setValue("max-zoom.input-text", "1");
|
||||||
when.click("layer-editor.layer-id");
|
when.click("layer-editor.layer-id");
|
||||||
when.wait(200);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should update style in local storage", () => {
|
it("should update style in local storage", () => {
|
||||||
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
|
then(cy.window()).shouldIncludeLocalStrorageStyle({
|
||||||
layers: [
|
layers: [
|
||||||
{
|
{
|
||||||
id: "background:" + bgId,
|
id: "background:" + bgId,
|
||||||
@@ -233,11 +244,12 @@ describe("layers", () => {
|
|||||||
when.click("layer-list-item:background:" + bgId);
|
when.click("layer-list-item:background:" + bgId);
|
||||||
when.setValue("layer-comment.input", comment);
|
when.setValue("layer-comment.input", comment);
|
||||||
when.click("layer-editor.layer-id");
|
when.click("layer-editor.layer-id");
|
||||||
when.wait(200);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should update style in local stroage", () => {
|
it("should update style in local stroage", () => {
|
||||||
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
|
then(
|
||||||
|
get.maputnikStyleFromLocalStorage()
|
||||||
|
).shouldIncludeLocalStrorageStyle({
|
||||||
layers: [
|
layers: [
|
||||||
{
|
{
|
||||||
id: "background:" + bgId,
|
id: "background:" + bgId,
|
||||||
@@ -254,20 +266,19 @@ describe("layers", () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
when.type("layer-comment.input", "{backspace}{backspace}");
|
when.type("layer-comment.input", "{backspace}{backspace}");
|
||||||
when.click("min-zoom.input-text");
|
when.click("min-zoom.input-text");
|
||||||
when.wait(400);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should update style in local storage", () => {
|
it("should update style in local storage", () => {
|
||||||
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude(
|
then(
|
||||||
{
|
get.maputnikStyleFromLocalStorage()
|
||||||
layers: [
|
).shouldIncludeLocalStrorageStyle({
|
||||||
{
|
layers: [
|
||||||
id: "background:" + bgId,
|
{
|
||||||
type: "background",
|
id: "background:" + bgId,
|
||||||
},
|
type: "background",
|
||||||
],
|
},
|
||||||
}
|
],
|
||||||
);
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -278,11 +289,12 @@ describe("layers", () => {
|
|||||||
bgId = createBackground();
|
bgId = createBackground();
|
||||||
when.click("layer-list-item:background:" + bgId);
|
when.click("layer-list-item:background:" + bgId);
|
||||||
when.click("spec-field:background-color");
|
when.click("spec-field:background-color");
|
||||||
when.wait(200);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should update style in local storage", () => {
|
it("should update style in local storage", () => {
|
||||||
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
|
then(
|
||||||
|
get.maputnikStyleFromLocalStorage()
|
||||||
|
).shouldIncludeLocalStrorageStyle({
|
||||||
layers: [
|
layers: [
|
||||||
{
|
{
|
||||||
id: "background:" + bgId,
|
id: "background:" + bgId,
|
||||||
|
|||||||
@@ -1,9 +1,33 @@
|
|||||||
|
import {
|
||||||
|
Assertable,
|
||||||
|
then as baseThen,
|
||||||
|
} from "@shellygo/cypress-test-utils/assertable";
|
||||||
import CypressWrapperDriver from "./cypress-wrapper-driver";
|
import CypressWrapperDriver from "./cypress-wrapper-driver";
|
||||||
import ModalDriver from "./modal-driver";
|
import ModalDriver from "./modal-driver";
|
||||||
|
|
||||||
const baseUrl = "http://localhost:8888/";
|
const baseUrl = "http://localhost:8888/";
|
||||||
|
|
||||||
export default class MaputnikDriver {
|
export class MaputnikAssertable<T> extends Assertable<T> {
|
||||||
|
private getStyleFromWindow = (win: Window) => {
|
||||||
|
const styleId = win.localStorage.getItem("maputnik:latest_style");
|
||||||
|
const styleItem = win.localStorage.getItem(`maputnik:style:${styleId}`);
|
||||||
|
const obj = JSON.parse(styleItem || "");
|
||||||
|
return obj;
|
||||||
|
};
|
||||||
|
shouldIncludeLocalStrorageStyle = (styleObj: Object) =>
|
||||||
|
baseThen(
|
||||||
|
cy.window().then((win) => this.getStyleFromWindow(win))
|
||||||
|
).shouldDeepNestedInclude(styleObj);
|
||||||
|
|
||||||
|
shouldHaveLocalStorageStyle = (styleObj: Object) =>
|
||||||
|
baseThen(
|
||||||
|
cy.window().then((win) => this.getStyleFromWindow(win))
|
||||||
|
).shouldDeepEqual(styleObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const then = (chainable: Cypress.Chainable<any>) =>
|
||||||
|
new MaputnikAssertable(chainable);
|
||||||
|
|
||||||
|
export class MaputnikDriver {
|
||||||
private helper = new CypressWrapperDriver();
|
private helper = new CypressWrapperDriver();
|
||||||
private modalDriver = new ModalDriver();
|
private modalDriver = new ModalDriver();
|
||||||
|
|
||||||
@@ -87,18 +111,18 @@ export default class MaputnikDriver {
|
|||||||
) => {
|
) => {
|
||||||
let url = "?debug";
|
let url = "?debug";
|
||||||
switch (styleProperties) {
|
switch (styleProperties) {
|
||||||
case "geojson":
|
case "geojson":
|
||||||
url += `&style=${baseUrl}geojson-style.json`;
|
url += `&style=${baseUrl}geojson-style.json`;
|
||||||
break;
|
break;
|
||||||
case "raster":
|
case "raster":
|
||||||
url += `&style=${baseUrl}raster-style.json`;
|
url += `&style=${baseUrl}raster-style.json`;
|
||||||
break;
|
break;
|
||||||
case "both":
|
case "both":
|
||||||
url += `&style=${baseUrl}geojson-raster-style.json`;
|
url += `&style=${baseUrl}geojson-raster-style.json`;
|
||||||
break;
|
break;
|
||||||
case "layer":
|
case "layer":
|
||||||
url += `&style=${baseUrl}/example-layer-style.json`;
|
url += `&style=${baseUrl}/example-layer-style.json`;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (zoom) {
|
if (zoom) {
|
||||||
url += `#${zoom}/41.3805/2.1635`;
|
url += `#${zoom}/41.3805/2.1635`;
|
||||||
@@ -111,8 +135,7 @@ export default class MaputnikDriver {
|
|||||||
this.helper.get.elementByTestId("toolbar:link").should("be.visible");
|
this.helper.get.elementByTestId("toolbar:link").should("be.visible");
|
||||||
},
|
},
|
||||||
|
|
||||||
typeKeys: (keys: string) =>
|
typeKeys: (keys: string) => this.helper.get.element("body").type(keys),
|
||||||
this.helper.get.element("body").type(keys),
|
|
||||||
|
|
||||||
clickZoomIn: () => {
|
clickZoomIn: () => {
|
||||||
this.helper.get.element(".maplibregl-ctrl-zoom-in").click();
|
this.helper.get.element(".maplibregl-ctrl-zoom-in").click();
|
||||||
@@ -191,16 +214,6 @@ export default class MaputnikDriver {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
styleStoreEqualToExampleFileData: () => {
|
|
||||||
cy.window().then((_win: any) => {
|
|
||||||
//const obj = this.get.styleFromWindow(win);
|
|
||||||
const obj = this.get.maputnikStyleFromLocalStorageObj();
|
|
||||||
this.helper.given
|
|
||||||
.fixture("example-style.json", "file:example-style.json")
|
|
||||||
.should("deep.equal", obj);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
beSelected: (selector: string, value: string) => {
|
beSelected: (selector: string, value: string) => {
|
||||||
this.helper.get
|
this.helper.get
|
||||||
.elementByTestId(selector)
|
.elementByTestId(selector)
|
||||||
|
|||||||
968
package-lock.json
generated
968
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user