mirror of
https://github.com/maputnik/editor.git
synced 2026-06-19 05:37:27 +00:00
improve drivers
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
|
import { then } from "@shellygo/cypress-test-utils/assertable";
|
||||||
import MaputnikDriver from "./maputnik-driver";
|
import MaputnikDriver from "./maputnik-driver";
|
||||||
|
|
||||||
describe("accessibility", () => {
|
describe("accessibility", () => {
|
||||||
let { beforeAndAfter, when, should } = new MaputnikDriver();
|
let { beforeAndAfter, get, when, should } = new MaputnikDriver();
|
||||||
beforeAndAfter();
|
beforeAndAfter();
|
||||||
|
|
||||||
describe("skip links", () => {
|
describe("skip links", () => {
|
||||||
@@ -16,6 +17,8 @@ describe("accessibility", () => {
|
|||||||
should.beFocused(selector);
|
should.beFocused(selector);
|
||||||
when.click(selector);
|
when.click(selector);
|
||||||
should.beFocused("skip-target-layer-list");
|
should.beFocused("skip-target-layer-list");
|
||||||
|
|
||||||
|
// then(get.skipTargetLayerList()).shouldBeFocused();
|
||||||
});
|
});
|
||||||
|
|
||||||
// This fails for some reason only in Chrome, but passes in firefox. Adding a skip here to allow merge and later on we'll decide if we want to fix this or not.
|
// This fails for some reason only in Chrome, but passes in firefox. Adding a skip here to allow merge and later on we'll decide if we want to fix this or not.
|
||||||
@@ -25,7 +28,7 @@ describe("accessibility", () => {
|
|||||||
when.tab().tab();
|
when.tab().tab();
|
||||||
should.beFocused(selector);
|
should.beFocused(selector);
|
||||||
when.click(selector);
|
when.click(selector);
|
||||||
should.beFocused("skip-target-layer-editor");
|
then(get.skipTargetLayerEditor()).shouldBeFocused();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("skip link to map view", () => {
|
it("skip link to map view", () => {
|
||||||
|
|||||||
@@ -5,37 +5,21 @@ export default class CypressWrapperDriver {
|
|||||||
|
|
||||||
public given = {
|
public given = {
|
||||||
...this.helper.given,
|
...this.helper.given,
|
||||||
/**
|
};
|
||||||
*
|
|
||||||
* @param url a url to a file, this assumes the file name is the last part of the url
|
|
||||||
* @param alias
|
|
||||||
*/
|
|
||||||
interceptGetToFile(url: string) {
|
|
||||||
let fileNameAndAlias = url.split('/').pop();
|
|
||||||
cy.intercept('GET', url, { fixture: fileNameAndAlias }).as(fileNameAndAlias!);
|
|
||||||
},
|
|
||||||
|
|
||||||
interceptAndIgnore(url: string) {
|
|
||||||
cy.intercept({ method: "GET", url }, []);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public get = {
|
public get = {
|
||||||
...this.helper.get,
|
...this.helper.get,
|
||||||
elementByClassOrType(slector: string) {
|
elementByClassOrType(slector: string) {
|
||||||
return cy.get(slector);
|
return cy.get(slector);
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
|
|
||||||
public when = {
|
public when = {
|
||||||
...this.helper.when,
|
...this.helper.when,
|
||||||
visit(address: string) {
|
|
||||||
cy.visit(address);
|
|
||||||
},
|
|
||||||
confirmAlert() {
|
confirmAlert() {
|
||||||
cy.on("window:confirm", () => true);
|
cy.on("window:confirm", () => true);
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
|
|
||||||
public beforeAndAfter = this.helper.beforeAndAfter;
|
public beforeAndAfter = this.helper.beforeAndAfter;
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,7 @@ describe("keyboard", () => {
|
|||||||
beforeAndAfter();
|
beforeAndAfter();
|
||||||
describe("shortcuts", () => {
|
describe("shortcuts", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
given.setupInterception();
|
given.setupMockBackedResponses();
|
||||||
when.setStyle("");
|
when.setStyle("");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -9,21 +9,59 @@ export default class MaputnikDriver {
|
|||||||
|
|
||||||
public beforeAndAfter = () => {
|
public beforeAndAfter = () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
this.given.setupInterception();
|
this.given.setupMockBackedResponses();
|
||||||
this.when.setStyle("both");
|
this.when.setStyle("both");
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
public given = {
|
public given = {
|
||||||
setupInterception: () => {
|
setupMockBackedResponses: () => {
|
||||||
this.helper.given.interceptGetToFile(SERVER_ADDRESS + "example-style.json");
|
this.helper.given.interceptAndMockResponse({
|
||||||
this.helper.given.interceptGetToFile(SERVER_ADDRESS + "example-layer-style.json");
|
method: "GET",
|
||||||
this.helper.given.interceptGetToFile(SERVER_ADDRESS + "geojson-style.json");
|
url: "http://localhost:8888/example-style.json",
|
||||||
this.helper.given.interceptGetToFile(SERVER_ADDRESS + "raster-style.json");
|
response: {
|
||||||
this.helper.given.interceptGetToFile(SERVER_ADDRESS + "geojson-raster-style.json");
|
fixture: "example-style.json",
|
||||||
|
},
|
||||||
this.helper.given.interceptAndIgnore("*example.local/*");
|
alias: "example-style.json",
|
||||||
this.helper.given.interceptAndIgnore("*example.com/*");
|
});
|
||||||
|
this.helper.given.interceptAndMockResponse({
|
||||||
|
method: "GET",
|
||||||
|
url: "http://localhost:8888/example-layer-style.json",
|
||||||
|
response: {
|
||||||
|
fixture: "example-layer-style.json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
this.helper.given.interceptAndMockResponse({
|
||||||
|
method: "GET",
|
||||||
|
url: "http://localhost:8888/geojson-style.json",
|
||||||
|
response: {
|
||||||
|
fixture: "geojson-style.json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
this.helper.given.interceptAndMockResponse({
|
||||||
|
method: "GET",
|
||||||
|
url: "http://localhost:8888/raster-style.json",
|
||||||
|
response: {
|
||||||
|
fixture: "raster-style.json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
this.helper.given.interceptAndMockResponse({
|
||||||
|
method: "GET",
|
||||||
|
url: "http://localhost:8888/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: [],
|
||||||
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -37,10 +75,9 @@ export default class MaputnikDriver {
|
|||||||
this.helper.when.waitForResponse("example-style.json");
|
this.helper.when.waitForResponse("example-style.json");
|
||||||
},
|
},
|
||||||
chooseExampleFile: () => {
|
chooseExampleFile: () => {
|
||||||
this.helper.get.elementByClassOrType("input[type='file']").selectFile(
|
this.helper.get
|
||||||
"cypress/fixtures/example-style.json",
|
.bySelector("type", "file")
|
||||||
{ force: true }
|
.selectFile("cypress/fixtures/example-style.json", { force: true });
|
||||||
);
|
|
||||||
},
|
},
|
||||||
setStyle: (
|
setStyle: (
|
||||||
styleProperties: "geojson" | "raster" | "both" | "layer" | "",
|
styleProperties: "geojson" | "raster" | "both" | "layer" | "",
|
||||||
@@ -48,18 +85,18 @@ export default class MaputnikDriver {
|
|||||||
) => {
|
) => {
|
||||||
let url = "?debug";
|
let url = "?debug";
|
||||||
switch (styleProperties) {
|
switch (styleProperties) {
|
||||||
case "geojson":
|
case "geojson":
|
||||||
url += `&style=${SERVER_ADDRESS}geojson-style.json`;
|
url += `&style=${SERVER_ADDRESS}geojson-style.json`;
|
||||||
break;
|
break;
|
||||||
case "raster":
|
case "raster":
|
||||||
url += `&style=${SERVER_ADDRESS}raster-style.json`;
|
url += `&style=${SERVER_ADDRESS}raster-style.json`;
|
||||||
break;
|
break;
|
||||||
case "both":
|
case "both":
|
||||||
url += `&style=${SERVER_ADDRESS}geojson-raster-style.json`;
|
url += `&style=${SERVER_ADDRESS}geojson-raster-style.json`;
|
||||||
break;
|
break;
|
||||||
case "layer":
|
case "layer":
|
||||||
url += `&style=${SERVER_ADDRESS}/example-layer-style.json`;
|
url += `&style=${SERVER_ADDRESS}/example-layer-style.json`;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (zoom) {
|
if (zoom) {
|
||||||
url += `#${zoom}/41.3805/2.1635`;
|
url += `#${zoom}/41.3805/2.1635`;
|
||||||
@@ -102,7 +139,10 @@ export default class MaputnikDriver {
|
|||||||
},
|
},
|
||||||
|
|
||||||
setValue: (selector: string, text: string) => {
|
setValue: (selector: string, text: string) => {
|
||||||
this.helper.get.element(selector).clear().type(text, { parseSpecialCharSequences: false });
|
this.helper.get
|
||||||
|
.element(selector)
|
||||||
|
.clear()
|
||||||
|
.type(text, { parseSpecialCharSequences: false });
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -119,12 +159,16 @@ export default class MaputnikDriver {
|
|||||||
exampleFileUrl: () => {
|
exampleFileUrl: () => {
|
||||||
return SERVER_ADDRESS + "example-style.json";
|
return SERVER_ADDRESS + "example-style.json";
|
||||||
},
|
},
|
||||||
|
skipTargetLayerList: () =>
|
||||||
|
this.helper.get.element("skip-target-layer-list"),
|
||||||
|
skipTargetLayerEditor: () =>
|
||||||
|
this.helper.get.element("skip-target-layer-editor"),
|
||||||
};
|
};
|
||||||
|
|
||||||
public should = {
|
public should = {
|
||||||
canvasBeFocused: () => {
|
canvasBeFocused: () => {
|
||||||
this.when.within("maplibre:map", () => {
|
this.when.within("maplibre:map", () => {
|
||||||
this.helper.get.elementByClassOrType("canvas").should("be.focused");
|
this.helper.get.element("canvas").should("be.focused");
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
notExist: (selector: string) => {
|
notExist: (selector: string) => {
|
||||||
@@ -156,7 +200,9 @@ export default class MaputnikDriver {
|
|||||||
styleStoreEqualToExampleFileData: () => {
|
styleStoreEqualToExampleFileData: () => {
|
||||||
cy.window().then((win: any) => {
|
cy.window().then((win: any) => {
|
||||||
const obj = this.get.styleFromWindow(win);
|
const obj = this.get.styleFromWindow(win);
|
||||||
this.helper.given.fixture("example-style.json", "file:example-style.json").should("deep.equal", obj);
|
this.helper.given
|
||||||
|
.fixture("example-style.json", "file:example-style.json")
|
||||||
|
.should("deep.equal", obj);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -164,10 +210,13 @@ export default class MaputnikDriver {
|
|||||||
this.helper.get.element(selector).should("exist");
|
this.helper.get.element(selector).should("exist");
|
||||||
},
|
},
|
||||||
beSelected: (selector: string, value: string) => {
|
beSelected: (selector: string, value: string) => {
|
||||||
this.helper.get.element(selector).find(`option[value="${value}"]`).should("be.selected");
|
this.helper.get
|
||||||
|
.element(selector)
|
||||||
|
.find(`option[value="${value}"]`)
|
||||||
|
.should("be.selected");
|
||||||
},
|
},
|
||||||
containText: (selector: string, text: string) => {
|
containText: (selector: string, text: string) => {
|
||||||
this.helper.get.element(selector).should("contain.text", text);
|
this.helper.get.element(selector).should("contain.text", text);
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ export default class ModalDriver {
|
|||||||
private helper = new CypressWrapperDriver();
|
private helper = new CypressWrapperDriver();
|
||||||
|
|
||||||
public when = {
|
public when = {
|
||||||
fillLayers: (opts: {type: string, layer?: string, id?: string}) => {
|
fillLayers: (opts: { type: string; layer?: string; id?: string }) => {
|
||||||
let type = opts.type;
|
let type = opts.type;
|
||||||
let layer = opts.layer;
|
let layer = opts.layer;
|
||||||
let id;
|
let id;
|
||||||
@@ -20,7 +20,7 @@ export default class ModalDriver {
|
|||||||
if (layer) {
|
if (layer) {
|
||||||
this.helper.when.within(() => {
|
this.helper.when.within(() => {
|
||||||
this.helper.get.elementByClassOrType("input").type(layer!);
|
this.helper.get.elementByClassOrType("input").type(layer!);
|
||||||
}, "add-layer.layer-source-block")
|
}, "add-layer.layer-source-block");
|
||||||
}
|
}
|
||||||
this.helper.when.click("add-layer");
|
this.helper.when.click("add-layer");
|
||||||
|
|
||||||
@@ -38,5 +38,5 @@ export default class ModalDriver {
|
|||||||
this.helper.when.waitUntil(() => this.helper.get.element(key));
|
this.helper.when.waitUntil(() => this.helper.get.element(key));
|
||||||
this.helper.when.click(key + ".close-modal");
|
this.helper.when.click(key + ".close-modal");
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
Generated
+103
-853
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -91,7 +91,7 @@
|
|||||||
"@cypress/code-coverage": "^3.12.15",
|
"@cypress/code-coverage": "^3.12.15",
|
||||||
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
||||||
"@rollup/plugin-replace": "^5.0.5",
|
"@rollup/plugin-replace": "^5.0.5",
|
||||||
"@shellygo/cypress-test-utils": "^2.0.9",
|
"@shellygo/cypress-test-utils": "^2.0.14",
|
||||||
"@storybook/addon-a11y": "^7.6.5",
|
"@storybook/addon-a11y": "^7.6.5",
|
||||||
"@storybook/addon-actions": "^7.6.5",
|
"@storybook/addon-actions": "^7.6.5",
|
||||||
"@storybook/addon-links": "^7.6.5",
|
"@storybook/addon-links": "^7.6.5",
|
||||||
|
|||||||
Reference in New Issue
Block a user