diff --git a/cypress/e2e/driver.ts b/cypress/e2e/driver.ts index 71762db2..d1c142fb 100644 --- a/cypress/e2e/driver.ts +++ b/cypress/e2e/driver.ts @@ -71,7 +71,7 @@ export default class MaputnikDriver { if (styleProperties) { cy.on("window:confirm", () => true); } - cy.get(".maputnik-toolbar-link").should("be.visible"); + this.helper.get.element("toolbar:link").should("be.visible"); }, fillLayersModal: (opts: {type: string, layer?: string, id?: string}) => { var type = opts.type; @@ -83,22 +83,24 @@ export default class MaputnikDriver { id = `${type}:${uuid()}`; } - cy.get( - this.get.dataAttribute("add-layer.layer-type", "select") - ).select(type); - cy.get(this.get.dataAttribute("add-layer.layer-id", "input")).type(id); + this.helper.get.element("add-layer.layer-type.select").select(type); + this.helper.get.element("add-layer.layer-id.input").type(id); if (layer) { - cy.get( - this.get.dataAttribute("add-layer.layer-source-block", "input") - ).type(layer); + this.when.within("add-layer.layer-source-block", () => { + cy.get("input").type(layer!); + }) } this.when.click("add-layer"); return id; }, - typeKeys: (keys: string) => { - cy.get("body").type(keys); + typeKeys: (keys: string, selector?: string) => { + if (selector) { + this.helper.get.element(selector).type(keys); + } else { + cy.get("body").type(keys); + } }, click: (selector: string) => { @@ -124,7 +126,7 @@ export default class MaputnikDriver { }, setValue: (selector: string, text: string) => { - cy.get(selector).clear().type(text, { parseSpecialCharSequences: false }); + this.helper.get.element(selector).clear().type(text, { parseSpecialCharSequences: false }); }, closeModal: (key: string) => { @@ -135,8 +137,8 @@ export default class MaputnikDriver { openLayersModal: () => { this.helper.when.click("layer-list:add-layer"); - cy.get(this.get.dataAttribute("modal:add-layer")).should("exist"); - cy.get(this.get.dataAttribute("modal:add-layer")).should("be.visible"); + this.helper.get.element("modal:add-layer").should("exist"); + this.helper.get.element("modal:add-layer").should("be.visible"); }, }; @@ -153,9 +155,6 @@ export default class MaputnikDriver { exampleFileUrl: () => { return "http://localhost:8888/example-style.json"; }, - dataAttribute: (key: string, selector?: string): string => { - return `*[data-wd-key='${key}'] ${selector || ""}`; - }, }; public should = { diff --git a/cypress/e2e/layers.cy.ts b/cypress/e2e/layers.cy.ts index 41efdb43..ad685c42 100644 --- a/cypress/e2e/layers.cy.ts +++ b/cypress/e2e/layers.cy.ts @@ -134,10 +134,7 @@ describe("layers", () => { var id = uuid(); when.selectWithin("add-layer.layer-type", "background"); - when.setValue( - get.dataAttribute("add-layer.layer-id", "input"), - "background:" + id - ); + when.setValue("add-layer.layer-id.input", "background:" + id); when.click("add-layer"); @@ -162,10 +159,7 @@ describe("layers", () => { when.click("layer-list-item:background:" + bgId); var id = uuid(); - when.setValue( - get.dataAttribute("layer-editor.layer-id", "input"), - "foobar:" + id - ); + when.setValue("layer-editor.layer-id.input", "foobar:" + id); when.click("min-zoom"); should.equalStyleStore( @@ -183,10 +177,7 @@ describe("layers", () => { var bgId = createBackground(); when.click("layer-list-item:background:" + bgId); - when.setValue( - get.dataAttribute("min-zoom", 'input[type="text"]'), - "1" - ); + when.setValue("min-zoom.input-text", "1"); when.click("layer-editor.layer-id"); @@ -202,25 +193,20 @@ describe("layers", () => { ); // AND RESET! - // driver.setValue(driver.get.dataAttribute("min-zoom", "input"), "") - // driver.click(driver.get.dataAttribute("max-zoom", "input")); - - // driver.isStyleStoreEqual((a: any) => a.layers, [ - // { - // "id": 'background:'+bgId, - // "type": 'background' - // } - // ]); + when.typeKeys("{backspace}", "min-zoom.input-text"); + when.click("max-zoom.input-text"); + + should.equalStyleStore((a: any) => a.layers, [{ + "id": 'background:'+bgId, + "type": 'background' + }]); }); it("max-zoom", () => { var bgId = createBackground(); when.click("layer-list-item:background:" + bgId); - when.setValue( - get.dataAttribute("max-zoom", 'input[type="text"]'), - "1" - ); + when.setValue("max-zoom.input-text", "1"); when.click("layer-editor.layer-id"); @@ -238,10 +224,10 @@ describe("layers", () => { it("comments", () => { var bgId = createBackground(); - var id = uuid(); + var comment = "42"; when.click("layer-list-item:background:" + bgId); - when.setValue(get.dataAttribute("layer-comment", "textarea"), id); + when.setValue("layer-comment.input", comment); when.click("layer-editor.layer-id"); @@ -252,23 +238,20 @@ describe("layers", () => { id: "background:" + bgId, type: "background", metadata: { - "maputnik:comment": id, + "maputnik:comment": comment, }, }, ] ); // Unset it again. - // TODO: This fails - // driver.setValue(driver.getDataAttribute("layer-comment", "textarea"), ""); - // driver.click(driver.getDataAttribute("min-zoom", "input")); - - // driver.isStyleStoreEqual((a: any) => a.layers, [ - // { - // "id": 'background:'+bgId, - // "type": 'background' - // } - // ]); + when.typeKeys("{backspace}{backspace}", "layer-comment.input"); + when.click("min-zoom.input-text"); + + should.equalStyleStore((a: any) => a.layers, [{ + "id": 'background:' + bgId, + "type": 'background' + }]); }); it("color", () => { diff --git a/cypress/e2e/modals.cy.ts b/cypress/e2e/modals.cy.ts index 911deef6..117a159a 100644 --- a/cypress/e2e/modals.cy.ts +++ b/cypress/e2e/modals.cy.ts @@ -26,7 +26,7 @@ describe("modals", () => { it("load from url", () => { var styleFileUrl = get.exampleFileUrl(); - when.setValue(get.dataAttribute("modal:open.url.input"), styleFileUrl); + when.setValue("modal:open.url.input", styleFileUrl); when.click("modal:open.url.button"); when.waitForExampleFileRequset(); @@ -83,30 +83,27 @@ describe("modals", () => { }); it("show name specifications", () => { - when.setValue(get.dataAttribute("modal:settings.name"), "foobar"); + when.setValue("modal:settings.name", "foobar"); when.click("modal:settings.owner"); should.equalStyleStore((obj) => obj.name, "foobar"); }); it("owner", () => { - when.setValue(get.dataAttribute("modal:settings.owner"), "foobar"); + when.setValue("modal:settings.owner", "foobar"); when.click("modal:settings.name"); should.equalStyleStore((obj) => obj.owner, "foobar"); }); it("sprite url", () => { - when.setValue( - get.dataAttribute("modal:settings.sprite"), - "http://example.com" - ); + when.setValue("modal:settings.sprite", "http://example.com"); when.click("modal:settings.name"); should.equalStyleStore((obj) => obj.sprite, "http://example.com"); }); it("glyphs url", () => { var glyphsUrl = "http://example.com/{fontstack}/{range}.pbf"; - when.setValue(get.dataAttribute("modal:settings.glyphs"), glyphsUrl); + when.setValue("modal:settings.glyphs", glyphsUrl); when.click("modal:settings.name"); should.equalStyleStore((obj) => obj.glyphs, glyphsUrl); @@ -115,9 +112,7 @@ describe("modals", () => { it("maptiler access token", () => { var apiKey = "testing123"; when.setValue( - get.dataAttribute( - "modal:settings.maputnik:openmaptiles_access_token" - ), + "modal:settings.maputnik:openmaptiles_access_token", apiKey ); when.click("modal:settings.name"); @@ -130,12 +125,7 @@ describe("modals", () => { it("thunderforest access token", () => { var apiKey = "testing123"; - when.setValue( - get.dataAttribute( - "modal:settings.maputnik:thunderforest_access_token" - ), - apiKey - ); + when.setValue("modal:settings.maputnik:thunderforest_access_token", apiKey); when.click("modal:settings.name"); should.equalStyleStore( diff --git a/src/components/AppMessagePanel.tsx b/src/components/AppMessagePanel.tsx index 76d9b9dd..9897d50b 100644 --- a/src/components/AppMessagePanel.tsx +++ b/src/components/AppMessagePanel.tsx @@ -1,5 +1,5 @@ import React from 'react' -import {formatLayerId} from '../util/format'; +import {formatLayerId} from '../libs/format'; import {LayerSpecification, StyleSpecification} from 'maplibre-gl'; type AppMessagePanelProps = { diff --git a/src/components/AppToolbar.tsx b/src/components/AppToolbar.tsx index db676a00..835f5f3d 100644 --- a/src/components/AppToolbar.tsx +++ b/src/components/AppToolbar.tsx @@ -36,6 +36,7 @@ class ToolbarLink extends React.Component { href={this.props.href} rel="noopener noreferrer" target="_blank" + data-wd-key="toolbar:link" > {this.props.children} @@ -56,6 +57,7 @@ class ToolbarLinkHighlighted extends React.Component {this.props.children} diff --git a/src/components/FieldComment.tsx b/src/components/FieldComment.tsx index 5bf06b64..8a7f18ad 100644 --- a/src/components/FieldComment.tsx +++ b/src/components/FieldComment.tsx @@ -26,6 +26,7 @@ export default class FieldComment extends React.Component { value={this.props.value} onChange={this.props.onChange} default="Comment..." + data-wd-key="layer-comment.input" /> } diff --git a/src/components/FieldFunction.tsx b/src/components/FieldFunction.tsx index 94a6d3bb..4ef904eb 100644 --- a/src/components/FieldFunction.tsx +++ b/src/components/FieldFunction.tsx @@ -5,7 +5,7 @@ import DataProperty, { Stop } from './_DataProperty' import ZoomProperty from './_ZoomProperty' import ExpressionProperty from './_ExpressionProperty' import {function as styleFunction} from '@maplibre/maplibre-gl-style-spec'; -import {findDefaultFromSpec} from '../util/spec-helper'; +import {findDefaultFromSpec} from '../libs/spec-helper'; function isLiteralExpression(value: any) { diff --git a/src/components/FieldId.tsx b/src/components/FieldId.tsx index e78dfc30..f64ddacb 100644 --- a/src/components/FieldId.tsx +++ b/src/components/FieldId.tsx @@ -20,6 +20,7 @@ export default class FieldId extends React.Component { } diff --git a/src/components/FieldMaxZoom.tsx b/src/components/FieldMaxZoom.tsx index 69f20eaf..5f9dc833 100644 --- a/src/components/FieldMaxZoom.tsx +++ b/src/components/FieldMaxZoom.tsx @@ -23,6 +23,7 @@ export default class FieldMaxZoom extends React.Component { min={latest.layer.maxzoom.minimum} max={latest.layer.maxzoom.maximum} default={latest.layer.maxzoom.maximum} + data-wd-key="max-zoom.input" /> } diff --git a/src/components/FieldMinZoom.tsx b/src/components/FieldMinZoom.tsx index f61b0a4a..3faa4557 100644 --- a/src/components/FieldMinZoom.tsx +++ b/src/components/FieldMinZoom.tsx @@ -23,6 +23,7 @@ export default class FieldMinZoom extends React.Component { min={latest.layer.minzoom.minimum} max={latest.layer.minzoom.maximum} default={latest.layer.minzoom.minimum} + data-wd-key='min-zoom.input' /> } diff --git a/src/components/FieldType.tsx b/src/components/FieldType.tsx index 77f9d74a..f87c3f49 100644 --- a/src/components/FieldType.tsx +++ b/src/components/FieldType.tsx @@ -44,6 +44,7 @@ export default class FieldType extends React.Component { ]} onChange={this.props.onChange} value={this.props.value} + data-wd-key={this.props.wdKey + ".select"} /> } diff --git a/src/components/InputJson.tsx b/src/components/InputJson.tsx index 544fbe29..35a8dd4a 100644 --- a/src/components/InputJson.tsx +++ b/src/components/InputJson.tsx @@ -8,7 +8,7 @@ import 'codemirror/addon/edit/matchbrackets' import 'codemirror/lib/codemirror.css' import 'codemirror/addon/lint/lint.css' import stringifyPretty from 'json-stringify-pretty-compact' -import '../util/codemirror-mgl'; +import '../libs/codemirror-mgl'; export type InputJsonProps = { diff --git a/src/components/InputNumber.tsx b/src/components/InputNumber.tsx index 56a34116..24ce52d1 100644 --- a/src/components/InputNumber.tsx +++ b/src/components/InputNumber.tsx @@ -9,7 +9,7 @@ export type InputNumberProps = { onChange?(value: number | undefined): unknown allowRange?: boolean rangeStep?: number - wdKey?: string + "data-wd-key"?: string required?: boolean "aria-label"?: string }; @@ -197,6 +197,7 @@ export default class InputNumber extends React.Component } @@ -233,6 +236,7 @@ export default class InputNumber extends React.Component } } diff --git a/src/components/LayerEditor.tsx b/src/components/LayerEditor.tsx index 8165f54c..701ff68e 100644 --- a/src/components/LayerEditor.tsx +++ b/src/components/LayerEditor.tsx @@ -18,7 +18,7 @@ import FieldSource from './FieldSource' import FieldSourceLayer from './FieldSourceLayer' import { changeType, changeProperty } from '../libs/layer' import layout from '../config/layout.json' -import {formatLayerId} from '../util/format'; +import {formatLayerId} from '../libs/format'; function getLayoutForType(type: LayerSpecification["type"]) { diff --git a/src/components/_DataProperty.tsx b/src/components/_DataProperty.tsx index 11a638e7..243976ba 100644 --- a/src/components/_DataProperty.tsx +++ b/src/components/_DataProperty.tsx @@ -10,9 +10,9 @@ import InputSelect from './InputSelect' import Block from './Block' import docUid from '../libs/document-uid' import sortNumerically from '../libs/sort-numerically' -import {findDefaultFromSpec} from '../util/spec-helper'; +import {findDefaultFromSpec} from '../libs/spec-helper'; -import labelFromFieldName from './_labelFromFieldName' +import labelFromFieldName from '../libs/label-from-field-name' import DeleteStopButton from './_DeleteStopButton' diff --git a/src/components/_ExpressionProperty.tsx b/src/components/_ExpressionProperty.tsx index 2ef27e03..e91dbf74 100644 --- a/src/components/_ExpressionProperty.tsx +++ b/src/components/_ExpressionProperty.tsx @@ -4,7 +4,7 @@ import stringifyPretty from 'json-stringify-pretty-compact' import Block from './Block' import InputButton from './InputButton' -import labelFromFieldName from './_labelFromFieldName' +import labelFromFieldName from '../libs/label-from-field-name' import FieldJson from './FieldJson' diff --git a/src/components/_FieldComment.tsx b/src/components/_FieldComment.tsx deleted file mode 100644 index 4d7c22a7..00000000 --- a/src/components/_FieldComment.tsx +++ /dev/null @@ -1,31 +0,0 @@ -import React from 'react' - -import Block from './Block' -import FieldString from './FieldString' - -type BlockCommentProps = { - value?: string - onChange(...args: unknown[]): unknown -}; - -export default class BlockComment extends React.Component { - render() { - const fieldSpec = { - doc: "Comments for the current layer. This is non-standard and not in the spec." - }; - - return - - - } -} - diff --git a/src/components/_FieldFont.tsx b/src/components/_FieldFont.tsx deleted file mode 100644 index 23043294..00000000 --- a/src/components/_FieldFont.tsx +++ /dev/null @@ -1,61 +0,0 @@ -import React from 'react' -import Block from './Block' -import FieldAutocomplete from './FieldAutocomplete' - -type FieldFontProps = { - value?: string[] - default?: string[] - fonts?: unknown[] - style?: object - onChange(...args: unknown[]): unknown - label?: string -}; - -export default class FieldFont extends React.Component { - static defaultProps = { - fonts: [] - } - - get values() { - const out = this.props.value || this.props.default || []; - - // Always put a "" in the last field to you can keep adding entries - if (out[out.length-1] !== ""){ - return out.concat(""); - } - else { - return out; - } - } - - changeFont(idx: number, newValue: string) { - const changedValues = this.values.slice(0) - changedValues[idx] = newValue - const filteredValues = changedValues - .filter(v => v !== undefined) - .filter(v => v !== "") - - this.props.onChange(filteredValues); - } - - render() { - const inputs = this.values.map((value, i) => { - return
  • - [f, f])} - onChange={this.changeFont.bind(this, i)} - /> -
  • - }) - - return -
      - {inputs} -
    -
    - } -} - diff --git a/src/components/_FieldId.tsx b/src/components/_FieldId.tsx deleted file mode 100644 index f8fa46b1..00000000 --- a/src/components/_FieldId.tsx +++ /dev/null @@ -1,27 +0,0 @@ -import React from 'react' - -import {latest} from '@maplibre/maplibre-gl-style-spec' -import Block from './Block' -import FieldString from './FieldString' - -type BlockIdProps = { - value: string - wdKey: string - onChange(...args: unknown[]): unknown - error?: {message: string} -}; - -export default class BlockId extends React.Component { - render() { - return - - - } -} - diff --git a/src/components/_FieldMaxZoom.tsx b/src/components/_FieldMaxZoom.tsx deleted file mode 100644 index 2499bb85..00000000 --- a/src/components/_FieldMaxZoom.tsx +++ /dev/null @@ -1,30 +0,0 @@ -import React from 'react' - -import {latest} from '@maplibre/maplibre-gl-style-spec' -import Block from './Block' -import FieldNumber from './FieldNumber' - -type BlockMaxZoomProps = { - value?: number - onChange(...args: unknown[]): unknown - error?: {message: string} -}; - -export default class BlockMaxZoom extends React.Component { - render() { - return - - - } -} - diff --git a/src/components/_FieldMinZoom.tsx b/src/components/_FieldMinZoom.tsx deleted file mode 100644 index 3b48b5c8..00000000 --- a/src/components/_FieldMinZoom.tsx +++ /dev/null @@ -1,30 +0,0 @@ -import React from 'react' - -import {latest} from '@maplibre/maplibre-gl-style-spec' -import Block from './Block' -import FieldNumber from './FieldNumber' - -type BlockMinZoomProps = { - value?: number - onChange(...args: unknown[]): unknown - error?: {message: string} -}; - -export default class BlockMinZoom extends React.Component { - render() { - return - - - } -} - diff --git a/src/components/_FieldSource.tsx b/src/components/_FieldSource.tsx deleted file mode 100644 index 0598b989..00000000 --- a/src/components/_FieldSource.tsx +++ /dev/null @@ -1,36 +0,0 @@ -import React from 'react' - -import {latest} from '@maplibre/maplibre-gl-style-spec' -import Block from './Block' -import FieldAutocomplete from './FieldAutocomplete' - -type BlockSourceProps = { - value?: string - wdKey?: string - onChange?(...args: unknown[]): unknown - sourceIds?: unknown[] - error?: {message: string} -}; - -export default class BlockSource extends React.Component { - static defaultProps = { - onChange: () => {}, - sourceIds: [], - } - - render() { - return - [src, src])} - /> - - } -} - diff --git a/src/components/_FieldSourceLayer.tsx b/src/components/_FieldSourceLayer.tsx deleted file mode 100644 index 06e2f83c..00000000 --- a/src/components/_FieldSourceLayer.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import React from 'react' - -import {latest} from '@maplibre/maplibre-gl-style-spec' -import Block from './Block' -import FieldAutocomplete from './FieldAutocomplete' - -type BlockSourceLayerProps = { - value?: string - onChange?(...args: unknown[]): unknown - sourceLayerIds?: unknown[] - isFixed?: boolean -}; - -export default class BlockSourceLayer extends React.Component { - static defaultProps = { - onChange: () => {}, - sourceLayerIds: [], - isFixed: false - } - - render() { - return - [l, l])} - /> - - } -} - diff --git a/src/components/_FieldSymbol.tsx b/src/components/_FieldSymbol.tsx deleted file mode 100644 index 261354e4..00000000 --- a/src/components/_FieldSymbol.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import React from 'react' -import FieldAutocomplete from './FieldAutocomplete' - - -type FieldSymbolProps = { - value?: string - icons?: unknown[] - onChange(...args: unknown[]): unknown -}; - - -export default class FieldSymbol extends React.Component { - static defaultProps = { - icons: [] - } - - render() { - return [f, f])} - onChange={this.props.onChange} - /> - } -} - diff --git a/src/components/_FieldType.tsx b/src/components/_FieldType.tsx deleted file mode 100644 index f23b684d..00000000 --- a/src/components/_FieldType.tsx +++ /dev/null @@ -1,52 +0,0 @@ -import React from 'react' - -import {latest} from '@maplibre/maplibre-gl-style-spec' -import Block from './Block' -import FieldSelect from './FieldSelect' -import FieldString from './FieldString' - -type BlockTypeProps = { - value: string - wdKey?: string - onChange(...args: unknown[]): unknown - error?: {message: string} - disabled?: boolean -}; - -export default class BlockType extends React.Component { - static defaultProps = { - disabled: false, - } - - render() { - return - {this.props.disabled && - - } - {!this.props.disabled && - - } - - } -} - diff --git a/src/components/_SpecProperty.tsx b/src/components/_SpecProperty.tsx index dc4b877e..9138467c 100644 --- a/src/components/_SpecProperty.tsx +++ b/src/components/_SpecProperty.tsx @@ -3,7 +3,7 @@ import React from 'react' import SpecField, {SpecFieldProps} from './SpecField' import FunctionButtons from './_FunctionButtons' -import labelFromFieldName from './_labelFromFieldName' +import labelFromFieldName from '../libs/label-from-field-name' type SpecPropertyProps = SpecFieldProps & { diff --git a/src/components/_ZoomProperty.tsx b/src/components/_ZoomProperty.tsx index 3eba8ebd..a21afd78 100644 --- a/src/components/_ZoomProperty.tsx +++ b/src/components/_ZoomProperty.tsx @@ -9,7 +9,7 @@ import InputSelect from './InputSelect' import Block from './Block' import DeleteStopButton from './_DeleteStopButton' -import labelFromFieldName from './_labelFromFieldName' +import labelFromFieldName from '../libs/label-from-field-name' import docUid from '../libs/document-uid' import sortNumerically from '../libs/sort-numerically' diff --git a/src/util/codemirror-mgl.ts b/src/libs/codemirror-mgl.ts similarity index 100% rename from src/util/codemirror-mgl.ts rename to src/libs/codemirror-mgl.ts diff --git a/src/util/format.ts b/src/libs/format.ts similarity index 100% rename from src/util/format.ts rename to src/libs/format.ts diff --git a/src/components/_labelFromFieldName.ts b/src/libs/label-from-field-name.ts similarity index 100% rename from src/components/_labelFromFieldName.ts rename to src/libs/label-from-field-name.ts diff --git a/src/util/spec-helper.ts b/src/libs/spec-helper.ts similarity index 100% rename from src/util/spec-helper.ts rename to src/libs/spec-helper.ts