Skip to content

Commit

Permalink
[FIX] tests: mount owl App in test mode and mount components in helper
Browse files Browse the repository at this point in the history
This commit is a backport of original merged in PR #2045, it was
introduced as it diminishes drastically the sources of errors when
mounting OWL components.

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.

closes #2045

Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com>
Part-of: #2258
  • Loading branch information
hokolomopo authored and rrahir committed Mar 22, 2023
1 parent b68c248 commit a17319c
Show file tree
Hide file tree
Showing 32 changed files with 986 additions and 1,427 deletions.
2 changes: 1 addition & 1 deletion tests/components/__snapshots__/context_menu.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Standalone context menu tests Context Menu context menu simple rendering 1`] = `
exports[`Context Menu integration tests context menu simple rendering 1`] = `
<div
class="o-menu"
>
Expand Down
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 { clickCell } from "../test_helpers/dom_helper";
import { getCellText } from "../test_helpers/getters_helpers";
import {
clearFunctions,
makeTestFixture,
mountSpreadsheet,
nextTick,
restoreDefaultFunctions,
Expand All @@ -20,7 +18,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 @@ -32,20 +29,14 @@ async function typeInComposerGrid(text: string, fromScratch: boolean = true) {
}

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

// start composition
fixture.querySelector(".o-grid")!.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter" }));
await nextTick();
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 a17319c

Please sign in to comment.