mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] app: improve API, small refactoring
This commit is contained in:
committed by
Mathieu Duckerts-Antoine
parent
f4da50d350
commit
0b1c4dd4ef
@@ -0,0 +1,43 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`app App supports env with getters/setters 1`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||
|
||||
let block1 = createBlock(\`<div><block-text-0/> <block-text-1/></div>\`);
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
let d1 = ctx['env'].someVal;
|
||||
let d2 = Object.keys(ctx['env'].services);
|
||||
return block1([d1, d2]);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`app can configure an app with props 1`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||
|
||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
let d1 = ctx['props'].value;
|
||||
return block1([d1]);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`app destroy remove the widget from the DOM 1`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||
|
||||
let block1 = createBlock(\`<div/>\`);
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
return block1();
|
||||
}
|
||||
}"
|
||||
`;
|
||||
@@ -0,0 +1,62 @@
|
||||
import { App, Component, xml } from "../../src";
|
||||
import { status } from "../../src/component/status";
|
||||
import { makeTestFixture, snapshotEverything, nextTick, elem } from "../helpers";
|
||||
|
||||
let fixture: HTMLElement;
|
||||
|
||||
snapshotEverything();
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = makeTestFixture();
|
||||
});
|
||||
|
||||
describe("app", () => {
|
||||
test("destroy remove the widget from the DOM", async () => {
|
||||
class SomeComponent extends Component {
|
||||
static template = xml`<div/>`;
|
||||
}
|
||||
|
||||
const app = new App(SomeComponent);
|
||||
const comp = await app.mount(fixture);
|
||||
const el = elem(comp);
|
||||
expect(document.contains(el)).toBe(true);
|
||||
app.destroy();
|
||||
expect(document.contains(el)).toBe(false);
|
||||
expect(status(comp)).toBe("destroyed");
|
||||
});
|
||||
|
||||
test("App supports env with getters/setters", async () => {
|
||||
let someVal = "maggot";
|
||||
|
||||
const services: any = { serv1: "" };
|
||||
const env = {
|
||||
get someVal() {
|
||||
return someVal;
|
||||
},
|
||||
services,
|
||||
};
|
||||
|
||||
class SomeComponent extends Component {
|
||||
static template = xml`<div><t t-esc="env.someVal" /> <t t-esc="Object.keys(env.services)" /></div>`;
|
||||
}
|
||||
|
||||
const app = new App(SomeComponent, { env });
|
||||
const comp = await app.mount(fixture);
|
||||
expect(fixture.innerHTML).toBe("<div>maggot serv1</div>");
|
||||
someVal = "brain";
|
||||
services.serv2 = "";
|
||||
comp.render();
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML).toBe("<div>brain serv1,serv2</div>");
|
||||
});
|
||||
|
||||
test("can configure an app with props", async () => {
|
||||
class SomeComponent extends Component {
|
||||
static template = xml`<div t-esc="props.value"/>`;
|
||||
}
|
||||
|
||||
const app = new App(SomeComponent, { props: { value: 333 } });
|
||||
await app.mount(fixture);
|
||||
expect(fixture.innerHTML).toBe("<div>333</div>");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user