refactoring (action management is now applied in root widget)

This commit is contained in:
Géry Debongnie
2019-03-04 12:52:14 +01:00
parent 0983ff0d24
commit 3a761da764
12 changed files with 75 additions and 196 deletions
+3
View File
@@ -113,6 +113,7 @@ describe("state transitions", () => {
expect(store.services.router.getQuery()).toEqual({ home: true });
await promise;
store.lastAction!.activate();
expect(store.state.inHome).toBe(false);
expect(store.services.router.getQuery()).toEqual({
action_id: "131",
@@ -138,6 +139,8 @@ describe("state transitions", () => {
const promise = store.activateMenuItem(96);
expect(document.title).toBe("Odoo");
await promise;
store.lastAction!.activate();
expect(document.title).toBe("Discuss - Odoo");
store.toggleHomeMenu();
@@ -1,7 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`can be rendered with a non empty stack 1`] = `"<div class=\\"o_content\\"><div>some client action</div></div>"`;
exports[`can be rendered with an empty stack 1`] = `"<div class=\\"o_content\\"></div>"`;
exports[`content is updated properly when new props are given 1`] = `"<div class=\\"o_content\\"><div>some client action</div></div>"`;
@@ -26,6 +26,7 @@ exports[`can be rendered (in home menu) 1`] = `
</a>
</div>
</div>
<div class=\\"o_content o_hidden\\"></div>
<div class=\\"o_notification_container\\"></div>
<div class=\\"o_loading d-none\\">Loading</div>
</div>"
@@ -46,7 +47,7 @@ exports[`if url has action_id, will render action and navigate to proper menu_id
</div>
<div class=\\"o_content\\"><div class=\\"o_discuss\\">
<div class=\\"o_content\\"><div class=\\"o_discuss\\">
<span>DISCUSS!!</span>
<button>Reset first counter</button>
<button>Reset counter 2 in 3s</button>
@@ -73,7 +74,6 @@ exports[`if url has action_id, will render action and navigate to proper menu_id
<button>Add notif</button>
<button>Add sticky notif</button>
</div></div>
<div class=\\"o_notification_container\\"></div>
<div class=\\"o_loading d-none\\">Loading</div>
</div>"
@@ -94,7 +94,7 @@ exports[`start with no action => clicks on client action => discuss is rendered
</div>
<div class=\\"o_content\\"><div class=\\"o_discuss\\">
<div class=\\"o_content\\"><div class=\\"o_discuss\\">
<span>DISCUSS!!</span>
<button>Reset first counter</button>
<button>Reset counter 2 in 3s</button>
@@ -121,7 +121,6 @@ exports[`start with no action => clicks on client action => discuss is rendered
<button>Add notif</button>
<button>Add sticky notif</button>
</div></div>
<div class=\\"o_notification_container\\"></div>
<div class=\\"o_loading d-none\\">Loading</div>
</div>"
@@ -1,70 +0,0 @@
import { Env, makeEnv } from "../../src/ts/env";
import { ActionStack, Store } from "../../src/ts/store/store";
import { ActionContainer, Props } from "../../src/ts/widgets/action_container";
import { Widget } from "../../src/ts/widgets/widget";
import * as helpers from "../helpers";
//------------------------------------------------------------------------------
// Setup and helpers
//------------------------------------------------------------------------------
let fixture: HTMLElement;
let store: Store;
let env: Env;
let props: Props;
let templates: string;
beforeAll(async () => {
templates = await helpers.loadTemplates();
});
beforeEach(() => {
fixture = helpers.makeTestFixture();
store = helpers.makeTestStore();
env = makeEnv(store, templates);
props = { stack: [] };
});
afterEach(() => {
fixture.remove();
});
class ClientAction extends Widget<{}, {}> {
inlineTemplate = "<div>some client action</div>";
}
const demoStack: ActionStack = [
{
id: 33,
context: {},
title: "some title",
target: "new",
type: "client",
Widget: ClientAction
}
];
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
test("can be rendered with an empty stack", async () => {
const container = new ActionContainer(env, props);
await container.mount(fixture);
expect(fixture.innerHTML).toMatchSnapshot();
});
test("can be rendered with a non empty stack", async () => {
props.stack = demoStack;
const container = new ActionContainer(env, props);
await container.mount(fixture);
expect(fixture.innerHTML).toMatchSnapshot();
});
test("content is updated properly when new props are given", async () => {
const container = new ActionContainer(env, props);
await container.mount(fixture);
await container.updateProps({ stack: demoStack });
await helpers.nextTick();
expect(fixture.innerHTML).toMatchSnapshot();
});
+1 -1
View File
@@ -45,12 +45,12 @@ test("if url has action_id, will render action and navigate to proper menu_id",
const root = new Root(env, store);
await root.mount(fixture);
await helpers.nextTick();
expect(env.services.router.getQuery()).toEqual({
action_id: "131",
menu_id: "96"
});
expect(fixture.innerHTML).toMatchSnapshot();
// we check here that the url was changed to set app id as menu_id
});
test("start with no action => clicks on client action => discuss is rendered", async () => {