Skip to content

Commit

Permalink
[REF/IMP] tests: mount owl App in test mode and mount components in h…
Browse files Browse the repository at this point in the history
…elper

Change the parameters of the owl `App` in the test. The `App` will now
be mounted in test mode. The main purpose is to enable props validation,
which ensure that the test is close to the reality, and avoid tests
failing for unclear reasons because a props was missing (d466315).

The Owl test mode is equivalent to dev mode, but without warning that
the app is unsuited for production. Documentation here :
https://github.com/odoo/owl/blob/master/doc/reference/app.md#dev-mode

Also added an helper `mountComponent` and modified the existing helper
`mountSpreadsheet`. The helpers now create and return the fixture in which
the component is mounted. They also register cleanup functions to remove
the fixture and destroy the app, so we don't have to do it manually.
  • Loading branch information
hokolomopo committed Feb 6, 2023
1 parent be95406 commit 0ef6bdb
Show file tree
Hide file tree
Showing 33 changed files with 302 additions and 746 deletions.
11 changes: 1 addition & 10 deletions tests/components/autocomplete_dropdown.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { App } from "@odoo/owl";
import { args, functionRegistry } from "../../src/functions/index";
import { Model } from "../../src/model";
import { selectCell } from "../test_helpers/commands_helpers";
import { click, clickCell, keyDown, keyUp, simulateClick } from "../test_helpers/dom_helper";
import { getCellText } from "../test_helpers/getters_helpers";
import {
clearFunctions,
makeTestFixture,
mountSpreadsheet,
nextTick,
restoreDefaultFunctions,
Expand All @@ -21,7 +19,6 @@ jest.mock("../../src/components/composer/content_editable_helper", () =>
let model: Model;
let composerEl: Element;
let fixture: HTMLElement;
let app: App;
let cehMock: ContentEditableHelper;

async function typeInComposerGrid(text: string, fromScratch: boolean = true) {
Expand All @@ -39,19 +36,13 @@ async function typeInComposerTopBar(text: string, fromScratch: boolean = true) {
}

beforeEach(async () => {
fixture = makeTestFixture();
({ app, model } = await mountSpreadsheet(fixture));
({ model, fixture } = await mountSpreadsheet());

// start composition
await keyDown("Enter");
composerEl = fixture.querySelector(".o-grid div.o-composer")!;
});

afterEach(() => {
fixture.remove();
app.destroy();
});

describe("Functions autocomplete", () => {
beforeEach(() => {
clearFunctions();
Expand Down
13 changes: 3 additions & 10 deletions tests/components/autofill.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { App, Component, xml } from "@odoo/owl";
import { Component, xml } from "@odoo/owl";
import { Spreadsheet } from "../../src";
import {
DEFAULT_CELL_HEIGHT,
Expand All @@ -9,21 +9,14 @@ import {
import { Model } from "../../src/model";
import { setCellContent, setSelection, setViewportOffset } from "../test_helpers/commands_helpers";
import { clickCell, triggerMouseEvent } from "../test_helpers/dom_helper";
import { makeTestFixture, mountSpreadsheet, nextTick, spyDispatch } from "../test_helpers/helpers";
import { mountSpreadsheet, nextTick, spyDispatch } from "../test_helpers/helpers";

let fixture: HTMLElement;
let model: Model;
let parent: Spreadsheet;
let app: App;

beforeEach(async () => {
fixture = makeTestFixture();
({ app, parent, model } = await mountSpreadsheet(fixture));
});

afterEach(() => {
fixture.remove();
app.destroy();
({ parent, model, fixture } = await mountSpreadsheet());
});

describe("Autofill component", () => {
Expand Down
Loading

0 comments on commit 0ef6bdb

Please sign in to comment.