Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(component-library): prevent user from changing value of number field with linked inheritance #484

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rich-pots-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@shopware-ag/meteor-component-library": patch
---

Disable number field when value is inherited
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { render, screen } from "@testing-library/vue";
import MtNumberField from "./mt-number-field.vue";
import { userEvent } from "@storybook/test";

describe("mt-number-field", () => {
it("is not possible to change the value when inheritance is linked", async () => {
// ARRANGE
const handler = vi.fn();

render(MtNumberField, {
props: {
modelValue: 0,
isInheritanceField: true,
isInherited: true,
// @ts-expect-error -- Event exist, but type is not defined via TypeScript
onInputChange: handler,
},
});

// ACT
await userEvent.type(screen.getByRole("textbox"), "1");

// ASSERT
expect(screen.getByRole("textbox")).toBeDisabled();

expect(screen.getByRole("textbox")).toHaveValue("0");
expect(handler).not.toHaveBeenCalled();
});

it("is not possible to increment the value by pressing the increment button when inheritance is linked", async () => {
// ASSERT
const handler = vi.fn();

render(MtNumberField, {
props: {
modelValue: 0,
isInheritanceField: true,
isInherited: true,
// @ts-expect-error -- Event exist, but type is not defined via TypeScript
"onUpdate:modelValue": handler,
},
});

// ACT
await userEvent.click(screen.getByRole("button", { name: "Increase" }));

expect(screen.getByRole("textbox")).toHaveValue("0");
expect(handler).not.toHaveBeenCalled();
});

it("is not possible to decrement the value by pressing the decrement button when inheritance is linked", async () => {
// ASSERT
const handler = vi.fn();

render(MtNumberField, {
props: {
modelValue: 0,
isInheritanceField: true,
isInherited: true,
// @ts-expect-error -- Event exist, but type is not defined via TypeScript
"onUpdate:modelValue": handler,
},
});

// ACT
await userEvent.click(screen.getByRole("button", { name: "Decrease" }));

expect(screen.getByRole("textbox")).toHaveValue("0");
expect(handler).not.toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<mt-base-field
class="mt-number-field"
:class="$attrs.class"
:disabled="disabled"
:disabled="disabled || isInherited"
:required="required"
:is-inherited="isInherited"
:is-inheritance-field="isInheritanceField"
Expand Down Expand Up @@ -31,7 +31,7 @@
:id="createInputId(identification)"
type="text"
:name="identification"
:disabled="disabled"
:disabled="disabled || isInherited"
:value="stringRepresentation"
:placeholder="placeholder"
:class="numberAlignEnd ? 'mt-number-field__align-end' : ''"
Expand All @@ -46,7 +46,7 @@
<div class="mt-number-field__controls" :class="controlClasses">
<button
@click="increaseNumberByStep"
:disabled="disabled"
:disabled="disabled || isInherited"
:aria-label="t('increaseButton')"
data-testid="mt-number-field-increase-button"
>
Expand All @@ -55,7 +55,7 @@

<button
@click="decreaseNumberByStep"
:disabled="disabled"
:disabled="disabled || isInherited"
:aria-label="t('decreaseButton')"
data-testid="mt-number-field-decrease-button"
>
Expand Down
Loading