move demo code to examples/

This commit is contained in:
Géry Debongnie
2019-03-15 12:15:37 +01:00
parent d99ea4c9f4
commit 46aedf78af
1638 changed files with 32 additions and 29 deletions
@@ -0,0 +1,66 @@
import { MenuInfo } from "../../src/ts/store/store";
import { Navbar, Props } from "../../src/ts/ui/navbar";
import * as helpers from "../helpers";
//------------------------------------------------------------------------------
// Setup and helpers
//------------------------------------------------------------------------------
let fixture: HTMLElement;
let env: helpers.TestEnv;
let props: Props;
let menuInfo: MenuInfo;
beforeEach(() => {
fixture = helpers.makeTestFixture();
env = helpers.makeTestEnv();
props = { inHome: false, app: null };
menuInfo = env.store.menuInfo;
});
afterEach(() => {
fixture.remove();
});
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
test("can be rendered (in home menu, no app)", async () => {
props.inHome = true;
const navbar = new Navbar(env, props);
await navbar.mount(fixture);
expect(fixture.innerHTML).toMatchSnapshot();
});
test("can be rendered (in home menu, one active app)", async () => {
props = { inHome: true, app: menuInfo.menus[96]! };
const navbar = new Navbar(env, props);
await navbar.mount(fixture);
expect(fixture.innerHTML).toMatchSnapshot();
});
test("can render one menu item", async () => {
props.app = menuInfo.menus[96]!;
const navbar = new Navbar(env, props);
await navbar.mount(fixture);
expect(fixture.innerHTML).toMatchSnapshot();
});
test("mobile mode: navbar is different", async () => {
props.app = menuInfo.menus[205]!;
env.isMobile = true;
const navbar = new Navbar(env, props);
await navbar.mount(fixture);
expect(fixture.innerHTML).toMatchSnapshot();
});
test("clicking on left icon toggle home menu ", async () => {
props.app = menuInfo.menus[96]!;
env.store.state.inHome = false;
const navbar = new Navbar(env, props);
await navbar.mount(fixture);
expect(env.store.state.inHome).toBe(false);
(<any>fixture).getElementsByClassName("o_title")[0].click();
expect(env.store.state.inHome).toBe(true);
});