mirror of
https://github.com/bringout/oca-ocb-report.git
synced 2026-04-21 10:42:01 +02:00
19.0 vanilla
This commit is contained in:
parent
62d197ac8b
commit
184bb0e321
667 changed files with 691406 additions and 239886 deletions
|
|
@ -0,0 +1,84 @@
|
|||
import { animationFrame } from "@odoo/hoot-mock";
|
||||
import { LoadableDataSource } from "@spreadsheet/data_sources/data_source";
|
||||
import { Deferred } from "@web/core/utils/concurrency";
|
||||
import { makeServerError } from "@web/../tests/web_test_helpers";
|
||||
import { describe, expect, test } from "@odoo/hoot";
|
||||
import { defineSpreadsheetActions, defineSpreadsheetModels } from "../helpers/data";
|
||||
|
||||
describe.current.tags("headless");
|
||||
|
||||
defineSpreadsheetModels();
|
||||
defineSpreadsheetActions();
|
||||
|
||||
test("data source is ready after all concurrent requests are resolved", async () => {
|
||||
const def1 = new Deferred();
|
||||
const def2 = new Deferred();
|
||||
let req = 0;
|
||||
class TestDataSource extends LoadableDataSource {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.data = null;
|
||||
}
|
||||
async _load() {
|
||||
this.data = null;
|
||||
switch (++req) {
|
||||
case 1:
|
||||
await def1;
|
||||
break;
|
||||
case 2:
|
||||
await def2;
|
||||
break;
|
||||
}
|
||||
this.data = "something";
|
||||
}
|
||||
}
|
||||
const dataSource = new TestDataSource({
|
||||
odooDataProvider: {
|
||||
notify: () => expect.step("notify"),
|
||||
notifyWhenPromiseResolves: () => expect.step("notify-from-promise"),
|
||||
cancelPromise: () => expect.step("cancel-promise"),
|
||||
},
|
||||
});
|
||||
dataSource.load();
|
||||
expect.verifySteps(["notify-from-promise"]);
|
||||
dataSource.load({ reload: true });
|
||||
expect(dataSource.isReady()).toBe(false);
|
||||
def1.resolve();
|
||||
await animationFrame();
|
||||
expect.verifySteps(["cancel-promise", "notify-from-promise"]);
|
||||
expect(dataSource.isReady()).toBe(false);
|
||||
def2.resolve();
|
||||
await animationFrame();
|
||||
expect(dataSource.isReady()).toBe(true);
|
||||
expect.verifySteps([]);
|
||||
});
|
||||
|
||||
test("Datasources handle errors thrown at _load", async () => {
|
||||
class TestDataSource extends LoadableDataSource {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.data = null;
|
||||
}
|
||||
async _load() {
|
||||
this.data = await this._orm.call();
|
||||
}
|
||||
}
|
||||
|
||||
const dataSource = new TestDataSource({
|
||||
odooDataProvider: {
|
||||
notify: () => expect.step("notify"),
|
||||
notifyWhenPromiseResolves: () => expect.step("notify-from-promise"),
|
||||
cancelPromise: () => expect.step("cancel-promise"),
|
||||
orm: {
|
||||
call: () => {
|
||||
throw makeServerError({ description: "Ya done!" });
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
await dataSource.load();
|
||||
expect.verifySteps(["notify-from-promise"]);
|
||||
expect(dataSource._isFullyLoaded).toBe(true);
|
||||
expect(dataSource._isValid).toBe(false);
|
||||
expect(dataSource._loadError.message).toBe("Ya done!");
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue