mirror of
https://github.com/maputnik/editor.git
synced 2026-08-03 11:47:26 +00:00
Remove maputnik assertable
This commit is contained in:
+3
-21
@@ -4,24 +4,6 @@ import { ModalDriver } from "./modal-driver";
|
|||||||
const baseUrl = "http://localhost:8888/";
|
const baseUrl = "http://localhost:8888/";
|
||||||
const isMac = process.platform === "darwin";
|
const isMac = process.platform === "darwin";
|
||||||
|
|
||||||
export class MaputnikAssertable<T> extends Assertable<T> {
|
|
||||||
constructor(target: T, private readonly getStoredStyle: () => Promise<any>) {
|
|
||||||
super(target);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the object under test (a fixture / response body) contains every
|
|
||||||
* top-level property of the style currently stored in localStorage.
|
|
||||||
*/
|
|
||||||
shouldEqualToStoredStyle = async () => {
|
|
||||||
const expected = await (this.target as any);
|
|
||||||
await this.retry(async () => {
|
|
||||||
const stored = await this.getStoredStyle();
|
|
||||||
this.assertDeepNestedInclude(expected, stored);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The maputnik-specific driver. It builds on the generic {@link PlaywrightHelper}
|
* The maputnik-specific driver. It builds on the generic {@link PlaywrightHelper}
|
||||||
* — spreading its `given`/`when`/`get` primitives and adding domain concepts
|
* — spreading its `given`/`when`/`get` primitives and adding domain concepts
|
||||||
@@ -32,7 +14,7 @@ export class MaputnikDriver {
|
|||||||
private readonly helper = new PlaywrightHelper();
|
private readonly helper = new PlaywrightHelper();
|
||||||
private readonly modalDriver = new ModalDriver(this);
|
private readonly modalDriver = new ModalDriver(this);
|
||||||
|
|
||||||
then = <T>(target: T) => new MaputnikAssertable(target, () => this.readStoredStyle());
|
then = <T>(target: T) => new Assertable(target);
|
||||||
|
|
||||||
/** Reads the maputnik style currently persisted in localStorage. */
|
/** Reads the maputnik style currently persisted in localStorage. */
|
||||||
private async readStoredStyle(): Promise<any> {
|
private async readStoredStyle(): Promise<any> {
|
||||||
@@ -197,12 +179,12 @@ export class MaputnikDriver {
|
|||||||
|
|
||||||
styleFromLocalStorage: () => this.helper.query(() => this.readStoredStyle()),
|
styleFromLocalStorage: () => this.helper.query(() => this.readStoredStyle()),
|
||||||
|
|
||||||
fixture: (name: string) => Promise.resolve(this.helper.readFixture(name)),
|
fixture: (name: string) => this.helper.readFixture(name),
|
||||||
|
|
||||||
responseBody: (alias: string) => {
|
responseBody: (alias: string) => {
|
||||||
// Our mocked style responses always return the matching fixture.
|
// Our mocked style responses always return the matching fixture.
|
||||||
const name = alias.endsWith(".json") ? alias : `${alias}.json`;
|
const name = alias.endsWith(".json") ? alias : `${alias}.json`;
|
||||||
return Promise.resolve(this.helper.readFixture(name));
|
return this.helper.readFixture(name);
|
||||||
},
|
},
|
||||||
|
|
||||||
exampleFileUrl: () => baseUrl + "example-style.json",
|
exampleFileUrl: () => baseUrl + "example-style.json",
|
||||||
|
|||||||
+4
-4
@@ -23,12 +23,12 @@ describe("modals", () => {
|
|||||||
|
|
||||||
test("upload", async () => {
|
test("upload", async () => {
|
||||||
await when.chooseExampleFile();
|
await when.chooseExampleFile();
|
||||||
await then(get.fixture("example-style.json")).shouldEqualToStoredStyle();
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude(get.fixture("example-style.json"));
|
||||||
});
|
});
|
||||||
|
|
||||||
test("upload via drag and drop", async () => {
|
test("upload via drag and drop", async () => {
|
||||||
await when.dropExampleFile();
|
await when.dropExampleFile();
|
||||||
await then(get.fixture("example-style.json")).shouldEqualToStoredStyle();
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude(get.fixture("example-style.json"));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when click open url", () => {
|
describe("when click open url", () => {
|
||||||
@@ -40,7 +40,7 @@ describe("modals", () => {
|
|||||||
await when.wait(200);
|
await when.wait(200);
|
||||||
});
|
});
|
||||||
test("load from url", async () => {
|
test("load from url", async () => {
|
||||||
await then(get.responseBody("example-style.json")).shouldEqualToStoredStyle();
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude(get.responseBody("example-style.json"));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -398,7 +398,7 @@ describe("modals", () => {
|
|||||||
await when.setValue("modal:open.url.input", get.exampleFileUrl());
|
await when.setValue("modal:open.url.input", get.exampleFileUrl());
|
||||||
await when.click("modal:open.url.button");
|
await when.click("modal:open.url.button");
|
||||||
|
|
||||||
await then(get.responseBody("example-style.json")).shouldEqualToStoredStyle();
|
await then(get.styleFromLocalStorage()).shouldDeepNestedInclude(get.responseBody("example-style.json"));
|
||||||
await then(get.styleFromLocalStorage()).shouldExist();
|
await then(get.styleFromLocalStorage()).shouldExist();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -75,12 +75,7 @@ function assertDeepNestedInclude(actual: any, expected: Record<string, unknown>)
|
|||||||
* assertable extends.
|
* assertable extends.
|
||||||
*/
|
*/
|
||||||
export class Assertable<T> {
|
export class Assertable<T> {
|
||||||
constructor(protected readonly target: T) {}
|
constructor(private readonly target: T) {}
|
||||||
|
|
||||||
// Exposed to subclasses (e.g. MaputnikAssertable) so custom assertions can be
|
|
||||||
// built without re-importing these module-private helpers.
|
|
||||||
protected readonly retry = retry;
|
|
||||||
protected readonly assertDeepNestedInclude = assertDeepNestedInclude;
|
|
||||||
|
|
||||||
private locator(): Locator {
|
private locator(): Locator {
|
||||||
if (!isLocator(this.target)) throw new Error("Expected a Locator target for this assertion");
|
if (!isLocator(this.target)) throw new Error("Expected a Locator target for this assertion");
|
||||||
|
|||||||
Reference in New Issue
Block a user