refactoring: widgets -> ui, discuss in subfolder

This commit is contained in:
Géry Debongnie
2019-03-04 14:49:00 +01:00
parent 3a761da764
commit e59b976dcb
20 changed files with 11 additions and 11 deletions
+70
View File
@@ -0,0 +1,70 @@
import { Env, makeEnv } from "../../src/ts/env";
import { Store } from "../../src/ts/store/store";
import { Root } from "../../src/ts/ui/root";
import * as helpers from "../helpers";
//------------------------------------------------------------------------------
// Setup and helpers
//------------------------------------------------------------------------------
let fixture: HTMLElement;
let store: Store;
let env: Env;
let templates: string;
beforeAll(async () => {
templates = await helpers.loadTemplates();
});
beforeEach(() => {
fixture = helpers.makeTestFixture();
store = helpers.makeTestStore();
env = makeEnv(store, templates);
// props = { menuInfo: helpers.makeDemoMenuInfo() };
});
afterEach(() => {
fixture.remove();
});
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
test("can be rendered (in home menu)", async () => {
const root = new Root(env, store);
await root.mount(fixture);
expect(fixture.innerHTML).toMatchSnapshot();
});
test("if url has action_id, will render action and navigate to proper menu_id", async () => {
const router = new helpers.MockRouter({ action_id: "131" });
store = helpers.makeTestStore({ router });
env = makeEnv(store, templates);
await helpers.nextTick();
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();
});
test("start with no action => clicks on client action => discuss is rendered", async () => {
const root = new Root(env, store);
await root.mount(fixture);
expect(env.services.router.getQuery()).toEqual({ home: true });
// discuss menu item
await (<any>document.querySelector('[data-menu="96"]')).click();
await helpers.nextTick();
expect(fixture.innerHTML).toMatchSnapshot();
expect(env.services.router.getQuery()).toEqual({
action_id: "131",
menu_id: "96"
});
});