From ae30d9db7dd615cd1094e609fb12d683b4efa5c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Sun, 14 Nov 2021 15:39:03 +0100 Subject: [PATCH] [FIX] portal: unskip some tests --- src/misc/portal.ts | 5 ++ tests/misc/__snapshots__/portal.test.ts.snap | 50 ++++++++++++++++++-- tests/misc/portal.test.ts | 27 +++++++---- 3 files changed, 69 insertions(+), 13 deletions(-) diff --git a/src/misc/portal.ts b/src/misc/portal.ts index 741c91ee..25827985 100644 --- a/src/misc/portal.ts +++ b/src/misc/portal.ts @@ -53,6 +53,11 @@ class VPortal extends VText implements Partial> { export class Portal extends Component { static template = xml``; + static props = { + target: { + type: String, + }, + }; constructor(props: any, env: any, node: ComponentNode) { super(props, env, node); diff --git a/tests/misc/__snapshots__/portal.test.ts.snap b/tests/misc/__snapshots__/portal.test.ts.snap index 83e1a870..90edd145 100644 --- a/tests/misc/__snapshots__/portal.test.ts.snap +++ b/tests/misc/__snapshots__/portal.test.ts.snap @@ -372,11 +372,11 @@ exports[`Portal portal with only text as content 1`] = ` exports[`Portal portal with target not in dom 1`] = ` "function anonymous(bdom, helpers ) { - let { text, createBlock, list, multi, html, toggler } = bdom; - let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture } = helpers; + let { text, createBlock, list, multi, html, toggler, component } = bdom; + let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber } = helpers; let assign = Object.assign; - let block1 = createBlock(\`
\`); + let block1 = createBlock(\`
\`); let block2 = createBlock(\`
2
\`); const slot2 = ctx => (node, key) => { @@ -384,7 +384,7 @@ exports[`Portal portal with target not in dom 1`] = ` } return function template(ctx, node, key = \\"\\") { - let b3 = assign(node.getChild(\`Portal\`, {target: '#does-not-exist'}, key + \`__1\`, ctx), {slots: {'default': slot2(ctx)}}); + let b3 = assign(component(\`Portal\`, {target: '#does-not-exist'}, key + \`__1\`, node, ctx), {slots: {'default': slot2(ctx)}}); return block1([], [b3]); } }" @@ -466,6 +466,48 @@ exports[`Portal with target in template (before portal) 1`] = ` }" `; +exports[`Portal: Props validation target is mandatory 1`] = ` +"function anonymous(bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, component } = bdom; + let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber } = helpers; + let assign = Object.assign; + + let block1 = createBlock(\`
\`); + let block2 = createBlock(\`
2
\`); + + const slot2 = ctx => (node, key) => { + return block2(); + } + + return function template(ctx, node, key = \\"\\") { + let b3 = assign(component(\`Portal\`, {}, key + \`__1\`, node, ctx), {slots: {'default': slot2(ctx)}}); + return block1([], [b3]); + } +}" +`; + +exports[`Portal: Props validation target is not list 1`] = ` +"function anonymous(bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, component } = bdom; + let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber } = helpers; + let assign = Object.assign; + + let block1 = createBlock(\`
\`); + let block2 = createBlock(\`
2
\`); + + const slot2 = ctx => (node, key) => { + return block2(); + } + + return function template(ctx, node, key = \\"\\") { + let b3 = assign(component(\`Portal\`, {target: ['body']}, key + \`__1\`, node, ctx), {slots: {'default': slot2(ctx)}}); + return block1([], [b3]); + } +}" +`; + exports[`Portal: UI/UX focus is kept across re-renders 1`] = ` "function anonymous(bdom, helpers ) { diff --git a/tests/misc/portal.test.ts b/tests/misc/portal.test.ts index 2ee53eba..0b753e0e 100644 --- a/tests/misc/portal.test.ts +++ b/tests/misc/portal.test.ts @@ -149,9 +149,7 @@ describe("Portal", () => { ); }); - test.skip("portal with target not in dom", async () => { - // need error handling to unskip this one - + test("portal with target not in dom", async () => { class Parent extends Component { static components = { Portal }; static template = xml` @@ -170,8 +168,8 @@ describe("Portal", () => { } expect(error).toBeDefined(); - expect(error.message).toBe('Could not find any match for "#does-not-exist"'); - expect(fixture.innerHTML).toBe(`
`); + expect(error.message).toBe("invalid portal target"); + expect(fixture.innerHTML).toBe(`
`); }); test("portal with child and props", async () => { @@ -508,7 +506,10 @@ describe("Portal: UI/UX", () => { }); describe("Portal: Props validation", () => { - test.skip("target is mandatory", async () => { + test("target is mandatory", async () => { + const consoleInfo = console.info; + console.info = jest.fn(); + class Parent extends Component { static components = { Portal }; static template = xml` @@ -519,16 +520,21 @@ describe("Portal: Props validation", () => { `; } let error; + let app = new App(Parent); + app.configure({ dev: true }); try { - await mount(Parent, fixture); + await app.mount(fixture); } catch (e) { error = e; } expect(error).toBeDefined(); expect(error.message).toBe(`Missing props 'target' (component 'Portal')`); + console.info = consoleInfo; }); - test.skip("target is not list", async () => { + test("target is not list", async () => { + const consoleInfo = console.info; + console.info = jest.fn(); class Parent extends Component { static components = { Portal }; static template = xml` @@ -539,12 +545,15 @@ describe("Portal: Props validation", () => { `; } let error; + let app = new App(Parent); + app.configure({ dev: true }); try { - await mount(Parent, fixture); + await app.mount(fixture); } catch (e) { error = e; } expect(error).toBeDefined(); expect(error.message).toBe(`Invalid Prop 'target' in component 'Portal'`); + console.info = consoleInfo; }); });