diff --git a/tests/blockdom/block_attributes.test.ts b/tests/blockdom/block_attributes.test.ts index 20d56187..40aa66f1 100644 --- a/tests/blockdom/block_attributes.test.ts +++ b/tests/blockdom/block_attributes.test.ts @@ -146,58 +146,3 @@ test("class attribute (with a preexisting value", async () => { expect(fixture.innerHTML).toBe(`
`); }); -describe("properties", () => { - test("input with value attribute", () => { - // render input with initial value - const block = createBlock(``); - - const tree = block(["zucchini"]); - mount(tree, fixture); - // const bnode1 = renderToBdom(template, { v: "zucchini" }); - // const fixture = makeTestFixture(); - // mount(bnode1, fixture); - const input = fixture.querySelector("input")!; - expect(input.value).toBe("zucchini"); - - // change value manually in input, to simulate user input - input.value = "tomato"; - expect(input.value).toBe("tomato"); - - // rerender with a different value, and patch actual dom, to check that - // input value was properly reset by owl - patch(tree, block(["potato"])); - expect(input.value).toBe("potato"); - }); - - test("input with value attribute, and falsy value given", () => { - const block = createBlock(``); - - const tree = block([undefined]); - mount(tree, fixture); - const input = fixture.querySelector("input")!; - expect(input.value).toBe(""); - - patch(tree, block([null])); - expect(input.value).toBe(""); - - patch(tree, block([0])); - expect(input.value).toBe("0"); - - patch(tree, block([""])); - expect(input.value).toBe(""); - - patch(tree, block([false])); - expect(input.value).toBe(""); - }); - - test("input type=checkbox with checked attribute", () => { - // render input with initial value - const block = createBlock(``); - - const tree = block([true]); - mount(tree, fixture); - expect(fixture.innerHTML).toBe(``); - const input = fixture.querySelector("input")!; - expect(input.checked).toBe(true); - }); -}); diff --git a/tests/blockdom/block_properties.test.ts b/tests/blockdom/block_properties.test.ts new file mode 100644 index 00000000..cd47b534 --- /dev/null +++ b/tests/blockdom/block_properties.test.ts @@ -0,0 +1,70 @@ +import { mount, patch, createBlock } from "../../src/runtime/blockdom"; +import { makeTestFixture } from "./helpers"; + +//------------------------------------------------------------------------------ +// Setup and helpers +//------------------------------------------------------------------------------ + +let fixture: HTMLElement; + +beforeEach(() => { + fixture = makeTestFixture(); +}); + +afterEach(() => { + fixture.remove(); +}); + +test("input with value attribute", () => { + // render input with initial value + const block = createBlock(``); + + const tree = block(["zucchini"]); + mount(tree, fixture); + // const bnode1 = renderToBdom(template, { v: "zucchini" }); + // const fixture = makeTestFixture(); + // mount(bnode1, fixture); + const input = fixture.querySelector("input")!; + expect(input.value).toBe("zucchini"); + + // change value manually in input, to simulate user input + input.value = "tomato"; + expect(input.value).toBe("tomato"); + + // rerender with a different value, and patch actual dom, to check that + // input value was properly reset by owl + patch(tree, block(["potato"])); + expect(input.value).toBe("potato"); +}); + +test("input with value attribute, and falsy value given", () => { + const block = createBlock(``); + + const tree = block([undefined]); + mount(tree, fixture); + const input = fixture.querySelector("input")!; + expect(input.value).toBe(""); + + patch(tree, block([null])); + expect(input.value).toBe(""); + + patch(tree, block([0])); + expect(input.value).toBe("0"); + + patch(tree, block([""])); + expect(input.value).toBe(""); + + patch(tree, block([false])); + expect(input.value).toBe(""); +}); + +test("input type=checkbox with checked attribute", () => { + // render input with initial value + const block = createBlock(``); + + const tree = block([true]); + mount(tree, fixture); + expect(fixture.innerHTML).toBe(``); + const input = fixture.querySelector("input")!; + expect(input.checked).toBe(true); +}); diff --git a/tests/compiler/__snapshots__/attributes.test.ts.snap b/tests/compiler/__snapshots__/attributes.test.ts.snap index edad8536..9dd9e4b2 100644 --- a/tests/compiler/__snapshots__/attributes.test.ts.snap +++ b/tests/compiler/__snapshots__/attributes.test.ts.snap @@ -28,20 +28,6 @@ exports[`attributes changing a class with t-att-class 1`] = ` }" `; -exports[`attributes changing an attribute with t-att- 1`] = ` -"function anonymous(app, bdom, helpers -) { - let { text, createBlock, list, multi, html, toggler, comment } = bdom; - - let block1 = createBlock(\`
\`); - - return function template(ctx, node, key = \\"\\") { - let attr1 = ctx['v']; - return block1([attr1]); - } -}" -`; - exports[`attributes class and t-att-class should combine together 1`] = ` "function anonymous(app, bdom, helpers ) { @@ -238,62 +224,6 @@ exports[`attributes dynamic formatted attributes with a dash 1`] = ` }" `; -exports[`attributes dynamic input value: falsy values 1`] = ` -"function anonymous(app, bdom, helpers -) { - let { text, createBlock, list, multi, html, toggler, comment } = bdom; - - let block1 = createBlock(\`\`); - - return function template(ctx, node, key = \\"\\") { - let attr1 = new String((0) === 0 ? 0 : ((0) || \\"\\")); - return block1([attr1]); - } -}" -`; - -exports[`attributes dynamic input value: falsy values 2`] = ` -"function anonymous(app, bdom, helpers -) { - let { text, createBlock, list, multi, html, toggler, comment } = bdom; - - let block1 = createBlock(\`\`); - - return function template(ctx, node, key = \\"\\") { - let attr1 = new String((false) === 0 ? 0 : ((false) || \\"\\")); - return block1([attr1]); - } -}" -`; - -exports[`attributes dynamic input value: falsy values 3`] = ` -"function anonymous(app, bdom, helpers -) { - let { text, createBlock, list, multi, html, toggler, comment } = bdom; - - let block1 = createBlock(\`\`); - - return function template(ctx, node, key = \\"\\") { - let attr1 = new String((undefined) === 0 ? 0 : ((undefined) || \\"\\")); - return block1([attr1]); - } -}" -`; - -exports[`attributes dynamic input value: falsy values 4`] = ` -"function anonymous(app, bdom, helpers -) { - let { text, createBlock, list, multi, html, toggler, comment } = bdom; - - let block1 = createBlock(\`\`); - - return function template(ctx, node, key = \\"\\") { - let attr1 = new String(('') === 0 ? 0 : (('') || \\"\\")); - return block1([attr1]); - } -}" -`; - exports[`attributes dynamic undefined class attribute 1`] = ` "function anonymous(app, bdom, helpers ) { @@ -777,20 +707,6 @@ exports[`attributes updating classes (with obj notation) 1`] = ` }" `; -exports[`attributes updating property with falsy value 1`] = ` -"function anonymous(app, bdom, helpers -) { - let { text, createBlock, list, multi, html, toggler, comment } = bdom; - - let block1 = createBlock(\`\`); - - return function template(ctx, node, key = \\"\\") { - let attr1 = new String((ctx['v']) === 0 ? 0 : ((ctx['v']) || \\"\\")); - return block1([attr1]); - } -}" -`; - exports[`attributes various escapes 1`] = ` "function anonymous(app, bdom, helpers ) { @@ -819,114 +735,3 @@ exports[`attributes various escapes 2 1`] = ` } }" `; - -exports[`special cases for some specific html attributes/properties input of type checkbox with t-att-indeterminate 1`] = ` -"function anonymous(app, bdom, helpers -) { - let { text, createBlock, list, multi, html, toggler, comment } = bdom; - - let block1 = createBlock(\`\`); - - return function template(ctx, node, key = \\"\\") { - let attr1 = new Boolean(ctx['v']); - return block1([attr1]); - } -}" -`; - -exports[`special cases for some specific html attributes/properties input type= checkbox, with t-att-checked 1`] = ` -"function anonymous(app, bdom, helpers -) { - let { text, createBlock, list, multi, html, toggler, comment } = bdom; - - let block1 = createBlock(\`\`); - - return function template(ctx, node, key = \\"\\") { - let attr1 = new Boolean(ctx['flag']); - return block1([attr1]); - } -}" -`; - -exports[`special cases for some specific html attributes/properties input with t-att-value (patching with same value 1`] = ` -"function anonymous(app, bdom, helpers -) { - let { text, createBlock, list, multi, html, toggler, comment } = bdom; - - let block1 = createBlock(\`\`); - - return function template(ctx, node, key = \\"\\") { - let attr1 = new String((ctx['v']) === 0 ? 0 : ((ctx['v']) || \\"\\")); - return block1([attr1]); - } -}" -`; - -exports[`special cases for some specific html attributes/properties input with t-att-value 1`] = ` -"function anonymous(app, bdom, helpers -) { - let { text, createBlock, list, multi, html, toggler, comment } = bdom; - - let block1 = createBlock(\`\`); - - return function template(ctx, node, key = \\"\\") { - let attr1 = new String((ctx['v']) === 0 ? 0 : ((ctx['v']) || \\"\\")); - return block1([attr1]); - } -}" -`; - -exports[`special cases for some specific html attributes/properties input, type checkbox, with t-att-checked (patching with same value 1`] = ` -"function anonymous(app, bdom, helpers -) { - let { text, createBlock, list, multi, html, toggler, comment } = bdom; - - let block1 = createBlock(\`\`); - - return function template(ctx, node, key = \\"\\") { - let attr1 = new Boolean(ctx['v']); - return block1([attr1]); - } -}" -`; - -exports[`special cases for some specific html attributes/properties select with t-att-value 1`] = ` -"function anonymous(app, bdom, helpers -) { - let { text, createBlock, list, multi, html, toggler, comment } = bdom; - - let block1 = createBlock(\`\`); - - return function template(ctx, node, key = \\"\\") { - let attr1 = new String((ctx['value']) === 0 ? 0 : ((ctx['value']) || \\"\\")); - return block1([attr1]); - } -}" -`; - -exports[`special cases for some specific html attributes/properties textarea with t-att-value 1`] = ` -"function anonymous(app, bdom, helpers -) { - let { text, createBlock, list, multi, html, toggler, comment } = bdom; - - let block1 = createBlock(\`