basic project infrastructure

This commit is contained in:
Géry Debongnie
2019-01-16 13:19:58 +01:00
parent 0f3b2d10da
commit f0d529139b
16 changed files with 671 additions and 9 deletions
+2 -2
View File
@@ -1,5 +1,5 @@
import QWeb from "../src/qweb";
import { EvalContext } from "../src/qweb";
import QWeb from "../src/core/qweb";
import { EvalContext } from "../src/core/qweb";
function renderToDOM(t: string, context: EvalContext = {}): DocumentFragment {
+1 -1
View File
@@ -1,4 +1,4 @@
import { escape, htmlTrim } from "../src/utils";
import { escape, htmlTrim } from "../src/core/utils";
describe("escape", () => {
test("normal strings", () => {
+56
View File
@@ -0,0 +1,56 @@
import Widget from "../src/core/widget";
import QWeb from "../src/core/qweb";
function makeWidget(W: typeof Widget): Widget {
const env = {
qweb: new QWeb(),
services: {}
};
const w = new W(null);
w.setEnvironment(env);
return w;
}
async function click(el: HTMLElement) {
el.click();
return Promise.resolve();
}
const template = `
<div><t t-esc="state.counter"/><button t-on-click="inc">Inc</button></div>
`;
export default class Counter extends Widget {
name = "counter";
template = template;
state = {
counter: 0
};
inc() {
this.updateState({ counter: this.state.counter + 1 });
}
}
describe("basic widget properties", () => {
test("has no el after creation", async () => {
const widget = makeWidget(Widget);
expect(widget.el).toBe(null);
});
test("can be mounted", async () => {
const widget = makeWidget(Widget);
const target = document.createElement("div");
await widget.mount(target);
expect(target.innerHTML).toBe("<div></div>");
});
test("can be clicked on and updated", async () => {
const counter = makeWidget(Counter);
const target = document.createElement("div");
await counter.mount(target);
expect(target.innerHTML).toBe("<div>0<button>Inc</button></div>");
await click((<HTMLElement>counter.el).getElementsByTagName("button")[0]);
expect(target.innerHTML).toBe("<div>1<button>Inc</button></div>");
});
});