// Which fields replace their contents when a dealer reaches for them. const test = require("node:test"); const assert = require("node:assert"); const { Money } = require("./load"); // Enough of an input to answer the question, without a DOM. const field = (props = {}) => ({ tagName: "INPUT", type: "text", inputMode: "", ...props }); test("a number box selects", () => { assert.equal(Money.selectsOnFocus(field({ type: "number" })), true); }); test("a decimal keypad box selects", () => { // The raise pad's amount is type=text with inputmode=decimal, so the phone shows // a number pad without the browser's spinner arrows. assert.equal(Money.selectsOnFocus(field({ type: "text", inputMode: "decimal" })), true); }); test("a name does not", () => { // Selecting all of a name on focus is the same mistake pointing the other way: // a name is a thing you edit, not a suggestion you replace. assert.equal(Money.selectsOnFocus(field({ type: "text" })), false); }); test("a colour swatch does not", () => { assert.equal(Money.selectsOnFocus(field({ type: "color" })), false); }); test("a checkbox does not", () => { assert.equal(Money.selectsOnFocus(field({ type: "checkbox" })), false); }); test("a textarea does not, whatever it is asked", () => { assert.equal(Money.selectsOnFocus({ tagName: "TEXTAREA", type: "text", inputMode: "decimal" }), false); }); test("a select does not", () => { assert.equal(Money.selectsOnFocus({ tagName: "SELECT", type: "select-one" }), false); }); test("case doesn't matter", () => { assert.equal(Money.selectsOnFocus(field({ type: "NUMBER" })), true); assert.equal(Money.selectsOnFocus(field({ type: "TEXT", inputMode: "DECIMAL" })), true); }); test("nothing at all is not a field", () => { assert.equal(Money.selectsOnFocus(null), false); assert.equal(Money.selectsOnFocus(undefined), false); }); test("a field with no type stated is a text box, so it does not", () => { assert.equal(Money.selectsOnFocus({ tagName: "INPUT" }), false); });