[FIX] re-introduce tests

This commit is contained in:
Lucas Perais (lpe)
2021-10-18 17:52:25 +02:00
committed by Aaron Bohy
parent d569ea1c28
commit 10df0b5f4a
17 changed files with 616 additions and 79 deletions
+2 -2
View File
@@ -382,7 +382,7 @@ describe("special cases for some specific html attributes/properties", () => {
test.skip("textarea with t-att-value", () => {
// render input with initial value
/* qweb.addTemplate("test", `<textarea t-att-value="v"/>`);
/* qweb.addTemplate("test", `<textarea t-att-value="v"/>`);
const vnode1 = qweb.render("test", { v: "zucchini" });
const vnode2 = patch(document.createElement("textarea"), vnode1);
let elm = vnode2.elm as HTMLInputElement;
@@ -400,7 +400,7 @@ describe("special cases for some specific html attributes/properties", () => {
});
test.skip("select with t-att-value", () => {
/* const template = `
/* const template = `
<select t-att-value="value">
<option value="potato">Potato</option>
<option value="tomato">Tomato</option>
+20 -2
View File
@@ -126,7 +126,7 @@ describe("simple templates, mostly static", () => {
describe("loading templates", () => {
test.skip("can initialize qweb with a string", () => {
/* const templates = `<?xml version="1.0" encoding="UTF-8"?>
/* const templates = `<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<div t-name="hey">jupiler</div>
</templates>`;
@@ -152,4 +152,22 @@ describe("loading templates", () => {
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", "<div>global</div>");
// expect(qweb.templates.mytemplate).toBeDefined();
// const vnode = qweb.render("mytemplate");
// expect(vnode.sel).toBe("div");
// expect((vnode as any).children[0].text).toBe("global");
});
});
+22
View File
@@ -0,0 +1,22 @@
describe("properly support svg", () => {
test.skip("add proper namespace to svg", () => {
// qweb.addTemplate(
// "test",
// `<svg width="100px" height="90px"><circle cx="50" cy="50" r="4" stroke="green" stroke-width="1" fill="yellow"/> </svg>`
// );
// expect(renderToString(qweb, "test")).toBe(
// `<svg width=\"100px\" height=\"90px\"><circle cx=\"50\" cy=\"50\" r=\"4\" stroke=\"green\" stroke-width=\"1\" fill=\"yellow\"></circle> </svg>`
// );
});
test.skip("add proper namespace to g tags", () => {
// this is necessary if one wants to use components in a svg
// qweb.addTemplate(
// "test",
// `<g><circle cx="50" cy="50" r="4" stroke="green" stroke-width="1" fill="yellow"/> </g>`
// );
// expect(renderToString(qweb, "test")).toBe(
// `<g><circle cx=\"50\" cy=\"50\" r=\"4\" stroke=\"green\" stroke-width=\"1\" fill=\"yellow\"></circle> </g>`
// );
});
});
+7
View File
@@ -15,6 +15,13 @@ describe("t-call (template calling)", () => {
expect(context.renderToString("caller")).toBe("<div><span>ok</span></div>");
});
test.skip("t-call, global templates", () => {
// QWeb.registerTemplate("abcd", '<div><t t-call="john"/></div>');
// qweb.addTemplate("john", `<span>desk</span>`);
// const expected = "<div><span>desk</span></div>";
// expect(trim(renderToString(qweb, "abcd"))).toBe(expected);
});
test("basic caller, no parent node", () => {
const context = new TestContext();
context.addTemplate("_basic-callee", `<span>ok</span>`);
+15
View File
@@ -14,6 +14,21 @@ describe("debugging", () => {
console.log = consoleLog;
});
test.skip("t-debug on sub template", () => {
// const consoleLog = console.log;
// console.log = jest.fn();
// qweb.addTemplates(`
// <templates>
// <p t-name="sub" t-debug="">coucou</p>
// <div t-name="test">
// <t t-call="sub"/>
// </div>
// </templates>`);
// qweb.render("test");
// expect(console.log).toHaveBeenCalledTimes(1);
// console.log = consoleLog;
});
test("t-log", () => {
const consoleLog = console.log;
console.log = jest.fn();
+22
View File
@@ -23,6 +23,28 @@ describe("t-foreach", () => {
expect(renderToString(template)).toBe(expected);
});
test.skip("t-key on t-foreach", async () => {
// qweb.addTemplate(
// "test",
// `
// <div>
// <t t-foreach="things" t-as="thing" t-key="thing">
// <span/>
// </t>
// </div>`
// );
// let vnode = qweb.render("test", { things: [1, 2] });
// vnode = patch(document.createElement("div"), vnode);
// let elm = vnode.elm as HTMLElement;
// expect(elm.outerHTML).toBe("<div><span></span><span></span></div>");
// const first = elm.querySelectorAll("span")[0];
// const second = elm.querySelectorAll("span")[1];
// patch(vnode, qweb.render("test", { things: [2, 1] }));
// expect(elm.outerHTML).toBe("<div><span></span><span></span></div>");
// expect(first).toBe(elm.querySelectorAll("span")[1]);
// expect(second).toBe(elm.querySelectorAll("span")[0]);
});
test("simple iteration (in a node)", () => {
const template = `
<div>
+22
View File
@@ -0,0 +1,22 @@
describe.skip("t-key", () => {
test("can use t-key directive on a node", () => {
// qweb.addTemplate("test", `<div t-key="beer.id"><t t-esc="beer.name"/></div>`);
// expect(renderToString(qweb, "test", { beer: { id: 12, name: "Chimay Rouge" } })).toBe(
// "<div>Chimay Rouge</div>"
// );
});
test("t-key directive in a list", () => {
// qweb.addTemplate(
// "test",
// `<ul>
// <li t-foreach="beers" t-as="beer" t-key="beer.id"><t t-esc="beer.name"/></li>
// </ul>`
// );
// expect(
// renderToString(qweb, "test", {
// beers: [{ id: 12, name: "Chimay Rouge" }],
// })
// ).toMatchSnapshot();
});
});