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

chore: remove redundant statement for autocomplete in Input #571

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
4 changes: 0 additions & 4 deletions src/lib/components/Input.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,6 @@
({ selectionStart, selectionEnd } = inputElement);
};

$: step = inputType === "number" ? (step ?? "any") : undefined;
$: autocomplete =
inputType !== "number" && !currency ? (autocomplete ?? "off") : undefined;

let displayInnerEnd: boolean;
$: displayInnerEnd = nonNullish($$slots["inner-end"]);
</script>
Expand Down
60 changes: 59 additions & 1 deletion src/tests/lib/components/Input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import InputTest from "./InputTest.svelte";
import InputValueTest from "./InputValueTest.svelte";

describe("Input", () => {
type InputType = "icp" | "number" | "text" | "currency";
type AutoComplete = "on" | "off" | undefined;

const props = { name: "name", placeholder: "test.placeholder" };

it("should render an input", () => {
Expand Down Expand Up @@ -34,7 +37,7 @@ describe("Input", () => {
container,
}: {
attribute: string;
expected: string;
expected: string | null | undefined;
container: HTMLElement;
}) => {
const input: HTMLInputElement | null = container.querySelector("input");
Expand Down Expand Up @@ -553,4 +556,59 @@ describe("Input", () => {

expect(input === document.activeElement).toBe(true);
});

describe.each(["number"])("inputType=%s", (inputType) => {
it("should never set autocomplete", () => {
const { container: container1 } = render(Input, {
props: {
...props,
inputType: inputType as InputType,
autocomplete: "off",
},
});

testGetAttribute({
container: container1,
attribute: "autocomplete",
expected: null,
});

const { container: container2 } = render(Input, {
props: {
...props,
inputType: inputType as InputType,
autocomplete: "on",
},
});

testGetAttribute({
container: container2,
attribute: "autocomplete",
expected: null,
});
});
});

describe.each(["icp", "text", "currency"])("inputType='%s'", (inputType) => {
describe.each([["on"], ["off"], [undefined, "off"]])(
"autocomplete='%s'",
(autocomplete, expected = undefined) => {
it(`should set autocomplete to '${expected}' for inputType='${inputType}' and autocomplete='${autocomplete}'`, () => {
const { container } = render(Input, {
props: {
...props,
inputType: inputType as InputType,
autocomplete: autocomplete as AutoComplete,
},
});

testGetAttribute({
container,
attribute: "autocomplete",
expected: autocomplete ?? expected,
});
});
},
);
});
});
Loading