diff --git a/CHANGELOG.md b/CHANGELOG.md index dd87111f..f3ffa9d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## main ### ✨ Features and improvements -- Preview sprites in the icon-image dropdown, with searchable names and keyboard selection +- Preview sprites in all sprite-backed dropdowns, including icon-image and pattern properties, with searchable names and keyboard selection - Replace Cypress with Playwright for end-to-end tests and Vitest browser mode (Playwright provider) for component tests; drop the `@shellygo/cypress-test-utils` helper in favour of a `MaputnikDriver` page object - Upgrade to MapLibre GL JS 6 and Vite 8, and update the remaining dependencies - Remove the RTL text plugin, since MapLibre GL JS now renders right-to-left text natively diff --git a/e2e/maputnik-driver.ts b/e2e/maputnik-driver.ts index 31fb1248..968f76d7 100644 --- a/e2e/maputnik-driver.ts +++ b/e2e/maputnik-driver.ts @@ -79,25 +79,25 @@ export class MaputnikDriver { modal: this.modalDriver.when, - openSpritePicker: async () => { - await this.helper.when.click("layer-list-item:symbols"); - await this.helper.when.scrollIntoView("spec-field:icon-image"); - await this.helper.get.elementByTestId("spec-field:icon-image").locator("input").fill(""); + openSpritePicker: async (layerId = "symbols", fieldName = "icon-image") => { + await this.helper.when.click(`layer-list-item:${layerId}`); + await this.helper.when.scrollIntoView(`spec-field:${fieldName}`); + await this.helper.get.elementByTestId(`spec-field:${fieldName}`).locator("input").fill(""); }, - scrollSpritePickerToBottom: () => this.helper.when.scrollIntoView("spec-field:icon-image", "end"), + scrollSpritePickerToBottom: (fieldName = "icon-image") => this.helper.when.scrollIntoView(`spec-field:${fieldName}`, "end"), - searchSprites: (text: string) => this.helper.get.elementByTestId("spec-field-input:icon-image").fill(text), + searchSprites: (text: string, fieldName = "icon-image") => this.helper.get.elementByTestId(`spec-field-input:${fieldName}`).fill(text), chooseSprite: (id: string) => this.helper.when.click(`sprite-option:${id}`), - chooseSpriteWithKeyboard: async () => { - const input = this.helper.get.elementByTestId("spec-field-input:icon-image"); + chooseSpriteWithKeyboard: async (fieldName = "icon-image") => { + const input = this.helper.get.elementByTestId(`spec-field-input:${fieldName}`); await input.press("ArrowDown"); await input.press("Enter"); }, - closeSpritePicker: () => this.helper.get.elementByTestId("spec-field-input:icon-image").press("Escape"), + closeSpritePicker: (fieldName = "icon-image") => this.helper.get.elementByTestId(`spec-field-input:${fieldName}`).press("Escape"), openSpriteStyle: async (name: "sprite-alternate-style" | "sprite-empty-style") => { await this.helper.when.click("nav:open"); diff --git a/e2e/sprite-picker.spec.ts b/e2e/sprite-picker.spec.ts index 653ecbbf..059f7d72 100644 --- a/e2e/sprite-picker.spec.ts +++ b/e2e/sprite-picker.spec.ts @@ -83,6 +83,40 @@ describe("sprite picker", () => { }); }); +describe("sprite-backed properties", () => { + const { given, when, get, then } = new MaputnikDriver(); + const spriteProperties = [ + { layerType: "background", source: undefined, layerId: "background-pattern", property: "background-pattern" }, + { layerType: "fill", source: "points", layerId: "fill-pattern", property: "fill-pattern" }, + { layerType: "line", source: "points", layerId: "line-pattern", property: "line-pattern" }, + { layerType: "fill-extrusion", source: "points", layerId: "fill-extrusion-pattern", property: "fill-extrusion-pattern" }, + ] as const; + + beforeEach(async () => { + await given.setupMockBackedResponses(); + await when.setStyle("sprite"); + }); + + for (const { layerType, source, layerId, property } of spriteProperties) { + test(`${property} uses the sprite preview picker`, async () => { + await when.modal.open(); + await when.modal.fillLayers({ type: layerType, layer: source, id: layerId }); + await when.openSpritePicker(layerId, property); + + await then(get.spriteOptions()).shouldHaveLength(4); + await then(get.spritePixel("red", 8, 8)).shouldDeepNestedInclude([255, 0, 0, 255]); + + await when.chooseSprite("green"); + await then(get.styleFromLocalStorage()).shouldDeepNestedInclude({ + layers: [ + { id: "symbols", layout: { "icon-image": "red" } }, + { id: layerId, paint: { [property]: "green" } }, + ], + }); + }); + } +}); + describe("namespaced sprite picker", () => { const { given, when, get, then } = new MaputnikDriver(); beforeEach(async () => { diff --git a/src/components/InputSpec.tsx b/src/components/InputSpec.tsx index 2fa01f5f..4f7a13e7 100644 --- a/src/components/InputSpec.tsx +++ b/src/components/InputSpec.tsx @@ -7,7 +7,6 @@ import { InputString, type InputStringProps } from "./InputString"; import { InputArray, type InputArrayProps } from "./InputArray"; import { InputDynamicArray, type InputDynamicArrayProps } from "./InputDynamicArray"; import { InputFont, type InputFontProps } from "./InputFont"; -import { InputAutocomplete, type InputAutocompleteProps } from "./InputAutocomplete"; import { InputEnum, type InputEnumProps } from "./InputEnum"; import { InputSprite } from "./InputSprite"; import capitalize from "lodash.capitalize"; @@ -73,15 +72,8 @@ export class InputSpec extends React.Component { case "resolvedImage": case "formatted": case "string": - if (this.props.fieldName === "icon-image") { - return } />; - } if (iconProperties.indexOf(this.props.fieldName!) >= 0) { - const options = this.props.fieldSpec.values || []; - return } - options={options.map(f => [f, f])} - />; + return } />; } else { return