mirror of
https://github.com/maputnik/editor.git
synced 2026-11-27 04:23:45 +00:00
fix: preview sprites for all sprite-backed properties (#2364)
## Description The sprite picker added in #2359 only replaced the input for `icon-image`. Maputnik already treats `background-pattern`, `fill-pattern`, `line-pattern`, `fill-extrusion-pattern`, and `icon-image` as sprite-backed properties through the shared `iconProperties` list. The other four properties still rendered the text-only autocomplete, so their dropdowns could not preview the sprite atlas even though they use the same sprite catalog in the style spec. This change routes every property in `iconProperties` through `InputSprite`. Non-sprite string fields continue to use `InputString`, and free-form values, search, keyboard selection, and expression editing keep the behavior introduced in #2359. Having one special case for `icon-image` and another branch for the remaining sprite properties was redundant and left the UI inconsistent. This is a follow-up to #2359 and completes the sprite-preview behavior related to #1294 for all sprite-backed style properties. ## Visuals No new visual treatment is introduced. Before this change, the four pattern fields displayed the text-only autocomplete; after this change they display the same thumbnail/search/keyboard picker already shown for `icon-image` in #2359. ## Verification - Added Playwright coverage for `background-pattern`, `fill-pattern`, `line-pattern`, and `fill-extrusion-pattern`. Each case opens the picker, verifies rendered atlas thumbnails, selects a sprite, and asserts the persisted style value. - `npm run lint` - `npm run build` - `npm run test-unit -- --run` (55 tests passed) - `npm run test -- e2e/sprite-picker.spec.ts --workers=1` (19 tests passed) - Confirmed the new assertion fails when the expected option count is deliberately mutated, then restored the assertion. - Local `.npmrc` changes were not included in the commit. ## Launch Checklist - [x] Briefly describe the changes in this PR. - [x] Link to related issues. - [x] Include before/after visuals or gifs if this PR includes visual changes. - [x] Write tests for all new functionality. - [x] Add an entry to `CHANGELOG.md` under the `## main` section. Co-authored-by: FantasticSPM <asd507172@gmail.com>
This commit is contained in:
co-authored by
FantasticSPM
parent
129111357c
commit
1a2c3363ce
+1
-1
@@ -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
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
@@ -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<InputSpecProps> {
|
||||
case "resolvedImage":
|
||||
case "formatted":
|
||||
case "string":
|
||||
if (this.props.fieldName === "icon-image") {
|
||||
return <InputSprite {...commonProps as React.ComponentProps<typeof InputSprite>} />;
|
||||
}
|
||||
if (iconProperties.indexOf(this.props.fieldName!) >= 0) {
|
||||
const options = this.props.fieldSpec.values || [];
|
||||
return <InputAutocomplete
|
||||
{...commonProps as Omit<InputAutocompleteProps, "options">}
|
||||
options={options.map(f => [f, f])}
|
||||
/>;
|
||||
return <InputSprite {...commonProps as React.ComponentProps<typeof InputSprite>} />;
|
||||
} else {
|
||||
return <InputString
|
||||
{...commonProps as InputStringProps}
|
||||
|
||||
Reference in New Issue
Block a user