Skip to content

Commit

Permalink
move then into driver
Browse files Browse the repository at this point in the history
  • Loading branch information
shelly_goldblit committed Dec 31, 2023
1 parent f7f6df7 commit b20c54d
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 58 deletions.
4 changes: 2 additions & 2 deletions cypress/e2e/accessibility.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MaputnikDriver, then } 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", () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/history.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MaputnikDriver } from "./maputnik-driver";

describe("history", () => {
let { beforeAndAfter, when, get, should } = new MaputnikDriver();
let { beforeAndAfter, when, get, should, then } = new MaputnikDriver();

Check failure on line 4 in cypress/e2e/history.cy.ts

View workflow job for this annotation

GitHub Actions / build artifacts

'then' is declared but its value is never read.

Check failure on line 4 in cypress/e2e/history.cy.ts

View workflow job for this annotation

GitHub Actions / build on ubuntu-latest

'then' is declared but its value is never read.

Check failure on line 4 in cypress/e2e/history.cy.ts

View workflow job for this annotation

GitHub Actions / build on windows-latest

'then' is declared but its value is never read.

Check failure on line 4 in cypress/e2e/history.cy.ts

View workflow job for this annotation

GitHub Actions / build on macos-latest

'then' is declared but its value is never read.
beforeAndAfter();

let undoKeyCombo: string;
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/keyboard.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MaputnikDriver, then } 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(() => {
Expand Down
52 changes: 25 additions & 27 deletions cypress/e2e/layers.cy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { v1 as uuid } from "uuid";
import { MaputnikDriver, then } 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");
Expand All @@ -18,16 +18,14 @@ describe("layers", () => {
});

it("should update layers in local storage", () => {
then(get.maputnikStyleFromLocalStorage()).shouldIncludeLocalStrorageStyle(
{
layers: [
{
id: id,
type: "background",
},
],
}
);
then(get.maputnikStyleFromLocalStorage()).shouldIncludeLocalStorageStyle({
layers: [
{
id: id,
type: "background",
},
],
});
});

describe("when clicking delete", () => {
Expand All @@ -37,7 +35,7 @@ describe("layers", () => {
it("should empty layers in local storage", () => {
then(
get.maputnikStyleFromLocalStorage()
).shouldIncludeLocalStrorageStyle({
).shouldIncludeLocalStorageStyle({
layers: [],
});
});
Expand All @@ -50,7 +48,7 @@ describe("layers", () => {
it("should add copy layer in local storage", () => {
then(
get.maputnikStyleFromLocalStorage()
).shouldIncludeLocalStrorageStyle({
).shouldIncludeLocalStorageStyle({
layers: [
{
id: id + "-copy",
Expand All @@ -73,7 +71,7 @@ describe("layers", () => {
it("should update visibility to none in local storage", () => {
then(
get.maputnikStyleFromLocalStorage()
).shouldIncludeLocalStrorageStyle({
).shouldIncludeLocalStorageStyle({
layers: [
{
id: id,
Expand All @@ -94,7 +92,7 @@ describe("layers", () => {
it("should update visibility to visible in local storage", () => {
then(
get.maputnikStyleFromLocalStorage()
).shouldIncludeLocalStrorageStyle({
).shouldIncludeLocalStorageStyle({
layers: [
{
id: id,
Expand Down Expand Up @@ -184,7 +182,7 @@ describe("layers", () => {
it("should update min-zoom in local storage", () => {
then(
get.maputnikStyleFromLocalStorage()
).shouldIncludeLocalStrorageStyle({
).shouldIncludeLocalStorageStyle({
layers: [
{
id: "background:" + bgId,
Expand All @@ -200,7 +198,7 @@ describe("layers", () => {
when.click("max-zoom.input-text");
then(
get.maputnikStyleFromLocalStorage()
).shouldIncludeLocalStrorageStyle({
).shouldIncludeLocalStorageStyle({
layers: [
{
id: "background:" + bgId,
Expand All @@ -223,7 +221,7 @@ describe("layers", () => {
});

it("should update style in local storage", () => {
then(cy.window()).shouldIncludeLocalStrorageStyle({
then(cy.window()).shouldIncludeLocalStorageStyle({
layers: [
{
id: "background:" + bgId,
Expand All @@ -246,10 +244,10 @@ describe("layers", () => {
when.click("layer-editor.layer-id");
});

it("should update style in local stroage", () => {
it("should update style in local storage", () => {
then(
get.maputnikStyleFromLocalStorage()
).shouldIncludeLocalStrorageStyle({
).shouldIncludeLocalStorageStyle({
layers: [
{
id: "background:" + bgId,
Expand All @@ -264,14 +262,14 @@ describe("layers", () => {

describe("when unsetting", () => {
beforeEach(() => {
when.type("layer-comment.input", "{backspace}{backspace}");
when.clear("layer-comment.input");
when.click("min-zoom.input-text");
});

it("should update style in local storage", () => {
then(
get.maputnikStyleFromLocalStorage()
).shouldIncludeLocalStrorageStyle({
).shouldIncludeLocalStorageStyle({
layers: [
{
id: "background:" + bgId,
Expand All @@ -294,7 +292,7 @@ describe("layers", () => {
it("should update style in local storage", () => {
then(
get.maputnikStyleFromLocalStorage()
).shouldIncludeLocalStrorageStyle({
).shouldIncludeLocalStorageStyle({
layers: [
{
id: "background:" + bgId,
Expand Down Expand Up @@ -501,10 +499,10 @@ describe("layers", () => {
get.elementByTestId("layer-list-group: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();
});
});
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/map.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MaputnikDriver, then } 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", () => {
Expand Down
41 changes: 19 additions & 22 deletions cypress/e2e/maputnik-driver.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
Assertable,
then as baseThen,
} from "@shellygo/cypress-test-utils/assertable";
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/";
Expand All @@ -13,20 +10,17 @@ export class MaputnikAssertable<T> extends Assertable<T> {
const obj = JSON.parse(styleItem || "");
return obj;
};
shouldIncludeLocalStrorageStyle = (styleObj: Object) =>
baseThen(
shouldIncludeLocalStorageStyle = (styleObj: Object) =>
then(
cy.window().then((win) => this.getStyleFromWindow(win))
).shouldDeepNestedInclude(styleObj);

shouldHaveLocalStorageStyle = (styleObj: Object) =>
baseThen(
then(
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 modalDriver = new ModalDriver();
Expand All @@ -38,6 +32,9 @@ export class MaputnikDriver {
});
};

public then = (chainable: Cypress.Chainable<any>) =>
new MaputnikAssertable(chainable);

public given = {
...this.helper.given,
setupMockBackedResponses: () => {
Expand Down Expand Up @@ -111,18 +108,18 @@ export class MaputnikDriver {
) => {
let url = "?debug";
switch (styleProperties) {
case "geojson":
url += `&style=${baseUrl}geojson-style.json`;
break;
case "raster":
url += `&style=${baseUrl}raster-style.json`;
break;
case "both":
url += `&style=${baseUrl}geojson-raster-style.json`;
break;
case "layer":
url += `&style=${baseUrl}/example-layer-style.json`;
break;
case "geojson":
url += `&style=${baseUrl}geojson-style.json`;
break;
case "raster":
url += `&style=${baseUrl}raster-style.json`;
break;
case "both":
url += `&style=${baseUrl}geojson-raster-style.json`;
break;
case "layer":
url += `&style=${baseUrl}/example-layer-style.json`;
break;
}
if (zoom) {
url += `#${zoom}/41.3805/2.1635`;
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/modals.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MaputnikDriver, then } 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(() => {
Expand Down

0 comments on commit b20c54d

Please sign in to comment.