import { renderToString, snapshotEverything, TestContext } from "../helpers"; snapshotEverything(); // ----------------------------------------------------------------------------- // Simple templates, mostly static // ----------------------------------------------------------------------------- describe("simple templates, mostly static", () => { test("simple string", () => { const template = `hello vdom`; expect(renderToString(template)).toBe("hello vdom"); }); test("simple string in t tag", () => { const template = `hello vdom`; expect(renderToString(template)).toBe("hello vdom"); }); test("empty string", () => { const template = ``; expect(renderToString(template)).toBe(""); }); test("empty string in a template set", () => { const template = ``; const context = new TestContext(); context.addTemplate("potato", template); expect(context.renderToString("potato")).toBe(""); }); test("empty div", () => { const template = `
`; expect(renderToString(template)).toBe("
"); }); test("div with content", () => { const template = `
foo
`; expect(renderToString(template)).toBe("
foo
"); }); test("multiple root nodes", () => { const template = `
foo
hey`; expect(renderToString(template)).toBe("
foo
hey"); }); test("dynamic text value", () => { const template = ``; expect(renderToString(template, { text: "owl" })).toBe("owl"); }); test("two t-escs next to each other", () => { const template = ``; expect(renderToString(template, { text1: "hello", text2: "owl" })).toBe("helloowl"); }); test("two t-escs next to each other", () => { const template = ``; expect(renderToString(template, { text1: "hello", text2: "owl" })).toBe("helloowl"); }); test("two t-escs next to each other, in a div", () => { const template = `
`; expect(renderToString(template, { text1: "hello", text2: "owl" })).toBe("
helloowl
"); }); test("static text and dynamic text", () => { const template = `hello `; expect(renderToString(template, { text: "owl" })).toBe("hello owl"); }); test("static text and dynamic text (no t tag)", () => { const template = `hello `; expect(renderToString(template, { text: "owl" })).toBe("hello owl"); }); test("t-esc in dom node", () => { const template = `
`; expect(renderToString(template, { text: "hello owl" })).toBe("
hello owl
"); }); test("dom node with t-esc", () => { const template1 = `
`; expect(renderToString(template1, { text: "hello owl" })).toBe("
hello owl
"); const template2 = `
`; expect(renderToString(template2, { text: "hello owl" })).toBe("
hello owl
"); }); test("t-esc in dom node, variations", () => { const template1 = `
hello
`; expect(renderToString(template1, { text: "owl" })).toBe("
hello owl
"); const template2 = `
hello world
`; expect(renderToString(template2, { text: "owl" })).toBe("
hello owl world
"); }); test("div with a class attribute", () => { const template = `
foo
`; expect(renderToString(template)).toBe(`
foo
`); }); test("div with a class attribute with a quote", () => { const template = `
word
`; expect(renderToString(template)).toBe(`
word
`); }); test("div with an arbitrary attribute with a quote", () => { const template = `
word
`; expect(renderToString(template)).toBe(`
word
`); }); test("div with an empty class attribute", () => { const template = `
word
`; expect(renderToString(template)).toBe(`
word
`); }); test("div with a span child node", () => { const template = `
word
`; expect(renderToString(template)).toBe("
word
"); }); test("can render a table row", () => { const template = `cell`; expect(renderToString(template)).toBe(template); }); }); describe("loading templates", () => { test.skip("can initialize qweb with a string", () => { /* const templates = `
jupiler
`; const qweb = new QWeb({ templates }); expect(renderToString(qweb, "hey")).toBe("
jupiler
");*/ }); test.skip("can load a few templates from a xml string", () => { /*const data = `
  • ok
  • foo
    `; qweb.addTemplates(data); const result = renderToString(qweb, "main"); expect(result).toBe("
    • ok
    • foo
    ");*/ }); test.skip("does not crash if string does not have templates", () => { /*const data = ""; qweb.addTemplates(data); expect(Object.keys(qweb.templates)).toEqual([]);*/ }); }); describe("global template registration", () => { test.skip("can register template globally", () => { // expect.assertions(5); // let qweb = new QWeb(); // try { // qweb.render("mytemplate"); // } catch (e) { // expect(e.message).toMatch("Template mytemplate does not exist"); // } // expect(qweb.templates.mytemplate).toBeUndefined(); // QWeb.registerTemplate("mytemplate", "
    global
    "); // expect(qweb.templates.mytemplate).toBeDefined(); // const vnode = qweb.render("mytemplate"); // expect(vnode.sel).toBe("div"); // expect((vnode as any).children[0].text).toBe("global"); }); });