Compare commits

...

17 Commits

Author SHA1 Message Date
ShellyDCMS a94ee550f8 update test utils version 2023-12-31 16:57:42 +00:00
shelly_goldblit 0ed6bb518f fix more tests 2023-12-31 18:53:46 +02:00
shelly_goldblit c5a7005a3d lint 2023-12-31 17:53:20 +02:00
shelly_goldblit 055d35f4b8 fix more tests 2023-12-31 17:47:27 +02:00
shelly_goldblit d4d37e5930 lint i guess 2023-12-31 17:39:07 +02:00
shelly_goldblit b20c54d417 move then into driver 2023-12-31 17:34:48 +02:00
ShellyDCMS f7f6df70b2 update test utils version 2023-12-31 14:39:57 +00:00
shelly_goldblit 20c121d17a lint 2023-12-31 16:26:34 +02:00
shelly_goldblit 27190f683b restore lock file 2023-12-31 16:18:02 +02:00
shelly_goldblit b4e31cc031 fix test 2023-12-31 16:17:05 +02:00
shelly_goldblit 26bf99d91a fix build 2023-12-31 13:45:34 +02:00
shelly_goldblit f5ab97d3a7 fix failing tests 2023-12-31 13:43:39 +02:00
shelly_goldblit 6aa48d66a2 fix some more tests 2023-12-31 12:05:50 +02:00
shelly_goldblit ff547fc3f7 fix some more tests 2023-12-31 11:55:03 +02:00
shelly_goldblit 138f685293 fix more tests 2023-12-31 11:42:47 +02:00
shelly_goldblit aa8cb8f3d3 fix some more tests 2023-12-31 11:40:40 +02:00
shelly_goldblit c694237703 fix some more tests 2023-12-31 11:31:31 +02:00
9 changed files with 190 additions and 150 deletions
+2 -3
View File
@@ -1,8 +1,7 @@
import { then } from "@shellygo/cypress-test-utils/assertable";
import MaputnikDriver from "./maputnik-driver";
import { MaputnikDriver } from "./maputnik-driver";
describe("accessibility", () => {
let { beforeAndAfter, get, when, should } = new MaputnikDriver();
let { beforeAndAfter, get, when, should, then } = new MaputnikDriver();
beforeAndAfter();
describe("skip links", () => {
+1 -1
View File
@@ -1,4 +1,4 @@
import MaputnikDriver from "./maputnik-driver";
import { MaputnikDriver } from "./maputnik-driver";
describe("history", () => {
let { beforeAndAfter, when, get, should } = new MaputnikDriver();
+2 -3
View File
@@ -1,8 +1,7 @@
import { then } from "@shellygo/cypress-test-utils/assertable";
import MaputnikDriver from "./maputnik-driver";
import { MaputnikDriver } from "./maputnik-driver";
describe("keyboard", () => {
let { beforeAndAfter, given, when, get } = new MaputnikDriver();
let { beforeAndAfter, given, when, get, then } = new MaputnikDriver();
beforeAndAfter();
describe("shortcuts", () => {
beforeEach(() => {
+135 -105
View File
@@ -1,9 +1,8 @@
import { then } from "@shellygo/cypress-test-utils/assertable";
import { v1 as uuid } from "uuid";
import MaputnikDriver from "./maputnik-driver";
import { MaputnikDriver } from "./maputnik-driver";
describe("layers", () => {
let { beforeAndAfter, get, when, should } = new MaputnikDriver();
let { beforeAndAfter, get, when, should, then } = new MaputnikDriver();
beforeAndAfter();
beforeEach(() => {
when.setStyle("both");
@@ -19,7 +18,7 @@ describe("layers", () => {
});
it("should update layers in local storage", () => {
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
then(get.maputnikStyleFromLocalStorage()).shouldIncludeLocalStorageStyle({
layers: [
{
id: id,
@@ -34,7 +33,9 @@ describe("layers", () => {
when.click("layer-list-item:" + id + ":delete");
});
it("should empty layers in local storage", () => {
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
then(
get.maputnikStyleFromLocalStorage()
).shouldIncludeLocalStorageStyle({
layers: [],
});
});
@@ -45,7 +46,9 @@ describe("layers", () => {
when.click("layer-list-item:" + id + ":copy");
});
it("should add copy layer in local storage", () => {
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
then(
get.maputnikStyleFromLocalStorage()
).shouldIncludeLocalStorageStyle({
layers: [
{
id: id + "-copy",
@@ -66,7 +69,9 @@ describe("layers", () => {
});
it("should update visibility to none in local storage", () => {
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
then(
get.maputnikStyleFromLocalStorage()
).shouldIncludeLocalStorageStyle({
layers: [
{
id: id,
@@ -85,7 +90,9 @@ describe("layers", () => {
});
it("should update visibility to visible in local storage", () => {
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
then(
get.maputnikStyleFromLocalStorage()
).shouldIncludeLocalStorageStyle({
layers: [
{
id: id,
@@ -162,113 +169,138 @@ describe("layers", () => {
);
});
it("min-zoom", () => {
let bgId = createBackground();
describe("min-zoom", () => {
let bgId: string;
when.click("layer-list-item:background:" + bgId);
when.setValue("min-zoom.input-text", "1");
beforeEach(() => {
bgId = createBackground();
when.click("layer-list-item:background:" + bgId);
when.setValue("min-zoom.input-text", "1");
when.click("layer-editor.layer-id");
});
when.click("layer-editor.layer-id");
it("should update min-zoom in local storage", () => {
then(
get.maputnikStyleFromLocalStorage()
).shouldIncludeLocalStorageStyle({
layers: [
{
id: "background:" + bgId,
type: "background",
minzoom: 1,
},
],
});
});
should.equalStyleStore(
(a: any) => a.layers,
[
{
id: "background:" + bgId,
type: "background",
minzoom: 1,
},
]
);
// AND RESET!
when.type("min-zoom.input-text", "{backspace}");
when.click("max-zoom.input-text");
should.equalStyleStore(
(a: any) => a.layers,
[
{
id: "background:" + bgId,
type: "background",
},
]
);
it("when clicking next layer should update style on local storage", () => {
when.type("min-zoom.input-text", "{backspace}");
when.click("max-zoom.input-text");
then(
get.maputnikStyleFromLocalStorage()
).shouldIncludeLocalStorageStyle({
layers: [
{
id: "background:" + bgId,
type: "background",
minzoom: 1,
},
],
});
});
});
it("max-zoom", () => {
let bgId = createBackground();
describe("max-zoom", () => {
let bgId: string;
when.click("layer-list-item:background:" + bgId);
when.setValue("max-zoom.input-text", "1");
beforeEach(() => {
bgId = createBackground();
when.click("layer-list-item:background:" + bgId);
when.setValue("max-zoom.input-text", "1");
when.click("layer-editor.layer-id");
});
when.click("layer-editor.layer-id");
should.equalStyleStore(
(a: any) => a.layers,
[
{
id: "background:" + bgId,
type: "background",
maxzoom: 1,
},
]
);
it("should update style in local storage", () => {
then(cy.window()).shouldIncludeLocalStorageStyle({
layers: [
{
id: "background:" + bgId,
type: "background",
maxzoom: 1,
},
],
});
});
});
it("comments", () => {
let bgId = createBackground();
describe("comments", () => {
let bgId: string;
let comment = "42";
when.click("layer-list-item:background:" + bgId);
when.setValue("layer-comment.input", comment);
beforeEach(() => {
bgId = createBackground();
when.click("layer-list-item:background:" + bgId);
when.setValue("layer-comment.input", comment);
when.click("layer-editor.layer-id");
});
when.click("layer-editor.layer-id");
should.equalStyleStore(
(a: any) => a.layers,
[
{
id: "background:" + bgId,
type: "background",
metadata: {
"maputnik:comment": comment,
it("should update style in local storage", () => {
then(
get.maputnikStyleFromLocalStorage()
).shouldIncludeLocalStorageStyle({
layers: [
{
id: "background:" + bgId,
type: "background",
metadata: {
"maputnik:comment": comment,
},
},
},
]
);
],
});
});
// Unset it again.
when.type("layer-comment.input", "{backspace}{backspace}");
when.click("min-zoom.input-text");
describe("when unsetting", () => {
beforeEach(() => {
when.clear("layer-comment.input");
when.click("min-zoom.input-text");
});
should.equalStyleStore(
(a: any) => a.layers,
[
{
id: "background:" + bgId,
type: "background",
},
]
);
it("should update style in local storage", () => {
then(
get.maputnikStyleFromLocalStorage()
).shouldIncludeLocalStorageStyle({
layers: [
{
id: "background:" + bgId,
type: "background",
},
],
});
});
});
});
it("color", () => {
let bgId = createBackground();
describe("color", () => {
let bgId: string;
beforeEach(() => {
bgId = createBackground();
when.click("layer-list-item:background:" + bgId);
when.click("spec-field:background-color", 0);
});
when.click("layer-list-item:background:" + bgId);
when.click("spec-field:background-color");
should.equalStyleStore(
(a: any) => a.layers,
[
{
id: "background:" + bgId,
type: "background",
},
]
);
it("should update style in local storage", () => {
then(
get.maputnikStyleFromLocalStorage()
).shouldIncludeLocalStorageStyle({
layers: [
{
id: "background:" + bgId,
type: "background",
},
],
});
});
});
});
@@ -459,18 +491,16 @@ describe("layers", () => {
type: "background",
});
then(get.elementByTestId("layer-list-group:foo")).shouldBeVisible();
then(get.elementByTestId("layer-list-item:foo")).shouldBeVisible();
then(get.elementByTestId("layer-list-item:foo_bar")).shouldNotBeVisible();
then(
get.elementByTestId("layer-list-group:foo_bar")
).shouldNotBeVisible();
then(
get.elementByTestId("layer-list-group:foo_bar_baz")
get.elementByTestId("layer-list-item:foo_bar_baz")
).shouldNotBeVisible();
when.click("layer-list-group:foo-0");
then(get.elementByTestId("layer-list-group:foo")).shouldBeVisible();
then(get.elementByTestId("layer-list-group:foo_bar")).shouldBeVisible();
then(get.elementByTestId("layer-list-item:foo")).shouldBeVisible();
then(get.elementByTestId("layer-list-item:foo_bar")).shouldBeVisible();
then(
get.elementByTestId("layer-list-group:foo_bar_baz")
get.elementByTestId("layer-list-item:foo_bar_baz")
).shouldBeVisible();
});
});
+3 -4
View File
@@ -1,8 +1,7 @@
import { then } from "@shellygo/cypress-test-utils/assertable";
import MaputnikDriver from "./maputnik-driver";
import { MaputnikDriver } from "./maputnik-driver";
describe("map", () => {
let { beforeAndAfter, get, when } = new MaputnikDriver();
let { beforeAndAfter, get, when, then } = new MaputnikDriver();
beforeAndAfter();
describe("zoom level", () => {
it("via url", () => {
@@ -18,10 +17,10 @@ describe("map", () => {
let zoomLevel = 12.37;
when.setStyle("geojson", zoomLevel);
then(get.elementByTestId("maplibre:ctrl-zoom")).shouldBeVisible();
when.clickZoomIn();
then(get.elementByTestId("maplibre:ctrl-zoom")).shouldContainText(
"Zoom: " + (zoomLevel + 1)
);
when.clickZoomIn();
});
});
});
+24 -14
View File
@@ -1,9 +1,27 @@
import { Assertable, then } from "@shellygo/cypress-test-utils/assertable";
import CypressWrapperDriver from "./cypress-wrapper-driver";
import ModalDriver from "./modal-driver";
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;
};
shouldIncludeLocalStorageStyle = (styleObj: Object) =>
then(
cy.window().then((win) => this.getStyleFromWindow(win))
).shouldDeepNestedInclude(styleObj);
shouldHaveLocalStorageStyle = (styleObj: Object) =>
then(
cy.window().then((win) => this.getStyleFromWindow(win))
).shouldDeepEqual(styleObj);
}
export class MaputnikDriver {
private helper = new CypressWrapperDriver();
private modalDriver = new ModalDriver();
@@ -14,6 +32,9 @@ export default class MaputnikDriver {
});
};
public then = (chainable: Cypress.Chainable<any>) =>
new MaputnikAssertable(chainable);
public given = {
...this.helper.given,
setupMockBackedResponses: () => {
@@ -111,8 +132,7 @@ export default class MaputnikDriver {
this.helper.get.elementByTestId("toolbar:link").should("be.visible");
},
typeKeys: (keys: string) =>
this.helper.get.element("body").type(keys),
typeKeys: (keys: string) => this.helper.get.element("body").type(keys),
clickZoomIn: () => {
this.helper.get.element(".maplibregl-ctrl-zoom-in").click();
@@ -191,16 +211,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) => {
this.helper.get
.elementByTestId(selector)
+18 -15
View File
@@ -1,8 +1,7 @@
import { then } from "@shellygo/cypress-test-utils/assertable";
import MaputnikDriver from "./maputnik-driver";
import { MaputnikDriver } from "./maputnik-driver";
describe("modals", () => {
let { beforeAndAfter, when, get } = new MaputnikDriver();
let { beforeAndAfter, when, get, then } = new MaputnikDriver();
beforeAndAfter();
beforeEach(() => {
@@ -21,7 +20,7 @@ describe("modals", () => {
it.skip("upload", () => {
// HM: I was not able to make the following choose file actually to select a file and close the modal...
when.chooseExampleFile();
then(get.responseBody("example-style.json")).shouldDeepEqual(
then(get.responseBody("example-style.json")).shouldHaveLocalStorageStyle(
get.maputnikStyleFromLocalStorageObj()
);
});
@@ -35,9 +34,9 @@ describe("modals", () => {
when.wait(200);
});
it("load from url", () => {
then(get.responseBody("example-style.json")).shouldDeepEqual(
get.maputnikStyleFromLocalStorageObj()
);
then(
get.responseBody("example-style.json")
).shouldHaveLocalStorageStyle(get.maputnikStyleFromLocalStorageObj());
});
});
});
@@ -104,7 +103,9 @@ describe("modals", () => {
});
it("show name specifications", () => {
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
then(
get.maputnikStyleFromLocalStorage()
).shouldIncludeLocalStorageStyle({
name: "foobar",
});
});
@@ -117,7 +118,9 @@ describe("modals", () => {
when.wait(200);
});
it("should update owner in local storage", () => {
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
then(
get.maputnikStyleFromLocalStorage()
).shouldIncludeLocalStorageStyle({
owner: "foobar",
});
});
@@ -126,7 +129,7 @@ describe("modals", () => {
it("sprite url", () => {
when.setValue("modal:settings.sprite", "http://example.com");
when.click("modal:settings.name");
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
then(get.maputnikStyleFromLocalStorage()).shouldIncludeLocalStorageStyle({
sprite: "http://example.com",
});
});
@@ -134,7 +137,7 @@ describe("modals", () => {
let glyphsUrl = "http://example.com/{fontstack}/{range}.pbf";
when.setValue("modal:settings.glyphs", glyphsUrl);
when.click("modal:settings.name");
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
then(get.maputnikStyleFromLocalStorage()).shouldIncludeLocalStorageStyle({
glyphs: glyphsUrl,
});
});
@@ -146,8 +149,8 @@ describe("modals", () => {
apiKey
);
when.click("modal:settings.name");
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
metadata: { "maputnik:openmaptiles_access_token": apiKey },
then(get.maputnikStyleFromLocalStorage()).shouldIncludeLocalStorageStyle({
"maputnik:openmaptiles_access_token": apiKey,
});
});
@@ -158,7 +161,7 @@ describe("modals", () => {
apiKey
);
when.click("modal:settings.name");
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
then(get.maputnikStyleFromLocalStorage()).shouldIncludeLocalStorageStyle({
metadata: { "maputnik:thunderforest_access_token": apiKey },
});
});
@@ -171,7 +174,7 @@ describe("modals", () => {
);
when.click("modal:settings.name");
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
then(get.maputnikStyleFromLocalStorage()).shouldIncludeLocalStorageStyle({
metadata: { "maputnik:renderer": "ol" },
});
});
+4 -4
View File
@@ -61,7 +61,7 @@
"@cypress/code-coverage": "^3.12.15",
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@rollup/plugin-replace": "^5.0.5",
"@shellygo/cypress-test-utils": "^2.0.15",
"@shellygo/cypress-test-utils": "^2.0.17",
"@storybook/addon-a11y": "^7.6.5",
"@storybook/addon-actions": "^7.6.5",
"@storybook/addon-links": "^7.6.5",
@@ -3613,9 +3613,9 @@
]
},
"node_modules/@shellygo/cypress-test-utils": {
"version": "2.0.15",
"resolved": "https://registry.npmjs.org/@shellygo/cypress-test-utils/-/cypress-test-utils-2.0.15.tgz",
"integrity": "sha512-sm/ezwsI/+H8ohoa7R0+Is5GGZ3IRyg55tPMk30Je4tswlxVpJd7IItj5RymZFhbpX3IRR320Rkw++XyX7xqiQ==",
"version": "2.0.17",
"resolved": "https://registry.npmjs.org/@shellygo/cypress-test-utils/-/cypress-test-utils-2.0.17.tgz",
"integrity": "sha512-eI7TL2D3wbWgjBxhMfLBOMV5XpvVcLN8e2hCKQSzvNp/Eis7ZmcGExsNMEFhY8BYG59A2TGX2daWJfv5bJdNhg==",
"dev": true,
"dependencies": {
"@cypress/mount-utils": "^4.0.0",
+1 -1
View File
@@ -91,7 +91,7 @@
"@cypress/code-coverage": "^3.12.15",
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@rollup/plugin-replace": "^5.0.5",
"@shellygo/cypress-test-utils": "^2.0.15",
"@shellygo/cypress-test-utils": "^2.0.17",
"@storybook/addon-a11y": "^7.6.5",
"@storybook/addon-actions": "^7.6.5",
"@storybook/addon-links": "^7.6.5",