This commit is contained in:
shelly_goldblit
2023-12-30 20:36:49 +02:00
parent 085eda76a1
commit f7a945abce
4 changed files with 98 additions and 70 deletions
+4 -4
View File
@@ -12,9 +12,9 @@ describe("accessibility", () => {
it("skip link to layer list", () => { it("skip link to layer list", () => {
const selector = "root:skip:layer-list"; const selector = "root:skip:layer-list";
should.exist(selector); then(get.elementByTestId(selector)).shouldExist();
when.tab(); when.tab();
should.beFocused(selector); then(get.skipTargetLayerList()).shouldBeFocused();
when.click(selector); when.click(selector);
then(get.skipTargetLayerList()).shouldBeFocused(); then(get.skipTargetLayerList()).shouldBeFocused();
}); });
@@ -22,7 +22,7 @@ describe("accessibility", () => {
// 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.
it.skip("skip link to layer editor", () => { it.skip("skip link to layer editor", () => {
const selector = "root:skip:layer-editor"; const selector = "root:skip:layer-editor";
should.exist(selector); then(get.elementByTestId(selector)).shouldExist();
when.tab().tab(); when.tab().tab();
should.beFocused(selector); should.beFocused(selector);
when.click(selector); when.click(selector);
@@ -31,7 +31,7 @@ describe("accessibility", () => {
it("skip link to map view", () => { it("skip link to map view", () => {
const selector = "root:skip:map-view"; const selector = "root:skip:map-view";
should.exist(selector); then(get.elementByTestId(selector)).shouldExist();
when.tab().tab().tab(); when.tab().tab().tab();
should.beFocused(selector); should.beFocused(selector);
when.click(selector); when.click(selector);
+14 -11
View File
@@ -182,7 +182,7 @@ describe("layers", () => {
); );
// AND RESET! // AND RESET!
when.type("{backspace}", "min-zoom.input-text"); when.type("min-zoom.input-text", "{backspace}");
when.click("max-zoom.input-text"); when.click("max-zoom.input-text");
should.equalStyleStore( should.equalStyleStore(
@@ -239,7 +239,7 @@ describe("layers", () => {
); );
// Unset it again. // Unset it again.
when.type("{backspace}{backspace}", "layer-comment.input"); when.type("layer-comment.input", "{backspace}{backspace}");
when.click("min-zoom.input-text"); when.click("min-zoom.input-text");
should.equalStyleStore( should.equalStyleStore(
@@ -459,16 +459,19 @@ describe("layers", () => {
type: "background", type: "background",
}); });
should.beVisible("layer-list-item:foo"); then(get.elementByTestId("layer-list-group:foo")).shouldBeVisible();
then(
should.notBeVisible("layer-list-item:foo_bar"); get.elementByTestId("layer-list-group:foo_bar")
should.notBeVisible("layer-list-item:foo_bar_baz"); ).shouldNotBeVisible();
then(
get.elementByTestId("layer-list-group:foo_bar_baz")
).shouldNotBeVisible();
when.click("layer-list-group:foo-0"); when.click("layer-list-group:foo-0");
then(get.elementByTestId("layer-list-group:foo")).shouldBeVisible();
should.beVisible("layer-list-item:foo"); then(get.elementByTestId("layer-list-group:foo_bar")).shouldBeVisible();
should.beVisible("layer-list-item:foo_bar"); then(
should.beVisible("layer-list-item:foo_bar_baz"); get.elementByTestId("layer-list-group:foo_bar_baz")
).shouldBeVisible();
}); });
}); });
}); });
+11 -18
View File
@@ -15,6 +15,7 @@ export default class MaputnikDriver {
}; };
public given = { public given = {
...this.helper.given,
setupMockBackedResponses: () => { setupMockBackedResponses: () => {
this.helper.given.interceptAndMockResponse({ this.helper.given.interceptAndMockResponse({
method: "GET", method: "GET",
@@ -26,7 +27,7 @@ export default class MaputnikDriver {
}); });
this.helper.given.interceptAndMockResponse({ this.helper.given.interceptAndMockResponse({
method: "GET", method: "GET",
url: baseUrl + "/example-layer-style.json", url: baseUrl + "example-layer-style.json",
response: { response: {
fixture: "example-layer-style.json", fixture: "example-layer-style.json",
}, },
@@ -72,7 +73,7 @@ export default class MaputnikDriver {
this.helper.when.within(fn, selector); this.helper.when.within(fn, selector);
}, },
tab: () => this.helper.get.element("body").tab(), tab: () => this.helper.get.element("body").tab(),
waitForExampleFileRequset: () => { waitForExampleFileResponse: () => {
this.helper.when.waitForResponse("example-style.json"); this.helper.when.waitForResponse("example-style.json");
}, },
chooseExampleFile: () => { chooseExampleFile: () => {
@@ -106,6 +107,7 @@ export default class MaputnikDriver {
if (styleProperties) { if (styleProperties) {
this.helper.when.confirmAlert(); this.helper.when.confirmAlert();
} }
// when methods should not include assertions
this.helper.get.elementByTestId("toolbar:link").should("be.visible"); this.helper.get.elementByTestId("toolbar:link").should("be.visible");
}, },
@@ -150,11 +152,15 @@ export default class MaputnikDriver {
return obj; return obj;
}, },
maputnikStyleFromLocalStorage: () => { maputnikStyleFromLocalStorageObj: () => {
const styleId = localStorage.getItem("maputnik:latest_style"); const styleId = localStorage.getItem("maputnik:latest_style");
const styleItem = localStorage.getItem(`maputnik:style:${styleId}`); const styleItem = localStorage.getItem(`maputnik:style:${styleId}`);
const obj = JSON.parse(styleItem || ""); const obj = JSON.parse(styleItem || "");
return cy.wrap(obj); console.log(obj);
return obj;
},
maputnikStyleFromLocalStorage: () => {
return cy.wrap(this.get.maputnikStyleFromLocalStorageObj());
}, },
exampleFileUrl: () => { exampleFileUrl: () => {
return baseUrl + "example-style.json"; return baseUrl + "example-style.json";
@@ -178,14 +184,6 @@ export default class MaputnikDriver {
this.helper.get.elementByTestId(selector).should("not.have.focus"); this.helper.get.elementByTestId(selector).should("not.have.focus");
}, },
beVisible: (selector: string) => {
this.helper.get.elementByTestId(selector).should("be.visible");
},
notBeVisible: (selector: string) => {
this.helper.get.elementByTestId(selector).should("not.be.visible");
},
equalStyleStore: (getter: (obj: any) => any, styleObj: any) => { equalStyleStore: (getter: (obj: any) => any, styleObj: any) => {
cy.window().then((win: any) => { cy.window().then((win: any) => {
const obj = this.get.styleFromWindow(win); const obj = this.get.styleFromWindow(win);
@@ -196,23 +194,18 @@ 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);
const bobj = this.get.maputnikStyleFromLocalStorageObj();
this.helper.given this.helper.given
.fixture("example-style.json", "file:example-style.json") .fixture("example-style.json", "file:example-style.json")
.should("deep.equal", obj); .should("deep.equal", obj);
}); });
}, },
exist: (selector: string) => {
this.helper.get.elementByTestId(selector).should("exist");
},
beSelected: (selector: string, value: string) => { beSelected: (selector: string, value: string) => {
this.helper.get this.helper.get
.elementByTestId(selector) .elementByTestId(selector)
.find(`option[value="${value}"]`) .find(`option[value="${value}"]`)
.should("be.selected"); .should("be.selected");
}, },
containText: (selector: string, text: string) => {
this.helper.get.elementByTestId(selector).should("contain.text", text);
},
}; };
} }
+69 -37
View File
@@ -1,9 +1,11 @@
import { then } from "@shellygo/cypress-test-utils/assertable";
import MaputnikDriver from "./maputnik-driver"; import MaputnikDriver from "./maputnik-driver";
describe("modals", () => { describe("modals", () => {
let { beforeAndAfter, when, get, should } = new MaputnikDriver(); let { beforeAndAfter, given, when, get, should } = new MaputnikDriver();
beforeAndAfter(); beforeAndAfter();
beforeEach(() => { beforeEach(() => {
given.fixture("example-style.json", "file:example-style.json");
when.setStyle(""); when.setStyle("");
}); });
describe("open", () => { describe("open", () => {
@@ -11,7 +13,8 @@ describe("modals", () => {
when.click("nav:open"); when.click("nav:open");
}); });
it.only("close", () => { it.skip("close", () => {
// Asserting non existence is an anti-pattern
when.modal.close("modal:open"); when.modal.close("modal:open");
should.notExist("modal:open"); should.notExist("modal:open");
}); });
@@ -19,26 +22,51 @@ describe("modals", () => {
it.skip("upload", () => { it.skip("upload", () => {
// HM: I was not able to make the following choose file actually to select a file and close the modal... // HM: I was not able to make the following choose file actually to select a file and close the modal...
when.chooseExampleFile(); when.chooseExampleFile();
then(get.responseBody("example-style.json")).shouldDeepEqual(
should.styleStoreEqualToExampleFileData(); get.maputnikStyleFromLocalStorageObj()
);
}); });
it("load from url", () => { describe("when click open url", () => {
let styleFileUrl = get.exampleFileUrl(); beforeEach(() => {
let styleFileUrl = get.exampleFileUrl();
when.setValue("modal:open.url.input", styleFileUrl); when.setValue("modal:open.url.input", styleFileUrl);
when.click("modal:open.url.button"); when.click("modal:open.url.button");
when.waitForExampleFileRequset(); });
it.only("load from url", () => {
// expect(
// Cypress._.isMatch(
// get.maputnikStyleFromLocalStorageObj(),
// get.responseBody("example-style.json")
// )
// ).to.be.true;
should.styleStoreEqualToExampleFileData(); // expect(
// Cypress._.isMatch(
// get.maputnikStyleFromLocalStorageObj(),
// { shelly: true }
// //get.responseBody("example-style.json")
// )
// );
should.styleStoreEqualToExampleFileData();
// then(get.fixture("file:example-style.json")).should(
// "deep.equal",
// get.maputnikStyleFromLocalStorageObj()
// );
// then(get.responseBody("example-style.json")).shouldDeepNestedInclude(
// get.maputnikStyleFromLocalStorageObj()
// );
});
}); });
}); });
describe("shortcuts", () => { describe("shortcuts", () => {
it("open/close", () => { it.skip("open/close", () => {
when.setStyle(""); when.setStyle("");
when.typeKeys("?"); when.typeKeys("?");
when.modal.close("modal:shortcuts"); when.modal.close("modal:shortcuts");
// Anti pattern. we should test that things exist. million things don't exist
should.notExist("modal:shortcuts"); should.notExist("modal:shortcuts");
}); });
}); });
@@ -48,7 +76,7 @@ describe("modals", () => {
when.click("nav:export"); when.click("nav:export");
}); });
it("close", () => { it.skip("close", () => {
when.modal.close("modal:export"); when.modal.close("modal:export");
should.notExist("modal:export"); should.notExist("modal:export");
}); });
@@ -65,9 +93,9 @@ describe("modals", () => {
describe("inspect", () => { describe("inspect", () => {
it("toggle", () => { it("toggle", () => {
// There is no assertion in this test
when.setStyle("geojson"); when.setStyle("geojson");
when.select("maputnik-select", "inspect");
when.selectWithin("nav:inspect", "inspect");
}); });
}); });
@@ -78,35 +106,40 @@ describe("modals", () => {
it("name", () => { it("name", () => {
when.click("field-doc-button-Name"); when.click("field-doc-button-Name");
then(get.elementsText("spec-field-doc")).shouldContainText(
should.containText("spec-field-doc", "name for the style"); "name for the style"
);
}); });
it("show name specifications", () => { it("show name specifications", () => {
when.setValue("modal:settings.name", "foobar"); when.setValue("modal:settings.name", "foobar");
when.click("modal:settings.owner"); when.click("modal:settings.owner");
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
should.equalStyleStore((obj) => obj.name, "foobar"); name: "foobar",
});
}); });
it("owner", () => { it("owner", () => {
when.setValue("modal:settings.owner", "foobar"); when.setValue("modal:settings.owner", "foobar");
when.click("modal:settings.name"); when.click("modal:settings.name");
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
should.equalStyleStore((obj) => obj.owner, "foobar"); owner: "foobar",
});
}); });
it("sprite url", () => { it("sprite url", () => {
when.setValue("modal:settings.sprite", "http://example.com"); when.setValue("modal:settings.sprite", "http://example.com");
when.click("modal:settings.name"); when.click("modal:settings.name");
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
should.equalStyleStore((obj) => obj.sprite, "http://example.com"); sprite: "http://example.com",
});
}); });
it("glyphs url", () => { it("glyphs url", () => {
let glyphsUrl = "http://example.com/{fontstack}/{range}.pbf"; let glyphsUrl = "http://example.com/{fontstack}/{range}.pbf";
when.setValue("modal:settings.glyphs", glyphsUrl); when.setValue("modal:settings.glyphs", glyphsUrl);
when.click("modal:settings.name"); when.click("modal:settings.name");
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
should.equalStyleStore((obj) => obj.glyphs, glyphsUrl); glyphs: glyphsUrl,
});
}); });
it("maptiler access token", () => { it("maptiler access token", () => {
@@ -116,11 +149,9 @@ describe("modals", () => {
apiKey apiKey
); );
when.click("modal:settings.name"); when.click("modal:settings.name");
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
should.equalStyleStore( metadata: { "maputnik:openmaptiles_access_token": apiKey },
(obj) => obj.metadata["maputnik:openmaptiles_access_token"], });
apiKey
);
}); });
it("thunderforest access token", () => { it("thunderforest access token", () => {
@@ -130,21 +161,22 @@ describe("modals", () => {
apiKey apiKey
); );
when.click("modal:settings.name"); when.click("modal:settings.name");
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
should.equalStyleStore( metadata: { "maputnik:thunderforest_access_token": apiKey },
(obj) => obj.metadata["maputnik:thunderforest_access_token"], });
apiKey
);
}); });
it("style renderer", () => { it("style renderer", () => {
cy.on("uncaught:exception", () => false); // this is due to the fact that this is an invalid style for openlayers cy.on("uncaught:exception", () => false); // this is due to the fact that this is an invalid style for openlayers
when.select("modal:settings.maputnik:renderer", "ol"); when.select("modal:settings.maputnik:renderer", "ol");
should.beSelected("modal:settings.maputnik:renderer", "ol"); then(get.inputValue("modal:settings.maputnik:renderer")).shouldEqual(
"ol"
);
when.click("modal:settings.name"); when.click("modal:settings.name");
then(get.maputnikStyleFromLocalStorage()).shouldDeepNestedInclude({
should.equalStyleStore((obj) => obj.metadata["maputnik:renderer"], "ol"); metadata: { "maputnik:renderer": "ol" },
});
}); });
}); });