mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
imp: work on store, refactor, improve todoapp
This commit is contained in:
+55
-2
@@ -1,5 +1,11 @@
|
||||
import { Store } from "../src/store";
|
||||
import { nextMicroTick } from "./helpers";
|
||||
import { Store, connect } from "../src/store";
|
||||
import { Component, Env } from "../src/component";
|
||||
import {
|
||||
nextMicroTick,
|
||||
makeTestWEnv,
|
||||
makeTestFixture,
|
||||
nextTick
|
||||
} from "./helpers";
|
||||
|
||||
describe("basic use", () => {
|
||||
test("commit a mutation", () => {
|
||||
@@ -54,3 +60,50 @@ describe("basic use", () => {
|
||||
expect(updateCounter).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("connecting a component to store", () => {
|
||||
let fixture: HTMLElement;
|
||||
let env: Env;
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = makeTestFixture();
|
||||
env = makeTestWEnv();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fixture.remove();
|
||||
});
|
||||
|
||||
class App extends Component<any, any, any> {
|
||||
inlineTemplate = `
|
||||
<div>
|
||||
<t t-foreach="props.todos" t-as="todo">
|
||||
<t t-widget="Todo" t-props="todo"/>
|
||||
</t>
|
||||
</div>`;
|
||||
widgets = { Todo };
|
||||
}
|
||||
class Todo extends Component<any, any, any> {
|
||||
inlineTemplate = `<span><t t-esc="props.msg"/></span>`;
|
||||
}
|
||||
|
||||
test("connecting a component works", async () => {
|
||||
const state = { todos: [] };
|
||||
const mutations = {
|
||||
addTodo(state, msg) {
|
||||
state.todos.push({ msg });
|
||||
}
|
||||
};
|
||||
const TodoApp = connect(s => s)(App);
|
||||
const store = new Store({ state, mutations });
|
||||
(<any>env).store = store;
|
||||
const app = new TodoApp(env);
|
||||
|
||||
await app.mount(fixture);
|
||||
expect(fixture.innerHTML).toMatchSnapshot();
|
||||
|
||||
store.commit("addTodo", "hello");
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user