diff --git a/addons/board/static/tests/dashboard_tests.js b/addons/board/static/tests/dashboard_tests.js index 5510be32bd9..905a0ff87f1 100644 --- a/addons/board/static/tests/dashboard_tests.js +++ b/addons/board/static/tests/dashboard_tests.js @@ -9,16 +9,12 @@ var ListRenderer = require('web.ListRenderer'); var pyUtils = require('web.py_utils'); const cpHelpers = testUtils.controlPanel; -const { - createWebClient, - doAction, - getActionManagerTestConfig, -} = require("@web/../tests/webclient/actions/helpers"); +const { createWebClient, doAction } = require("@web/../tests/webclient/helpers"); var createView = testUtils.createView; const patchDate = testUtils.mock.patchDate; -let testConfig; +let serverData; QUnit.module('Dashboard', { beforeEach: function () { this.data = { @@ -53,9 +49,8 @@ QUnit.module('Dashboard', { }], }, }; - testConfig = getActionManagerTestConfig(); - // map legacy test data - Object.assign(testConfig.serverData, { models: this.data }); + + serverData = { models: this.data }; }, }); @@ -717,9 +712,9 @@ QUnit.test("save actions to dashboard", async function (assert) { }, }); - testConfig.serverData.models["partner"].fields.foo.sortable = true; + serverData.models.partner.fields.foo.sortable = true; - testConfig.serverData.views = { + serverData.views = { "partner,false,list": '', "partner,false,search": "", }; @@ -752,7 +747,7 @@ QUnit.test("save actions to dashboard", async function (assert) { } }; - const webClient = await createWebClient({ testConfig, mockRPC }); + const webClient = await createWebClient({ serverData, mockRPC }); await doAction(webClient, { id: 1, @@ -785,7 +780,7 @@ QUnit.test("save two searches to dashboard", async function (assert) { // the second search saved should not be influenced by the first assert.expect(2); - testConfig.serverData.views = { + serverData.views = { "partner,false,list": '', "partner,false,search": "", }; @@ -812,7 +807,7 @@ QUnit.test("save two searches to dashboard", async function (assert) { } }; - const webClient = await createWebClient({ testConfig, mockRPC }); + const webClient = await createWebClient({ serverData, mockRPC }); await doAction(webClient, { id: 1, @@ -863,7 +858,7 @@ QUnit.test("save a action domain to dashboard", async function (assert) { // The filter domain already contains the view domain, but is always added by dashboard.., var expected_domain = ["&", view_domain, "&", view_domain, filter_domain]; - testConfig.serverData.views = { + serverData.views = { "partner,false,list": '', "partner,false,search": "", }; @@ -875,7 +870,7 @@ QUnit.test("save a action domain to dashboard", async function (assert) { } }; - const webClient = await createWebClient({ testConfig, mockRPC }); + const webClient = await createWebClient({ serverData, mockRPC }); await doAction(webClient, { id: 1, @@ -1065,13 +1060,13 @@ QUnit.test( const unpatchDate = patchDate(2020, 6, 1, 11, 0, 0); - testConfig.serverData.models.partner.fields.date = { + serverData.models.partner.fields.date = { string: "Date", type: "date", sortable: true, }; - testConfig.serverData.views = { + serverData.views = { "partner,false,pivot": '', "partner,false,search": '', }; @@ -1095,7 +1090,7 @@ QUnit.test( } }; - const webClient = await createWebClient({ testConfig, mockRPC }); + const webClient = await createWebClient({ serverData, mockRPC }); await doAction(webClient, { id: 1, diff --git a/addons/bus/static/tests/assets_watchdog_tests.js b/addons/bus/static/tests/assets_watchdog_tests.js index 73ea72c3f3a..465845a430d 100644 --- a/addons/bus/static/tests/assets_watchdog_tests.js +++ b/addons/bus/static/tests/assets_watchdog_tests.js @@ -5,10 +5,7 @@ import * as BusService from "bus.BusService"; import * as RamStorage from "web.RamStorage"; import * as AbstractStorageService from "web.AbstractStorageService"; -import { - createWebClient, - getActionManagerTestConfig, -} from "@web/../tests/webclient/actions/helpers"; +import { createWebClient } from "@web/../tests/webclient/helpers"; import { assetsWatchdogService } from "@bus/js/services/assets_watchdog_service"; import { click, nextTick, patchWithCleanup } from "@web/../tests/helpers/utils"; import { NotificationContainer } from "@web/core/notifications/notification_container"; @@ -24,13 +21,11 @@ const serviceRegistry = registry.category("services"); QUnit.module("Bus Assets WatchDog", (hooks) => { let legacyServicesRegistry; - let testConfig; hooks.beforeEach((assert) => { legacyServicesRegistry = new legacyRegistry(); legacyServicesRegistry.add("bus_service", BusService); legacyServicesRegistry.add("local_storage", LocalStorageService); - testConfig = getActionManagerTestConfig(); serviceRegistry.add("assetsWatchdog", assetsWatchdogService); clearRegistryWithCleanup(mainComponentRegistry); @@ -68,7 +63,6 @@ QUnit.module("Bus Assets WatchDog", (hooks) => { }; const webClient = await createWebClient({ - testConfig, legacyParams: { serviceRegistry: legacyServicesRegistry }, mockRPC, }); diff --git a/addons/calendar/static/tests/calendar_notification_tests.js b/addons/calendar/static/tests/calendar_notification_tests.js index 28d682da446..161fc70bea7 100644 --- a/addons/calendar/static/tests/calendar_notification_tests.js +++ b/addons/calendar/static/tests/calendar_notification_tests.js @@ -5,10 +5,7 @@ import * as BusService from "bus.BusService"; import * as RamStorage from "web.RamStorage"; import * as AbstractStorageService from "web.AbstractStorageService"; -import { - createWebClient, - getActionManagerTestConfig, -} from "@web/../tests/webclient/actions/helpers"; +import { createWebClient } from "@web/../tests/webclient/helpers"; import { calendarNotificationService } from "@calendar/js/services/calendar_notification_service"; import { click, nextTick, patchWithCleanup } from "@web/../tests/helpers/utils"; import { NotificationContainer } from "@web/core/notifications/notification_container"; @@ -24,13 +21,11 @@ const serviceRegistry = registry.category("services"); QUnit.module("Calendar Notification", (hooks) => { let legacyServicesRegistry; - let testConfig; hooks.beforeEach(() => { legacyServicesRegistry = new legacyRegistry(); legacyServicesRegistry.add("bus_service", BusService); legacyServicesRegistry.add("local_storage", LocalStorageService); - testConfig = getActionManagerTestConfig(); serviceRegistry.add("calendarNotification", calendarNotificationService); clearRegistryWithCleanup(mainComponentRegistry); @@ -83,7 +78,6 @@ QUnit.module("Calendar Notification", (hooks) => { }; const webClient = await createWebClient({ - testConfig, legacyParams: { serviceRegistry: legacyServicesRegistry }, mockRPC, }); @@ -154,7 +148,6 @@ QUnit.module("Calendar Notification", (hooks) => { serviceRegistry.add("action", fakeActionService, { force: true }); const webClient = await createWebClient({ - testConfig, legacyParams: { serviceRegistry: legacyServicesRegistry }, mockRPC, }); @@ -213,7 +206,6 @@ QUnit.module("Calendar Notification", (hooks) => { }; const webClient = await createWebClient({ - testConfig, legacyParams: { serviceRegistry: legacyServicesRegistry }, mockRPC, }); diff --git a/addons/mail/static/src/utils/test_utils.js b/addons/mail/static/src/utils/test_utils.js index 0919be63146..9982a4fb0eb 100644 --- a/addons/mail/static/src/utils/test_utils.js +++ b/addons/mail/static/src/utils/test_utils.js @@ -23,12 +23,7 @@ import { mock, } from 'web.test_utils'; import Widget from 'web.Widget'; -import { - createWebClient, - getActionManagerTestConfig, -} from "@web/../tests/webclient/actions/helpers"; -import { ComponentAdapter } from "web.OwlCompatibility"; -import LegacyMockServer from "web.MockServer"; +import { createWebClient } from "@web/../tests/webclient/helpers"; const { addMockEnvironment, @@ -551,27 +546,22 @@ async function start(param0 = {}) { } }); } else if (hasActionManager) { - let testConfig; - if (!kwargs.testConfig) { - testConfig = getActionManagerTestConfig(); - } else { - testConfig = kwargs.testConfig; - delete kwargs.testConfig; - } + let serverData = kwargs.serverData || {}; + delete kwargs.serverData; if (kwargs.actions) { const actions = {}; kwargs.actions.forEach((act) => { actions[act.xml_id || act.id] = act; }); - Object.assign(testConfig.serverData.actions, actions); + Object.assign(serverData.actions, actions); delete kwargs.actions; } - Object.assign(testConfig.serverData.views, kwargs.archs); + Object.assign(serverData.views, kwargs.archs); delete kwargs.archs; - Object.assign(testConfig.serverData.models, kwargs.data); + Object.assign(serverData.models, kwargs.data); delete kwargs.data; const mockRPC = kwargs.mockRPC; @@ -579,7 +569,7 @@ async function start(param0 = {}) { const legacyParams = kwargs; legacyParams.withLegacyMockServer = true; - const widget = await createWebClient({ testConfig, mockRPC, legacyParams }); + const widget = await createWebClient({ serverData, mockRPC, legacyParams }); legacyPatch(widget, { destroy() { diff --git a/addons/mail/static/tests/activity_tests.js b/addons/mail/static/tests/activity_tests.js index ed32a3dd096..70d02c37b79 100644 --- a/addons/mail/static/tests/activity_tests.js +++ b/addons/mail/static/tests/activity_tests.js @@ -2,13 +2,12 @@ import ActivityView from '@mail/js/views/activity/activity_view'; import testUtils from 'web.test_utils'; -import { createWebClient } from "@web/../tests/webclient/actions/helpers"; import { legacyExtraNextTick, patchWithCleanup } from "@web/../tests/helpers/utils"; -import { doAction, getActionManagerTestConfig } from "@web/../tests/webclient/actions/helpers"; +import { createWebClient, doAction } from "@web/../tests/webclient/helpers"; import { registry } from "@web/core/registry"; -let testConfig; +let serverData; var createView = testUtils.createView; @@ -113,8 +112,7 @@ QUnit.module('activity view', { ], }, }; - testConfig = getActionManagerTestConfig(); - Object.assign(testConfig.serverData.models, this.data); + serverData = { models: this.data }; } }); @@ -361,15 +359,17 @@ QUnit.test('activity view: activity widget', async function (assert) { QUnit.test("activity view: no group_by_menu and no comparison_menu", async function (assert) { assert.expect(4); - testConfig.serverData.actions[1] = { - id: 1, - name: "Task Action", - res_model: "task", - type: "ir.actions.act_window", - views: [[false, "activity"]], + serverData.actions = { + 1: { + id: 1, + name: "Task Action", + res_model: "task", + type: "ir.actions.act_window", + views: [[false, "activity"]], + }, }; - testConfig.serverData.views = { + serverData.views = { "task,false,activity": '' + "" + @@ -393,7 +393,7 @@ QUnit.test("activity view: no group_by_menu and no comparison_menu", async funct patchWithCleanup(odoo.session_info.user_context, { lang: "zz_ZZ" }); - const webClient = await createWebClient({ testConfig, mockRPC , legacyParams: {withLegacyMockServer: true}}); + const webClient = await createWebClient({ serverData, mockRPC , legacyParams: {withLegacyMockServer: true}}); await doAction(webClient, 1); @@ -479,15 +479,17 @@ QUnit.test('activity view: search more to schedule an activity for a record of a QUnit.test("Activity view: discard an activity creation dialog", async function (assert) { assert.expect(2); - testConfig.serverData.actions[1] = { - id: 1, - name: "Task Action", - res_model: "task", - type: "ir.actions.act_window", - views: [[false, "activity"]], + serverData.actions = { + 1: { + id: 1, + name: "Task Action", + res_model: "task", + type: "ir.actions.act_window", + views: [[false, "activity"]], + }, }; - testConfig.serverData.views = { + serverData.views = { "task,false,activity": ` @@ -512,7 +514,7 @@ QUnit.test("Activity view: discard an activity creation dialog", async function } }; - const webClient = await createWebClient({ testConfig, mockRPC, legacyParams: {withLegacyMockServer: true} }); + const webClient = await createWebClient({ serverData, mockRPC, legacyParams: {withLegacyMockServer: true} }); await doAction(webClient, 1); await testUtils.dom.click( diff --git a/addons/mail/static/tests/tools/debug_manager_tests.js b/addons/mail/static/tests/tools/debug_manager_tests.js index dc4243f208b..45b972823c2 100644 --- a/addons/mail/static/tests/tools/debug_manager_tests.js +++ b/addons/mail/static/tests/tools/debug_manager_tests.js @@ -2,11 +2,7 @@ import { manageMessages } from "@mail/js/tools/debug_manager"; import { click, legacyExtraNextTick, patchWithCleanup } from "@web/../tests/helpers/utils"; -import { - createWebClient, - doAction, - getActionManagerTestConfig, -} from "@web/../tests/webclient/actions/helpers"; +import { createWebClient, doAction, getActionManagerServerData } from "@web/../tests/webclient/helpers"; import { debugService } from "@web/core/debug/debug_service"; import { registry } from "@web/core/registry"; @@ -16,14 +12,14 @@ QUnit.test("Manage Messages", async function (assert) { assert.expect(6); patchWithCleanup(odoo, { debug: "1" }); - const testConfig = getActionManagerTestConfig(); + const serverData = getActionManagerServerData(); // Add fake "mail.message" model and arch - testConfig.serverData.models["mail.message"] = { + serverData.models["mail.message"] = { fields: { name: { string: "Name", type: "char" } }, records: [], }; - Object.assign(testConfig.serverData.views, { + Object.assign(serverData.views, { "mail.message,false,list": ``, "mail.message,false,form": `
`, "mail.message,false,search": ``, @@ -44,7 +40,7 @@ QUnit.test("Manage Messages", async function (assert) { } } - const wc = await createWebClient({ testConfig, mockRPC }); + const wc = await createWebClient({ serverData, mockRPC }); await doAction(wc, 3, { viewType: "form", resId: 5 }); await legacyExtraNextTick(); await click(wc.el, ".o_debug_manager .o_dropdown_toggler"); diff --git a/addons/product/static/tests/product_pricelist_report_test.js b/addons/product/static/tests/product_pricelist_report_test.js index a381884a4d0..7e48a976fb0 100644 --- a/addons/product/static/tests/product_pricelist_report_test.js +++ b/addons/product/static/tests/product_pricelist_report_test.js @@ -3,8 +3,9 @@ odoo.define('product.pricelist.report.tests', function (require) { const GeneratePriceList = require('product.generate_pricelist').GeneratePriceList; const testUtils = require('web.test_utils'); -const { createWebClient, getActionManagerTestConfig, doAction } = require('@web/../tests/webclient/actions/helpers'); -let testConfig; +const { createWebClient, doAction } = require('@web/../tests/webclient/helpers'); + +let serverData; QUnit.module('Product Pricelist', { beforeEach: function () { @@ -31,8 +32,7 @@ QUnit.module('Product Pricelist', { }] } }; - testConfig = getActionManagerTestConfig(); - Object.assign(testConfig.serverData, {models: this.data}); + serverData = { models: this.data }; }, }, function () { QUnit.test('Pricelist Client Action', async function (assert) { @@ -57,7 +57,7 @@ QUnit.module('Product Pricelist', { } }; - const webClient = await createWebClient({ testConfig, mockRPC }); + const webClient = await createWebClient({ serverData, mockRPC }); await doAction(webClient, { id: 1, name: 'Generate Pricelist', diff --git a/addons/stock/static/tests/stock_traceability_report_backend_tests.js b/addons/stock/static/tests/stock_traceability_report_backend_tests.js index e5b1f55273c..bdd7fc8375b 100644 --- a/addons/stock/static/tests/stock_traceability_report_backend_tests.js +++ b/addons/stock/static/tests/stock_traceability_report_backend_tests.js @@ -9,7 +9,7 @@ odoo.define('stock.stock_traceability_report_backend_tests', function (require) const { dom: domUtils } = testUtils; const { legacyExtraNextTick } = require("@web/../tests/helpers/utils"); - const { createWebClient, getActionManagerTestConfig, doAction } = require('@web/../tests/webclient/actions/helpers'); + const { createWebClient, doAction } = require('@web/../tests/webclient/helpers'); /** * Helper function to instantiate a stock report action. @@ -93,33 +93,35 @@ odoo.define('stock.stock_traceability_report_backend_tests', function (require) this.__superMounted(...arguments); }, }); - const models = { - partner: { - fields: { - display_name: { string: "Displayed name", type: "char" }, + const serverData = { + models: { + partner: { + fields: { + display_name: { string: "Displayed name", type: "char" }, + }, + records: [ + {id: 1, display_name: "Genda Swami"}, + ], + }, + }, + views: { + 'partner,false,form': '', + 'partner,false,search': '', + }, + actions: { + 42: { + id: 42, + name: "Stock report", + tag: 'stock_report_generic', + type: 'ir.actions.client', + context: {}, + params: {}, }, - records: [ - {id: 1, display_name: "Genda Swami"}, - ], }, }; - let testConfig = getActionManagerTestConfig(); - Object.assign(testConfig.serverData, { models }); - testConfig.serverData.views = { - 'partner,false,form': '
', - 'partner,false,search': '', - }; - testConfig.serverData.actions[42] = { - id: 42, - name: "Stock report", - tag: 'stock_report_generic', - type: 'ir.actions.client', - context: {}, - params: {}, - }; const webClient = await createWebClient({ - testConfig, + serverData, mockRPC: function (route) { if (route === '/web/dataset/call_kw/stock.traceability.report/get_html') { return Promise.resolve({ diff --git a/addons/web/static/tests/core/router_service_tests.js b/addons/web/static/tests/core/router_service_tests.js index 359eec146a1..bf93962bec8 100644 --- a/addons/web/static/tests/core/router_service_tests.js +++ b/addons/web/static/tests/core/router_service_tests.js @@ -9,6 +9,19 @@ import { nextTick, patchWithCleanup } from "../helpers/utils"; async function createRouter(params = {}) { const env = params.env || {}; env.bus = env.bus || new owl.core.EventBus(); + if (params.onPushState) { + const originalPushState = browser.history.pushState; + const onPushState = params.onPushState; + delete params.onPushState; + patchWithCleanup(browser, { + history: Object.assign({}, browser.history, { + pushState() { + originalPushState(...arguments); + onPushState(...arguments); + }, + }), + }); + } const router = await makeFakeRouterService(params).start(env); return router; } diff --git a/addons/web/static/tests/helpers/mock_services.js b/addons/web/static/tests/helpers/mock_services.js index ad951c30a1c..c6b949e485c 100644 --- a/addons/web/static/tests/helpers/mock_services.js +++ b/addons/web/static/tests/helpers/mock_services.js @@ -126,61 +126,17 @@ export function makeMockFetch(mockRPC) { }; } -function makeMockLocation() { - const locationLink = Object.assign(document.createElement("a"), { - href: window.location.origin + window.location.pathname, - assign(url) { - this.href = url; - }, - reload() {}, - }); - return new Proxy(locationLink, { - get(target, p) { - return target[p]; - }, - set(target, p, value) { - target[p] = value; - if (p === "hash") { - window.dispatchEvent(new HashChangeEvent("hashchange")); - } - return true; - }, - }); -} - /** * @param {Object} [params={}] - * @param {Object} [params.initialRoute] initial route object - * @param {Object} [params.onPushState] hook on the "pushState" method - * @param {Object} [params.onReplaceState] hook on the "onReplaceState" method * @param {Object} [params.onRedirect] hook on the "redirect" method * @returns {typeof routerService} */ export function makeFakeRouterService(params = {}) { - const mockLocation = makeMockLocation(); - Object.assign(mockLocation, params.initialRoute); - patchWithCleanup(browser, { - location: mockLocation, - history: { - pushState(state, title, url) { - mockLocation.assign(url); - if (params.onPushState) { - params.onPushState(url); - } - }, - replaceState(state, title, url) { - mockLocation.assign(url); - if (params.onReplaceState) { - params.onReplaceState(url); - } - }, - }, - }); return { start({ bus }) { const router = routerService.start(...arguments); bus.on("test:hashchange", null, (hash) => { - mockLocation.hash = objectToUrlEncodedString(hash); + browser.location.hash = objectToUrlEncodedString(hash); }); registerCleanup(router.cancelPushes); patchWithCleanup(router, { diff --git a/addons/web/static/tests/legacy/control_panel/search_bar_tests.js b/addons/web/static/tests/legacy/control_panel/search_bar_tests.js index 40375ca8e9d..79cebce327f 100644 --- a/addons/web/static/tests/legacy/control_panel/search_bar_tests.js +++ b/addons/web/static/tests/legacy/control_panel/search_bar_tests.js @@ -1,16 +1,12 @@ /** @odoo-module alias="web.search_bar_tests" **/ import testUtils from "web.test_utils"; -import { - createWebClient, - doAction, - getActionManagerTestConfig, -} from "@web/../tests/webclient/actions/helpers"; +import { createWebClient, doAction } from "@web/../tests/webclient/helpers"; import { Model } from "web.Model"; import Registry from "web.Registry"; import SearchBar from "web.SearchBar"; -let testConfig; +let serverData; // legacy stuff let cpHelpers; @@ -20,10 +16,7 @@ QUnit.module("Search Bar (legacy)", (hooks) => { cpHelpers = testUtils.controlPanel; }); hooks.beforeEach(() => { - testConfig = getActionManagerTestConfig(); - }); - hooks.beforeEach(() => { - const serverData = { + serverData = { models: { partner: { fields: { @@ -67,13 +60,12 @@ QUnit.module("Search Bar (legacy)", (hooks) => { }, }, }; - testConfig.serverData = serverData; }); QUnit.test("basic rendering", async function (assert) { assert.expect(1); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 1); assert.strictEqual( @@ -86,7 +78,7 @@ QUnit.module("Search Bar (legacy)", (hooks) => { QUnit.test("navigation with facets", async function (assert) { assert.expect(4); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 1); // add a facet @@ -113,7 +105,7 @@ QUnit.module("Search Bar (legacy)", (hooks) => { let searchReadCount = 0; const webClient = await createWebClient({ - testConfig, + serverData, legacyParams: { getTZOffset() { return 360; @@ -171,7 +163,6 @@ QUnit.module("Search Bar (legacy)", (hooks) => { QUnit.test("autocomplete menu clickout interactions", async function (assert) { assert.expect(9); - const { serverData } = testConfig; const data = serverData.models; const fields = serverData.models.partner.fields; @@ -234,7 +225,7 @@ QUnit.module("Search Bar (legacy)", (hooks) => { let searchReadCount = 0; const webClient = await createWebClient({ - testConfig, + serverData, mockRPC: (route, args) => { if (route === '/web/dataset/search_read') { switch (searchReadCount) { @@ -267,7 +258,7 @@ QUnit.module("Search Bar (legacy)", (hooks) => { let searchReadCount = 0; const firstLoading = testUtils.makeTestPromise(); const webClient = await createWebClient({ - testConfig, + serverData, mockRPC: (route, args) => { if (route === '/web/dataset/search_read') { switch (searchReadCount) { @@ -323,8 +314,8 @@ QUnit.module("Search Bar (legacy)", (hooks) => { // Switch to pivot to ensure that the event comes from the control panel // (pivot does not have a handler on "reload" event). - testConfig.serverData.actions[1].views = [[false, "pivot"]]; - testConfig.serverData.views['partner,false,pivot'] = ` + serverData.actions[1].views = [[false, "pivot"]]; + serverData.views['partner,false,pivot'] = ` @@ -332,7 +323,7 @@ QUnit.module("Search Bar (legacy)", (hooks) => { let rpcs; const webClient = await createWebClient({ - testConfig, + serverData, mockRPC: () => { rpcs++; }, }); await doAction(webClient, 1); @@ -348,7 +339,7 @@ QUnit.module("Search Bar (legacy)", (hooks) => { QUnit.test('selecting (no result) triggers a re-render', async function (assert) { assert.expect(3); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 1); const searchInput = webClient.el.querySelector('.o_searchview_input'); @@ -377,7 +368,7 @@ QUnit.module("Search Bar (legacy)", (hooks) => { // not handled but are triggered to ensure they do not interfere. const TEST = "TEST"; const テスト = "テスト"; - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 1); const searchInput = webClient.el.querySelector('.o_searchview_input'); @@ -450,7 +441,7 @@ QUnit.module("Search Bar (legacy)", (hooks) => { QUnit.test('open search view autocomplete on paste value using mouse', async function (assert) { assert.expect(1); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 1); // Simulate paste text through the mouse. @@ -467,7 +458,7 @@ QUnit.module("Search Bar (legacy)", (hooks) => { QUnit.test('select autocompleted many2one', async function (assert) { assert.expect(5); - testConfig.serverData.views['partner,false,search'] = ` + serverData.views['partner,false,search'] = ` @@ -477,7 +468,7 @@ QUnit.module("Search Bar (legacy)", (hooks) => { `; const webClient = await createWebClient({ - testConfig, + serverData, mockRPC: (route, { domain }) => { if (route === '/web/dataset/search_read') { assert.step(JSON.stringify(domain)); @@ -508,7 +499,7 @@ QUnit.module("Search Bar (legacy)", (hooks) => { assert.expect(4); const webClient = await createWebClient({ - testConfig, + serverData, mockRPC: (route, { domain }) => { if (route === '/web/dataset/search_read') { assert.step(JSON.stringify(domain)); @@ -536,12 +527,12 @@ QUnit.module("Search Bar (legacy)", (hooks) => { QUnit.test('autocompletion with a boolean field', async function (assert) { assert.expect(11); - testConfig.serverData.views['partner,false,search'] = ` + serverData.views['partner,false,search'] = ` `; const webClient = await createWebClient({ - testConfig, + serverData, mockRPC: (route, { domain }) => { if (route === '/web/dataset/search_read') { assert.step(JSON.stringify(domain)); @@ -581,11 +572,11 @@ QUnit.module("Search Bar (legacy)", (hooks) => { QUnit.test('autocompletion with a selection field', async function (assert) { assert.expect(5); - testConfig.serverData.views['partner,false,search'] = ` + serverData.views['partner,false,search'] = ` `; - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 1); await cpHelpers.editSearch(webClient, "n"); @@ -600,20 +591,20 @@ QUnit.module("Search Bar (legacy)", (hooks) => { QUnit.test("reference fields are supported in search view", async function (assert) { assert.expect(7); - const partnerModel = testConfig.serverData.models.partner; + const partnerModel = serverData.models.partner; partnerModel.fields.ref = { type: 'reference', string: "Reference" }; partnerModel.records.forEach((record, i) => { record.ref = `ref${String(i).padStart(3, "0")}`; }); - testConfig.serverData.views["partner,false,search"] = ` + serverData.views["partner,false,search"] = ` `; const webClient = await createWebClient({ - testConfig, + serverData, mockRPC: (route, { domain }) => { if (route === '/web/dataset/search_read') { assert.step(JSON.stringify(domain)); diff --git a/addons/web/static/tests/legacy/services/service_provider_adapter_notification_tests.js b/addons/web/static/tests/legacy/services/service_provider_adapter_notification_tests.js index 5dc5755c596..020bd57d094 100644 --- a/addons/web/static/tests/legacy/services/service_provider_adapter_notification_tests.js +++ b/addons/web/static/tests/legacy/services/service_provider_adapter_notification_tests.js @@ -6,14 +6,12 @@ import core from "web.core"; import * as LegacyRegistry from "web.Registry"; import { registerCleanup } from "../../helpers/cleanup"; import { nextTick, patchWithCleanup } from "../../helpers/utils"; -import { createWebClient, doAction, getActionManagerTestConfig } from "../../webclient/actions/helpers"; +import { createWebClient, doAction } from "../../webclient/helpers"; -let testConfig; let legacyParams; QUnit.module("Service Provider Adapter Notification", (hooks) => { hooks.beforeEach(() => { - testConfig = getActionManagerTestConfig(); legacyParams = { serviceRegistry: new LegacyRegistry(), }; @@ -56,7 +54,7 @@ QUnit.module("Service Provider Adapter Notification", (hooks) => { delete core.action_registry.map.NotifyTestLeg; delete core.action_registry.map.CloseTestLeg; }); - const webClient = await createWebClient({ testConfig, legacyParams }); + const webClient = await createWebClient({ legacyParams }); await doAction(webClient, "NotifyTestLeg"); await nextTick(); assert.containsOnce(document.body, ".o_notification"); diff --git a/addons/web/static/tests/legacy/views/abstract_view_tests.js b/addons/web/static/tests/legacy/views/abstract_view_tests.js index d3c42f0934d..dd1fc97a341 100644 --- a/addons/web/static/tests/legacy/views/abstract_view_tests.js +++ b/addons/web/static/tests/legacy/views/abstract_view_tests.js @@ -5,7 +5,7 @@ var AbstractView = require('web.AbstractView'); var ajax = require('web.ajax'); var testUtils = require('web.test_utils'); -const { createWebClient, doAction, getActionManagerTestConfig } = require('@web/../tests/webclient/actions/helpers'); +const { createWebClient, doAction } = require('@web/../tests/webclient/helpers'); var createView = testUtils.createView; QUnit.module('Views', { @@ -113,10 +113,9 @@ QUnit.module('Views', { QUnit.test('group_by from context can be a string, instead of a list of strings', async function (assert) { assert.expect(1); - const testConfig = getActionManagerTestConfig(); - Object.assign(testConfig.serverData, { + const serverData = { actions: { - 1:{ + 1: { id: 1, name: 'Foo', res_model: 'foo', @@ -132,14 +131,14 @@ QUnit.module('Views', { 'foo,false,search': '', }, models: this.data - }); + }; const mockRPC = (route, args) => { if (args.method === 'web_read_group') { assert.deepEqual(args.kwargs.groupby, ['bar']); } }; - const webClient = await createWebClient({testConfig, mockRPC}); + const webClient = await createWebClient({ serverData, mockRPC }); await doAction(webClient, 1); }); diff --git a/addons/web/static/tests/legacy/views/calendar_tests.js b/addons/web/static/tests/legacy/views/calendar_tests.js index 35672d97b94..3d0d37a5105 100644 --- a/addons/web/static/tests/legacy/views/calendar_tests.js +++ b/addons/web/static/tests/legacy/views/calendar_tests.js @@ -10,15 +10,14 @@ const fieldRegistry = require('web.field_registry'); var ViewDialogs = require('web.view_dialogs'); var fieldUtils = require('web.field_utils'); var mixins = require('web.mixins'); -var RamStorage = require('web.RamStorage'); var testUtils = require('web.test_utils'); var session = require('web.session'); const Widget = require('web.Widget'); const { patchWithCleanup } = require("@web/../tests/helpers/utils"); -const { createWebClient, getActionManagerTestConfig, doAction } = require('@web/../tests/webclient/actions/helpers'); -let testConfig; +const { createWebClient, doAction } = require('@web/../tests/webclient/helpers'); +let serverData; CalendarRenderer.include({ getAvatars: function () { @@ -130,11 +129,10 @@ QUnit.module('Views', { ] }, }; - testConfig = getActionManagerTestConfig(); + serverData = { models: this.data }; this.data.event.methods = { check_access_rights: this.data.event.check_access_rights, } - Object.assign(testConfig.serverData, {models: this.data}); }, afterEach: function () { window.removeEventListener('scroll', _preventScroll, true); @@ -306,23 +304,25 @@ QUnit.module('Views', { QUnit.test('breadcrumbs are updated with the displayed period', async function (assert) { assert.expect(4); - testConfig.serverData.views = { + serverData.views = { 'event,1,calendar': '', 'event,false,search': '', }; - testConfig.serverData.actions[1] = { - id: 1, - flags: { - initialDate: initialDate, + serverData.actions = { + 1: { + id: 1, + flags: { + initialDate: initialDate, + }, + name: 'Meetings Test', + res_model: 'event', + type: 'ir.actions.act_window', + views: [[1, 'calendar']], }, - name: 'Meetings Test', - res_model: 'event', - type: 'ir.actions.act_window', - views: [[1, 'calendar']], }; - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 1); // displays month mode by default @@ -2868,7 +2868,7 @@ QUnit.module('Views', { QUnit.test('calendar is configured to have no groupBy menu', async function (assert) { assert.expect(1); - testConfig.serverData.views = { + serverData.views = { 'event,1,calendar': '', }; - testConfig.serverData.actions[1] = { - id: 1, - name: 'some action', - res_model: 'event', - type: 'ir.actions.act_window', - views: [[1, 'calendar']] + serverData.actions = { + 1: { + id: 1, + name: 'some action', + res_model: 'event', + type: 'ir.actions.act_window', + views: [[1, 'calendar']] + }, }; - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 1); assert.containsNone($(webClient.el).find('.o_control_panel .o_search_options span.fa.fa-bars'), @@ -3368,21 +3370,23 @@ QUnit.module('Views', { QUnit.test('initial_date given in the context', async function (assert) { assert.expect(1); - testConfig.serverData.views = { + serverData.views = { 'event,1,calendar': '', 'event,false,search': '', }; - testConfig.serverData.actions[1] = { - id: 1, - name: 'context initial date', - res_model: 'event', - type: 'ir.actions.act_window', - views: [[1, 'calendar']], - context: {initial_date: initialDate} + serverData.actions = { + 1: { + id: 1, + name: 'context initial date', + res_model: 'event', + type: 'ir.actions.act_window', + views: [[1, 'calendar']], + context: {initial_date: initialDate} + }, }; - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 1); await testUtils.nextTick(); assert.strictEqual($('.o_control_panel .breadcrumb-item').text(), diff --git a/addons/web/static/tests/legacy/views/form_tests.js b/addons/web/static/tests/legacy/views/form_tests.js index 2c6d73881ed..fd04e076aaf 100644 --- a/addons/web/static/tests/legacy/views/form_tests.js +++ b/addons/web/static/tests/legacy/views/form_tests.js @@ -24,9 +24,9 @@ const cpHelpers = testUtils.controlPanel; var createView = testUtils.createView; const { legacyExtraNextTick, patchWithCleanup } = require("@web/../tests/helpers/utils"); -const { createWebClient, doAction, getActionManagerTestConfig } = require('@web/../tests/webclient/actions/helpers'); +const { createWebClient, doAction } = require('@web/../tests/webclient/helpers'); -let testConfig; +let serverData; QUnit.module('Views', { beforeEach: function () { this.data = { @@ -155,14 +155,15 @@ QUnit.module('Views', { views: [[false, 'kanban'], [false, 'form']], }]; - testConfig = getActionManagerTestConfig(); - // map legacy test data const actions = {}; this.actions.forEach((act) => { actions[act.xmlId || act.id] = act; }); - Object.assign(testConfig.serverData, {actions, models: this.data}); + serverData = { + actions, + models: this.data, + }; }, }, function () { @@ -503,11 +504,11 @@ QUnit.module('Views', { QUnit.test('Form and subview with _view_ref contexts', async function (assert) { assert.expect(3); - testConfig.serverData.models.product.fields.partner_type_ids = {string: "one2many field", type: "one2many", relation: "partner_type"}, - testConfig.serverData.models.product.records = [{id: 1, name: 'Tromblon', partner_type_ids: [12,14]}]; - testConfig.serverData.models.partner.records[0].product_id = 1; + serverData.models.product.fields.partner_type_ids = {string: "one2many field", type: "one2many", relation: "partner_type"}, + serverData.models.product.records = [{id: 1, name: 'Tromblon', partner_type_ids: [12,14]}]; + serverData.models.partner.records[0].product_id = 1; - testConfig.serverData.views = { + serverData.views = { 'product,false,form': '
'+ ''+ '' + @@ -551,7 +552,7 @@ QUnit.module('Views', { } }; - const webClient = await createWebClient({testConfig, mockRPC}); + const webClient = await createWebClient({serverData, mockRPC}); await doAction(webClient, { res_id: 1, type: 'ir.actions.act_window', @@ -6816,7 +6817,7 @@ QUnit.module('Views', { QUnit.test('translation alerts preserved on reverse breadcrumb', async function (assert) { assert.expect(2); - testConfig.serverData.models['ir.translation'] = { + serverData.models['ir.translation'] = { fields: { name: { string: "name", type: "char" }, source: {string: "Source", type: "char"}, @@ -6825,9 +6826,9 @@ QUnit.module('Views', { records: [], }; - testConfig.serverData.models.partner.fields.foo.translate = true; + serverData.models.partner.fields.foo.translate = true; - testConfig.serverData.views = { + serverData.views = { 'partner,false,form': '' + '' + '' + @@ -6842,7 +6843,7 @@ QUnit.module('Views', { 'ir.translation,false,search': '', }; - testConfig.serverData.actions = { + serverData.actions = { 1: { id: 1, name: 'Partner', @@ -6861,7 +6862,7 @@ QUnit.module('Views', { } }; - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); patchWithCleanup(_t.database, { multi_lang: true, }); @@ -8813,7 +8814,7 @@ QUnit.module('Views', { QUnit.test('discard after a failed save', async function (assert) { assert.expect(2); - testConfig.serverData.views = { + serverData.views = { 'partner,false,form': '' + '' + '' + @@ -8823,7 +8824,7 @@ QUnit.module('Views', { 'partner,false,search': '', }; - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 1); await testUtils.dom.click('.o_control_panel .o-kanban-button-new'); @@ -9716,7 +9717,7 @@ QUnit.module('Views', { QUnit.test('Auto save: save when page changed', async function (assert) { assert.expect(10); - testConfig.serverData.actions[1] = { + serverData.actions[1] = { id: 1, name: 'Partner', res_model: 'partner', @@ -9724,7 +9725,7 @@ QUnit.module('Views', { views: [[false, 'list'], [false, 'form']], }; - testConfig.serverData.views = { + serverData.views = { 'partner,false,list': ` @@ -9749,7 +9750,7 @@ QUnit.module('Views', { } }; - const webClient = await createWebClient({ testConfig , mockRPC }); + const webClient = await createWebClient({ serverData , mockRPC }); await doAction(webClient, 1); @@ -9780,7 +9781,7 @@ QUnit.module('Views', { QUnit.test('Auto save: save when breadcrumb clicked', async function (assert) { assert.expect(7); - testConfig.serverData.actions[1] = { + serverData.actions[1] = { id: 1, name: 'Partner', res_model: 'partner', @@ -9788,7 +9789,7 @@ QUnit.module('Views', { views: [[false, 'list'], [false, 'form']], }; - testConfig.serverData.views = { + serverData.views = { 'partner,false,list': ` @@ -9813,7 +9814,7 @@ QUnit.module('Views', { } }; - const webClient = await createWebClient({ testConfig , mockRPC }); + const webClient = await createWebClient({ serverData , mockRPC }); await doAction(webClient, 1); @@ -9840,7 +9841,7 @@ QUnit.module('Views', { QUnit.test('Auto save: save when action changed', async function (assert) { assert.expect(6); - testConfig.serverData.actions[1] = { + serverData.actions[1] = { id: 1, name: 'Partner', res_model: 'partner', @@ -9848,7 +9849,7 @@ QUnit.module('Views', { views: [[false, 'list'], [false, 'form']], }; - testConfig.serverData.actions[2] = { + serverData.actions[2] = { id: 2, name: 'Other action', res_model: 'partner', @@ -9856,7 +9857,7 @@ QUnit.module('Views', { views: [[false, 'kanban']], }; - testConfig.serverData.views = { + serverData.views = { 'partner,false,list': ` @@ -9891,7 +9892,7 @@ QUnit.module('Views', { } }; - const webClient = await createWebClient({ testConfig , mockRPC }); + const webClient = await createWebClient({ serverData , mockRPC }); await doAction(webClient, 1); @@ -10017,7 +10018,7 @@ QUnit.module('Views', { QUnit.test('Auto save: save on closing tab/browser (detached form)', async function (assert) { assert.expect(3); - testConfig.serverData.actions[1] = { + serverData.actions[1] = { id: 1, name: 'Partner', res_model: 'partner', @@ -10025,7 +10026,7 @@ QUnit.module('Views', { views: [[false, 'list'], [false, 'form']], }; - testConfig.serverData.views = { + serverData.views = { 'partner,false,list': ` @@ -10047,7 +10048,7 @@ QUnit.module('Views', { } }; - const webClient = await createWebClient({ testConfig , mockRPC }); + const webClient = await createWebClient({ serverData, mockRPC }); await doAction(webClient, 1); diff --git a/addons/web/static/tests/legacy/views/graph_tests.js b/addons/web/static/tests/legacy/views/graph_tests.js index ed6ede924e9..6fe528c9961 100644 --- a/addons/web/static/tests/legacy/views/graph_tests.js +++ b/addons/web/static/tests/legacy/views/graph_tests.js @@ -7,7 +7,7 @@ const testUtils = require('web.test_utils'); const { sortBy } = require('web.utils'); const { legacyExtraNextTick } = require("@web/../tests/helpers/utils"); -const { createWebClient, doAction, getActionManagerTestConfig } = require('@web/../tests/webclient/actions/helpers'); +const { createWebClient, doAction } = require('@web/../tests/webclient/helpers'); const { createView } = testUtils; const cpHelpers = testUtils.controlPanel; @@ -75,7 +75,7 @@ function checkLegend(assert, graph, expectedLegendLabels) { assert.deepEqual(actualLegendLabels, expectedLegendLabels); } -let testConfig; +let serverData; QUnit.module('Views', { beforeEach: function () { this.data = { @@ -125,8 +125,7 @@ QUnit.module('Views', { }, }; - testConfig = getActionManagerTestConfig(); - Object.assign(testConfig.serverData, {models: this.data}); + serverData = { models: this.data }; } }, function () { @@ -793,7 +792,7 @@ QUnit.module('Views', { QUnit.test('measure dropdown consistency', async function (assert) { assert.expect(2); - testConfig.serverData.views = { + serverData.views = { 'foo,false,graph': ` @@ -809,7 +808,7 @@ QUnit.module('Views', { `, }; - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, { res_model: 'foo', diff --git a/addons/web/static/tests/legacy/views/list_tests.js b/addons/web/static/tests/legacy/views/list_tests.js index 626b99c6da3..660493358b1 100644 --- a/addons/web/static/tests/legacy/views/list_tests.js +++ b/addons/web/static/tests/legacy/views/list_tests.js @@ -27,9 +27,9 @@ const cpHelpers = testUtils.controlPanel; var createView = testUtils.createView; const { legacyExtraNextTick } = require("@web/../tests/helpers/utils"); -const { createWebClient, doAction, getActionManagerTestConfig, loadState } = require('@web/../tests/webclient/actions/helpers'); +const { createWebClient, doAction, loadState } = require('@web/../tests/webclient/helpers'); -let testConfig; +let serverData; QUnit.module('Views', { beforeEach: function () { @@ -133,8 +133,7 @@ QUnit.module('Views', { }, }; - testConfig = getActionManagerTestConfig(); - Object.assign(testConfig.serverData, {models: this.data}); + serverData = { models: this.data }; } }, function () { @@ -1772,17 +1771,19 @@ QUnit.module('Views', { QUnit.test('editable list view: check that controlpanel buttons are updating when groupby applied', async function (assert) { assert.expect(4); - testConfig.serverData.models.foo.fields.foo = {string: "Foo", type: "char", required:true}; + serverData.models.foo.fields.foo = {string: "Foo", type: "char", required:true}; - testConfig.serverData.actions[11] = { - id: 11, - name: 'Partners Action 11', - res_model: 'foo', - type: 'ir.actions.act_window', - views: [[3, 'list']], - search_view_id: [9, 'search'], + serverData.actions = { + 11: { + id: 11, + name: 'Partners Action 11', + res_model: 'foo', + type: 'ir.actions.act_window', + views: [[3, 'list']], + search_view_id: [9, 'search'], + }, }; - testConfig.serverData.views = { + serverData.views = { 'foo,3,list': '', 'foo,9,search': ''+ @@ -1790,7 +1791,7 @@ QUnit.module('Views', { '', }; - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 11); await testUtils.dom.click($(webClient.el).find('.o_list_button_add')); @@ -9484,19 +9485,21 @@ QUnit.module('Views', { QUnit.test('add filter in a grouped list with a pager', async function (assert) { assert.expect(11); - testConfig.serverData.actions[11] = { - id: 11, - name: 'Action 11', - res_model: 'foo', - type: 'ir.actions.act_window', - views: [[3, 'list']], - search_view_id: [9, 'search'], - flags: { - context: { group_by: ['int_field'] }, + serverData.actions = { + 11: { + id: 11, + name: 'Action 11', + res_model: 'foo', + type: 'ir.actions.act_window', + views: [[3, 'list']], + search_view_id: [9, 'search'], + flags: { + context: { group_by: ['int_field'] }, + }, }, }; - testConfig.serverData.views = { + serverData.views = { 'foo,3,list': '', 'foo,9,search': ` @@ -9510,7 +9513,7 @@ QUnit.module('Views', { } }; - const webClient = await createWebClient({testConfig, mockRPC}); + const webClient = await createWebClient({serverData, mockRPC}); await doAction(webClient, 11); assert.containsOnce(webClient, '.o_list_view'); @@ -11055,22 +11058,24 @@ QUnit.module('Views', { QUnit.test('change the viewType of the current action', async function (assert) { assert.expect(25); - testConfig.serverData.actions[1] = { - id: 1, - name: 'Partners Action 1', - res_model: 'foo', - type: 'ir.actions.act_window', - views: [[1, 'kanban']], - }; - testConfig.serverData.actions[2] = { - id: 2, - name: 'Partners', - res_model: 'foo', - type: 'ir.actions.act_window', - views: [[false, 'list'], [1, 'kanban']], + serverData.actions = { + 1: { + id: 1, + name: 'Partners Action 1', + res_model: 'foo', + type: 'ir.actions.act_window', + views: [[1, 'kanban']], + }, + 2: { + id: 2, + name: 'Partners', + res_model: 'foo', + type: 'ir.actions.act_window', + views: [[false, 'list'], [1, 'kanban']], + }, }; - testConfig.serverData.views = { + serverData.views = { 'foo,1,kanban': '' + '
' + '
', @@ -11083,7 +11088,7 @@ QUnit.module('Views', { 'foo,false,search': '', }; - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 2); @@ -11630,28 +11635,30 @@ QUnit.module('Views', { QUnit.test("Auto save: add a record and leave action", async function (assert) { assert.expect(4); - testConfig.serverData.actions[1] = { - id: 1, - name: 'Action 1', - res_model: 'foo', - type: 'ir.actions.act_window', - views: [[2, 'list']], - search_view_id: [1, 'search'], + serverData.actions = { + 1: { + id: 1, + name: 'Action 1', + res_model: 'foo', + type: 'ir.actions.act_window', + views: [[2, 'list']], + search_view_id: [1, 'search'], + }, + 2: { + id: 2, + name: 'Action 2', + res_model: 'foo', + type: 'ir.actions.act_window', + views: [[3, 'list']], + search_view_id: [1, 'search'], + }, }; - testConfig.serverData.actions[2] = { - id: 2, - name: 'Action 2', - res_model: 'foo', - type: 'ir.actions.act_window', - views: [[3, 'list']], - search_view_id: [1, 'search'], - }; - testConfig.serverData.views = { + serverData.views = { 'foo,1,search': '', 'foo,2,list': '', 'foo,3,list': '', }; - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 1); @@ -11672,28 +11679,30 @@ QUnit.module('Views', { QUnit.test("Auto save: modify a record and leave action", async function (assert) { assert.expect(2); - testConfig.serverData.actions[1] = { - id: 1, - name: 'Action 1', - res_model: 'foo', - type: 'ir.actions.act_window', - views: [[2, 'list']], - search_view_id: [1, 'search'], + serverData.actions = { + 1: { + id: 1, + name: 'Action 1', + res_model: 'foo', + type: 'ir.actions.act_window', + views: [[2, 'list']], + search_view_id: [1, 'search'], + }, + 2: { + id: 2, + name: 'Action 2', + res_model: 'foo', + type: 'ir.actions.act_window', + views: [[3, 'list']], + search_view_id: [1, 'search'], + }, }; - testConfig.serverData.actions[2] = { - id: 2, - name: 'Action 2', - res_model: 'foo', - type: 'ir.actions.act_window', - views: [[3, 'list']], - search_view_id: [1, 'search'], - }; - testConfig.serverData.views = { + serverData.views = { 'foo,1,search': '', 'foo,2,list': '', 'foo,3,list': '', }; - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 1); @@ -11712,37 +11721,39 @@ QUnit.module('Views', { QUnit.test("Auto save: modify a record and leave action (reject)", async function (assert) { assert.expect(5); - testConfig.serverData.actions[1] = { - id: 1, - name: 'Action 1', - res_model: 'foo', - type: 'ir.actions.act_window', - views: [[2, 'list']], - search_view_id: [1, 'search'], + serverData.actions = { + 1: { + id: 1, + name: 'Action 1', + res_model: 'foo', + type: 'ir.actions.act_window', + views: [[2, 'list']], + search_view_id: [1, 'search'], + }, + 2: { + id: 2, + name: 'Action 2', + res_model: 'foo', + type: 'ir.actions.act_window', + views: [[3, 'list']], + search_view_id: [1, 'search'], + }, }; - testConfig.serverData.actions[2] = { - id: 2, - name: 'Action 2', - res_model: 'foo', - type: 'ir.actions.act_window', - views: [[3, 'list']], - search_view_id: [1, 'search'], - }; - testConfig.serverData.views = { + serverData.views = { 'foo,1,search': '', 'foo,2,list': '', 'foo,3,list': '', }; - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); - await doAction(webClient,1); + await doAction(webClient, 1); assert.strictEqual($(webClient.el).find('.o_field_cell[name="foo"]').text(), "yopblipgnapblip"); await testUtils.dom.click($(webClient.el).find('.o_field_cell[name="foo"]:first')); await testUtils.fields.editInput($(webClient.el).find('.o_field_widget[name="foo"]'), ""); - await assert.rejects(doAction(webClient,2)); + await assert.rejects(doAction(webClient, 2)); assert.strictEqual($(webClient.el).find('.o_field_cell[name="foo"]').text(), "blipgnapblip"); assert.hasClass($(webClient.el).find('.o_field_widget[name="foo"]:first'), 'o_field_invalid'); @@ -11753,7 +11764,6 @@ QUnit.module('Views', { assert.expect(3); const list = await createView({ - debug: true, View: ListView, model: 'foo', data: this.data, diff --git a/addons/web/static/tests/legacy/views/pivot_tests.js b/addons/web/static/tests/legacy/views/pivot_tests.js index d6002cec0d1..4de91b1047d 100644 --- a/addons/web/static/tests/legacy/views/pivot_tests.js +++ b/addons/web/static/tests/legacy/views/pivot_tests.js @@ -7,7 +7,7 @@ const PivotController = require("web.PivotController"); var testUtils = require('web.test_utils'); var testUtilsDom = require('web.test_utils_dom'); -const { createWebClient, doAction, getActionManagerTestConfig } = require('@web/../tests/webclient/actions/helpers'); +const { createWebClient, doAction } = require('@web/../tests/webclient/helpers'); var _t = core._t; const cpHelpers = testUtils.controlPanel; @@ -27,7 +27,7 @@ var getCurrentValues = function (pivot) { }; -let testConfig; +let serverData; QUnit.module('Views', { beforeEach: function () { @@ -114,8 +114,7 @@ QUnit.module('Views', { }, }; - testConfig = getActionManagerTestConfig(); - Object.assign(testConfig.serverData, {models: this.data}); + serverData = { models: this.data }; }, }, function () { QUnit.module('PivotView'); @@ -2723,8 +2722,8 @@ QUnit.module('Views', { QUnit.test('Navigation list view for a group and back with breadcrumbs', async function (assert) { assert.expect(16); // create a webClient to test the interactions with the search view - - testConfig.serverData.views = { + + serverData.views = { 'partner,false,pivot': '' + '' + '', @@ -2754,7 +2753,7 @@ QUnit.module('Views', { } }; - const webClient = await createWebClient({testConfig, mockRPC}); + const webClient = await createWebClient({serverData, mockRPC}); await doAction(webClient, { res_model: 'partner', diff --git a/addons/web/static/tests/legacy/views/qweb_tests.js b/addons/web/static/tests/legacy/views/qweb_tests.js index 53db230fa25..1c196f01c71 100644 --- a/addons/web/static/tests/legacy/views/qweb_tests.js +++ b/addons/web/static/tests/legacy/views/qweb_tests.js @@ -2,8 +2,7 @@ odoo.define('web.qweb_view_tests', function (require) { "use strict"; const utils = require('web.test_utils'); -const { legacyExtraNextTick } = require("@web/../tests/helpers/utils"); -const { createWebClient, doAction, getActionManagerTestConfig } = require('@web/../tests/webclient/actions/helpers'); +const { createWebClient, doAction } = require('@web/../tests/webclient/helpers'); QUnit.module("Views", { @@ -11,17 +10,18 @@ QUnit.module("Views", { QUnit.module("QWeb"); QUnit.test("basic", async function (assert) { assert.expect(14); - const testConfig = getActionManagerTestConfig(); - testConfig.serverData.models = { - test: { - fields: {}, - records: [], - } - }; - testConfig.serverData.views = { - 'test,5,qweb': '
', - 'test,false,search': '' + const serverData = { + models: { + test: { + fields: {}, + records: [], + } + }, + views: { + 'test,5,qweb': '
', + 'test,false,search': '' + }, }; const mockRPC = (route, args) => { @@ -46,7 +46,7 @@ QUnit.module("Views", { } }; - const webClient = await createWebClient({testConfig, mockRPC}); + const webClient = await createWebClient({serverData, mockRPC}); let resolved = false; const doActionProm = doAction(webClient, { @@ -64,7 +64,7 @@ QUnit.module("Views", { await utils.dom.click(content.querySelector('[type=toggle]')); assert.equal(content.querySelector('div#sub').textContent, 'ok', 'should have unfolded the sub-item'); await utils.dom.click(content.querySelector('[type=toggle]')); - assert.containsNone(content, "div#sub") + assert.containsNone(content, "div#sub"); await utils.dom.click(content.querySelector('[type=toggle]')); assert.verifySteps(['fetch', 'unfold', 'unfold']); diff --git a/addons/web/static/tests/legacy/views/search_panel_tests.js b/addons/web/static/tests/legacy/views/search_panel_tests.js index c7a28be2d1f..d50ecea676d 100644 --- a/addons/web/static/tests/legacy/views/search_panel_tests.js +++ b/addons/web/static/tests/legacy/views/search_panel_tests.js @@ -10,7 +10,7 @@ const SearchPanel = require("web.searchPanel"); const cpHelpers = testUtils.controlPanel; const createView = testUtils.createView; -const { createWebClient, doAction, getActionManagerTestConfig, loadState } = require('@web/../tests/webclient/actions/helpers'); +const { createWebClient, doAction } = require('@web/../tests/webclient/helpers'); const { legacyExtraNextTick } = require("@web/../tests/helpers/utils"); /** @@ -38,7 +38,7 @@ function toggleFold(widget, text) { return testUtils.dom.click(target); } -let testConfig; +let serverData; QUnit.module('Views', { beforeEach: function () { @@ -121,14 +121,16 @@ QUnit.module('Views', { `, }; - testConfig = getActionManagerTestConfig(); - // map legacy test data const actions = {}; this.actions.forEach((act) => { actions[act.xmlId || act.id] = act; }); - Object.assign(testConfig.serverData, {actions, models: this.data, views: this.archs}); + serverData = { + actions, + models: this.data, + views: this.archs, + }; }, }, function () { @@ -2333,7 +2335,7 @@ QUnit.module('Views', { QUnit.test('search panel is available on list and kanban by default', async function (assert) { assert.expect(8); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 1); @@ -2359,7 +2361,7 @@ QUnit.module('Views', { QUnit.test('search panel with view_types attribute', async function (assert) { assert.expect(6); - testConfig.serverData.views['partner,false,search'] = + serverData.views['partner,false,search'] = ` @@ -2368,7 +2370,7 @@ QUnit.module('Views', { `; - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 1); assert.containsOnce(webClient, '.o_content.o_controller_with_searchpanel .o_kanban_view'); @@ -2394,7 +2396,7 @@ QUnit.module('Views', { } }; - const webClient = await createWebClient({ testConfig , mockRPC }); + const webClient = await createWebClient({ serverData , mockRPC }); await doAction(webClient, 1); @@ -2441,7 +2443,7 @@ QUnit.module('Views', { } }; - const webClient = await createWebClient({ testConfig , mockRPC }); + const webClient = await createWebClient({ serverData , mockRPC }); await doAction(webClient, 1); assert.containsNone(webClient, '.o_search_panel_filter_value input:checked'); @@ -2487,7 +2489,7 @@ QUnit.module('Views', { QUnit.test('search panel filters are kept when switching to a view with no search panel', async function (assert) { assert.expect(13); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 1); assert.containsOnce(webClient, '.o_content.o_controller_with_searchpanel .o_kanban_view'); @@ -2520,7 +2522,7 @@ QUnit.module('Views', { QUnit.test('after onExecuteAction, selects "All" as default category value', async function (assert) { assert.expect(4); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 2); await testUtils.dom.click($(webClient.el).find('.o_form_view button:contains("multi view")')); @@ -2536,8 +2538,8 @@ QUnit.module('Views', { QUnit.test('search panel is not instantiated if stated in context', async function (assert) { assert.expect(2); - testConfig.serverData.actions[2].context = {search_panel: false}; - const webClient = await createWebClient({ testConfig }); + serverData.actions[2].context = {search_panel: false}; + const webClient = await createWebClient({ serverData }); await doAction(webClient, 2); await testUtils.dom.click($(webClient.el).find('.o_form_view button:contains("multi view")')); @@ -2556,7 +2558,7 @@ QUnit.module('Views', { } }; - const webClient = await createWebClient({ testConfig, mockRPC }); + const webClient = await createWebClient({ serverData, mockRPC }); await doAction(webClient, 1); await cpHelpers.switchView(webClient, 'list'); @@ -2577,10 +2579,10 @@ QUnit.module('Views', { SearchPanel.scrollDebounce = 0; for (var i = 10; i < 20; i++) { - testConfig.serverData.models.category.records.push({id: i, name: "Cat " + i}); + serverData.models.category.records.push({id: i, name: "Cat " + i}); } - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); webClient.el.querySelector('.o_action_manager').style.maxHeight = "300px"; await doAction(webClient, 1); diff --git a/addons/web/static/tests/legacy/widgets/domain_selector_tests.js b/addons/web/static/tests/legacy/widgets/domain_selector_tests.js index 9e49c8d644c..bb8278924bf 100644 --- a/addons/web/static/tests/legacy/widgets/domain_selector_tests.js +++ b/addons/web/static/tests/legacy/widgets/domain_selector_tests.js @@ -3,7 +3,7 @@ odoo.define('web.domain_selector_tests', function (require) { var DomainSelector = require("web.DomainSelector"); var testUtils = require("web.test_utils"); -const { createWebClient, doAction, getActionManagerTestConfig } = require('@web/../tests/webclient/actions/helpers'); +const { createWebClient, doAction } = require('@web/../tests/webclient/helpers'); QUnit.module('widgets', {}, function () { @@ -248,26 +248,29 @@ QUnit.module('DomainSelector', { QUnit.test("inline domain editor in modal", async function (assert) { assert.expect(1); - const testConfig = getActionManagerTestConfig(); - testConfig.serverData.actions[5] = { - id: 5, - name: "Partner Form", - res_model: "partner", - target: "new", - type: "ir.actions.act_window", - views: [["view_ref", "form"]], + const serverData = { + actions: { + 5: { + id: 5, + name: "Partner Form", + res_model: "partner", + target: "new", + type: "ir.actions.act_window", + views: [["view_ref", "form"]], + }, + }, + models: this.data, + views: { + "partner,view_ref,form": ` + + + + `, + }, }; - testConfig.serverData.views = { - "partner,view_ref,form": ` -
- - - `, - }; - - const webClient = await createWebClient({testConfig}); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 5); assert.strictEqual(document.querySelector('div[name="foo"]').closest('.modal-body').style.overflow, 'visible', "modal should have visible overflow if there is inline domain field widget"); diff --git a/addons/web/static/tests/setup.js b/addons/web/static/tests/setup.js index 9b16f991845..6722a5dd9c9 100644 --- a/addons/web/static/tests/setup.js +++ b/addons/web/static/tests/setup.js @@ -2,7 +2,7 @@ import core from "web.core"; import session from "web.session"; -import { browser } from "@web/core/browser/browser"; +import { browser, makeRAMLocalStorage } from "@web/core/browser/browser"; import { patchWithCleanup } from "@web/../tests/helpers/utils"; import { legacyProm } from "web.test_legacy"; import { registerCleanup } from "./helpers/cleanup"; @@ -24,21 +24,61 @@ function forceLocaleAndTimezoneWithCleanup() { }); } -function patchBrowserWithCleanup() { - // patch addEventListner to automatically remove listeners bound (via browser.addEventListener) - // during a test (e.g. during the deployment of a service) - const originalAddEventListener = browser.addEventListener; - const originalRemoveEventListener = browser.removeEventListener; - patchWithCleanup(browser, { - addEventListener() { - originalAddEventListener(...arguments); - registerCleanup(() => { - originalRemoveEventListener(...arguments); - }); +function makeMockLocation() { + const locationLink = Object.assign(document.createElement("a"), { + href: window.location.origin + window.location.pathname, + assign(url) { + this.href = url; + }, + reload() {}, + }); + return new Proxy(locationLink, { + get(target, p) { + return target[p]; + }, + set(target, p, value) { + target[p] = value; + if (p === "hash") { + window.dispatchEvent(new HashChangeEvent("hashchange")); + } + return true; }, }); } +function patchBrowserWithCleanup() { + const originalAddEventListener = browser.addEventListener; + const originalRemoveEventListener = browser.removeEventListener; + const mockLocation = makeMockLocation(); + patchWithCleanup( + browser, + { + // patch addEventListner to automatically remove listeners bound (via + // browser.addEventListener) during a test (e.g. during the deployment of a service) + addEventListener() { + originalAddEventListener(...arguments); + registerCleanup(() => { + originalRemoveEventListener(...arguments); + }); + }, + // in tests, we never want to interact with the real url or reload the page + location: mockLocation, + history: { + pushState(state, title, url) { + mockLocation.assign(url); + }, + replaceState(state, title, url) { + mockLocation.assign(url); + }, + }, + // in tests, we never want to interact with the real local/session storages. + localStorage: makeRAMLocalStorage(), + sessionStorage: makeRAMLocalStorage(), + }, + { pure: true } + ); +} + function patchLegacyCoreBus() { // patch core.bus.on to automatically remove listners bound on the legacy bus // during a test (e.g. during the deployment of a service) diff --git a/addons/web/static/tests/webclient/actions/client_action_tests.js b/addons/web/static/tests/webclient/actions/client_action_tests.js index 18b769f1820..a3c703c06b9 100644 --- a/addons/web/static/tests/webclient/actions/client_action_tests.js +++ b/addons/web/static/tests/webclient/actions/client_action_tests.js @@ -1,5 +1,6 @@ /** @odoo-module **/ +import { browser } from "@web/core/browser/browser"; import { registry } from "@web/core/registry"; import { NotificationContainer } from "@web/core/notifications/notification_container"; import core from "web.core"; @@ -7,27 +8,25 @@ import AbstractAction from "web.AbstractAction"; import testUtils from "web.test_utils"; import { registerCleanup } from "../../helpers/cleanup"; import { clearRegistryWithCleanup } from "../../helpers/mock_env"; -import { makeFakeRouterService } from "../../helpers/mock_services"; -import { click, legacyExtraNextTick } from "../../helpers/utils"; -import { createWebClient, doAction, getActionManagerTestConfig } from "./helpers"; +import { click, legacyExtraNextTick, patchWithCleanup } from "../../helpers/utils"; +import { createWebClient, doAction, getActionManagerServerData } from "./../helpers"; const { Component, tags } = owl; -let testConfig; +let serverData; const mainComponentRegistry = registry.category("main_components"); -const serviceRegistry = registry.category("services"); const actionRegistry = registry.category("actions"); QUnit.module("ActionManager", (hooks) => { hooks.beforeEach(() => { - testConfig = getActionManagerTestConfig(); + serverData = getActionManagerServerData(); }); QUnit.module("Client Actions"); QUnit.test("can display client actions in Dialog", async function (assert) { assert.expect(2); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, { name: "Dialog Test", target: "new", @@ -40,7 +39,7 @@ QUnit.module("ActionManager", (hooks) => { QUnit.test("can display client actions as main, then in Dialog", async function (assert) { assert.expect(3); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, "__test__client__action__"); assert.containsOnce(webClient, ".o_action_manager .test_client_action"); await doAction(webClient, { @@ -56,7 +55,7 @@ QUnit.module("ActionManager", (hooks) => { "can display client actions in Dialog, then as main destroys Dialog", async function (assert) { assert.expect(4); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, { target: "new", tag: "__test__client__action__", @@ -84,7 +83,7 @@ QUnit.module("ActionManager", (hooks) => { }; core.action_registry.add("HelloWorldTestLeg", ClientAction); registerCleanup(() => delete core.action_registry.map.HelloWorldTestLeg); - const webClient = await createWebClient({ testConfig, mockRPC }); + const webClient = await createWebClient({ serverData, mockRPC }); await doAction(webClient, "HelloWorldTestLeg"); assert.containsNone( document.body, @@ -108,7 +107,7 @@ QUnit.module("ActionManager", (hooks) => { const mockRPC = async function (route, args) { assert.step((args && args.method) || route); }; - const webClient = await createWebClient({ testConfig, mockRPC }); + const webClient = await createWebClient({ serverData, mockRPC }); await doAction(webClient, "HelloWorldTest"); assert.containsNone( document.body, @@ -137,7 +136,7 @@ QUnit.module("ActionManager", (hooks) => { }); core.action_registry.add("HelloWorldTest", ClientAction); registerCleanup(() => delete core.action_registry.map.HelloWorldTest); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, "HelloWorldTest"); assert.strictEqual( $(".o_control_panel:visible").length, @@ -172,19 +171,19 @@ QUnit.module("ActionManager", (hooks) => { return { foo: "baz" }; }, }); - serviceRegistry.add( - "router", - makeFakeRouterService({ - onPushState() { + const pushState = browser.history.pushState; + patchWithCleanup(browser, { + history: Object.assign({}, browser.history, { + pushState() { + pushState(...arguments); assert.step("push_state"); }, }), - { force: true } - ); + }); core.action_registry.add("HelloWorldTest", ClientAction); registerCleanup(() => delete core.action_registry.map.HelloWorldTest); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); let currentTitle = webClient.env.services.title.current; assert.strictEqual(currentTitle, '{"zopenerp":"Odoo"}'); let currentHash = webClient.env.services.router.current.hash; @@ -214,7 +213,7 @@ QUnit.module("ActionManager", (hooks) => { }); core.action_registry.add("HelloWorldTest", ClientAction); registerCleanup(() => delete core.action_registry.map.HelloWorldTest); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, "HelloWorldTest"); assert.containsOnce( webClient.el, @@ -241,7 +240,7 @@ QUnit.module("ActionManager", (hooks) => { }); core.action_registry.add("HelloWorldTest", ClientAction); registerCleanup(() => delete core.action_registry.map.HelloWorldTest); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, "HelloWorldTest"); assert.strictEqual( $("ol.breadcrumb").text(), @@ -283,7 +282,7 @@ QUnit.module("ActionManager", (hooks) => { }); core.action_registry.add("ClientAction", ClientAction); core.action_registry.add("ClientAction2", ClientAction2); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, "ClientAction"); assert.containsOnce(webClient.el, ".breadcrumb-item"); assert.strictEqual( @@ -319,7 +318,7 @@ QUnit.module("ActionManager", (hooks) => { } ClientAction.template = tags.xml`
owl client action
`; actionRegistry.add("OwlClientAction", ClientAction); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 8); await doAction(webClient, "OwlClientAction"); assert.containsOnce(webClient.el, ".my_owl_action"); @@ -337,7 +336,7 @@ QUnit.module("ActionManager", (hooks) => { mainComponentRegistry.add("NotificationContainer", { Component: NotificationContainer, }); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 1); assert.containsOnce(webClient, ".o_kanban_view"); await doAction(webClient, { @@ -380,9 +379,9 @@ QUnit.module("ActionManager", (hooks) => { mainComponentRegistry.add("NotificationContainer", { Component: NotificationContainer, }); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); const options = { - onClose: function (infos) { + onClose: function () { assert.step("onClose"); }, }; @@ -408,7 +407,6 @@ QUnit.module("ActionManager", (hooks) => { notificationSelector, "a notification should be present" ); - const notificationElement = document.body.querySelector(notificationSelector); assert.verifySteps(["onClose"]); }); }); diff --git a/addons/web/static/tests/webclient/actions/close_action_tests.js b/addons/web/static/tests/webclient/actions/close_action_tests.js index 69fbcfcb33c..c7257add288 100644 --- a/addons/web/static/tests/webclient/actions/close_action_tests.js +++ b/addons/web/static/tests/webclient/actions/close_action_tests.js @@ -2,20 +2,20 @@ import testUtils from "web.test_utils"; import { legacyExtraNextTick, nextTick } from "../../helpers/utils"; -import { createWebClient, doAction, getActionManagerTestConfig } from "./helpers"; +import { createWebClient, doAction, getActionManagerServerData } from "./../helpers"; -let testConfig; +let serverData; QUnit.module("ActionManager", (hooks) => { hooks.beforeEach(() => { - testConfig = getActionManagerTestConfig(); + serverData = getActionManagerServerData(); }); QUnit.module('"ir.actions.act_window_close" actions'); QUnit.test("close the currently opened dialog", async function (assert) { assert.expect(2); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); // execute an action in target="new" await doAction(webClient, 5); assert.containsOnce( @@ -32,7 +32,7 @@ QUnit.module("ActionManager", (hooks) => { QUnit.test('execute "on_close" only if there is no dialog to close', async function (assert) { assert.expect(3); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); // execute an action in target="new" await doAction(webClient, 5); function onClose() { @@ -51,7 +51,7 @@ QUnit.module("ActionManager", (hooks) => { QUnit.test("close action with provided infos", async function (assert) { assert.expect(1); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); const options = { onClose: function (infos) { assert.strictEqual( @@ -73,7 +73,7 @@ QUnit.module("ActionManager", (hooks) => { QUnit.test("history back calls on_close handler of dialog action", async function (assert) { assert.expect(4); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); function onClose() { assert.step("on_close"); } @@ -91,7 +91,7 @@ QUnit.module("ActionManager", (hooks) => { "history back calls on_close handler of dialog action with 2 breadcrumbs", async function (assert) { assert.expect(7); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 1); // kanban await doAction(webClient, 3); // list assert.containsOnce(webClient.el, ".o_list_view"); @@ -120,7 +120,7 @@ QUnit.module("ActionManager", (hooks) => { return readOnFirstRecordDef; } }; - const webClient = await createWebClient({ testConfig, mockRPC }); + const webClient = await createWebClient({ serverData, mockRPC }); await doAction(webClient, 3); // open first record in form view. this will crash and will not // display a form view diff --git a/addons/web/static/tests/webclient/actions/concurrency_tests.js b/addons/web/static/tests/webclient/actions/concurrency_tests.js index 9be68022bdb..c879df5a97e 100644 --- a/addons/web/static/tests/webclient/actions/concurrency_tests.js +++ b/addons/web/static/tests/webclient/actions/concurrency_tests.js @@ -3,12 +3,12 @@ import { registry } from "@web/core/registry"; import testUtils from "web.test_utils"; import { legacyExtraNextTick, nextTick } from "../../helpers/utils"; -import { createWebClient, doAction, getActionManagerTestConfig } from "./helpers"; +import { createWebClient, doAction, getActionManagerServerData } from "./../helpers"; const { Component, tags } = owl; const actionRegistry = registry.category("actions"); -let testConfig; +let serverData; // legacy stuff let cpHelpers; @@ -18,7 +18,7 @@ QUnit.module("ActionManager", (hooks) => { }); hooks.beforeEach(() => { - testConfig = getActionManagerTestConfig(); + serverData = getActionManagerServerData(); }); QUnit.module("Concurrency management"); @@ -32,7 +32,7 @@ QUnit.module("ActionManager", (hooks) => { await def; } }; - const webClient = await createWebClient({ testConfig, mockRPC }); + const webClient = await createWebClient({ serverData, mockRPC }); doAction(webClient, 4); doAction(webClient, 8); def.resolve(); @@ -62,7 +62,7 @@ QUnit.module("ActionManager", (hooks) => { await defs.shift(); } }; - const webClient = await createWebClient({ testConfig, mockRPC }); + const webClient = await createWebClient({ serverData, mockRPC }); await doAction(webClient, 4); // kanban view is loaded, switch to list view await cpHelpers.switchView(webClient.el, "list"); @@ -96,7 +96,7 @@ QUnit.module("ActionManager", (hooks) => { return 1; } }; - const webClient = await createWebClient({ testConfig, mockRPC }); + const webClient = await createWebClient({ serverData, mockRPC }); doAction(webClient, 2); doAction(webClient, 4); def.resolve(); @@ -117,7 +117,7 @@ QUnit.module("ActionManager", (hooks) => { await def; } }; - const webClient = await createWebClient({ testConfig, mockRPC }); + const webClient = await createWebClient({ serverData, mockRPC }); // create a situation with 3 breadcrumbs: kanban/form/list await doAction(webClient, 4); await testUtils.dom.click($(webClient.el).find(".o_kanban_record:first")); @@ -155,7 +155,7 @@ QUnit.module("ActionManager", (hooks) => { await def; } }; - const webClient = await createWebClient({ testConfig, mockRPC }); + const webClient = await createWebClient({ serverData, mockRPC }); webClient.env.bus.trigger("test:hashchange", { action: 4, id: 2, @@ -218,10 +218,10 @@ QUnit.module("ActionManager", (hooks) => { assert.step((args && args.method) || route); if (route === "/web/dataset/call_button") { await def; - return testConfig.serverData.actions[1]; + return serverData.actions[1]; } }; - const webClient = await createWebClient({ testConfig, mockRPC }); + const webClient = await createWebClient({ serverData, mockRPC }); // execute action 3 and open a record in form view await doAction(webClient, 3); await testUtils.dom.click($(webClient.el).find(".o_list_view .o_data_row:first")); @@ -283,7 +283,7 @@ QUnit.module("ActionManager", (hooks) => { await def; } }; - const webClient = await createWebClient({ testConfig, mockRPC }); + const webClient = await createWebClient({ serverData, mockRPC }); await doAction(webClient, 3); assert.containsOnce( webClient, @@ -349,7 +349,7 @@ QUnit.module("ActionManager", (hooks) => { await def; } }; - const webClient = await createWebClient({ testConfig, mockRPC }); + const webClient = await createWebClient({ serverData, mockRPC }); // execute a first action (its 'load_views' RPC is blocked) doAction(webClient, 3); await testUtils.nextTick(); @@ -399,7 +399,7 @@ QUnit.module("ActionManager", (hooks) => { await def; } }; - const webClient = await createWebClient({ testConfig, mockRPC }); + const webClient = await createWebClient({ serverData, mockRPC }); // execute a first action (its 'search_read' RPC is blocked) doAction(webClient, 3); await testUtils.nextTick(); @@ -448,7 +448,7 @@ QUnit.module("ActionManager", (hooks) => { await def; } }; - const webClient = await createWebClient({ testConfig, mockRPC }); + const webClient = await createWebClient({ serverData, mockRPC }); await doAction(webClient, 3); assert.containsOnce(webClient, ".o_list_view"); assert.containsN(webClient, ".o_list_view .o_data_row", 5); @@ -487,7 +487,7 @@ QUnit.module("ActionManager", (hooks) => { } ClientAction.template = tags.xml`
ClientAction
`; actionRegistry.add("slowAction", ClientAction); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); doAction(webClient, "slowAction"); await nextTick(); await legacyExtraNextTick(); @@ -516,7 +516,7 @@ QUnit.module("ActionManager", (hooks) => { return Promise.resolve(def); } }; - const webClient = await createWebClient({ testConfig, mockRPC }); + const webClient = await createWebClient({ serverData, mockRPC }); await doAction(webClient, 3); assert.containsOnce(webClient, ".o_list_view"); def = testUtils.makeTestPromise(); @@ -555,7 +555,7 @@ QUnit.module("ActionManager", (hooks) => { await Promise.resolve(defs.shift()); } }; - const webClient = await createWebClient({ testConfig, mockRPC }); + const webClient = await createWebClient({ serverData, mockRPC }); await doAction(webClient, 3); assert.containsOnce(webClient, ".o_list_view"); doAction(webClient, 4, { clearBreadcrumbs: true }); diff --git a/addons/web/static/tests/webclient/actions/effects_tests.js b/addons/web/static/tests/webclient/actions/effects_tests.js index 5949180934b..7b9e65c0fdf 100644 --- a/addons/web/static/tests/webclient/actions/effects_tests.js +++ b/addons/web/static/tests/webclient/actions/effects_tests.js @@ -6,15 +6,15 @@ import { EffectContainer } from "@web/webclient/effects/effect_container"; import testUtils from "web.test_utils"; import { clearRegistryWithCleanup } from "../../helpers/mock_env"; import { click, legacyExtraNextTick, nextTick, patchWithCleanup } from "../../helpers/utils"; -import { createWebClient, doAction, getActionManagerTestConfig } from "./helpers"; +import { createWebClient, doAction, getActionManagerServerData } from "./../helpers"; -let testConfig; +let serverData; const mainComponentRegistry = registry.category("main_components"); QUnit.module("ActionManager", (hooks) => { hooks.beforeEach(() => { - testConfig = getActionManagerTestConfig(); + serverData = getActionManagerServerData(); }); QUnit.module("Effects"); @@ -26,7 +26,7 @@ QUnit.module("ActionManager", (hooks) => { mainComponentRegistry.add("EffectContainer", { Component: EffectContainer, }); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 1); assert.containsOnce(webClient.el, ".o_kanban_view"); assert.containsNone(webClient.el, ".o_reward"); @@ -58,7 +58,7 @@ QUnit.module("ActionManager", (hooks) => { Component: NotificationContainer, }); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 1); assert.containsOnce(webClient.el, ".o_kanban_view"); assert.containsNone(webClient.el, ".o_reward"); @@ -74,7 +74,7 @@ QUnit.module("ActionManager", (hooks) => { QUnit.test("on close with effect from server", async function (assert) { assert.expect(1); patchWithCleanup(odoo.session_info, { show_effect: true }); - const mockRPC = async (route, args) => { + const mockRPC = async (route) => { if (route === "/web/dataset/call_button") { return Promise.resolve({ type: "ir.actions.act_window_close", @@ -89,7 +89,7 @@ QUnit.module("ActionManager", (hooks) => { mainComponentRegistry.add("EffectContainer", { Component: EffectContainer, }); - const webClient = await createWebClient({ testConfig, mockRPC }); + const webClient = await createWebClient({ serverData, mockRPC }); await doAction(webClient, 6); await click(webClient.el.querySelector('button[name="object"]')); assert.containsOnce(webClient, ".o_reward"); @@ -97,7 +97,7 @@ QUnit.module("ActionManager", (hooks) => { QUnit.test("on close with effect in xml", async function (assert) { assert.expect(2); - testConfig.serverData.views["partner,false,form"] = ` + serverData.views["partner,false,form"] = `
`; - testConfig.serverData.models.partner.filters = [ + serverData.models.partner.filters = [ { id: 1, context: "{}", @@ -227,7 +228,7 @@ QUnit.module("ActionManager", (hooks) => { searchReadCount += 1; } }; - const webClient = await createWebClient({ testConfig, mockRPC }); + const webClient = await createWebClient({ serverData, mockRPC }); await doAction(webClient, 3); // Sort records await testUtils.dom.click($(webClient.el).find(".o_list_view th.o_column_sortable")); @@ -243,7 +244,7 @@ QUnit.module("ActionManager", (hooks) => { QUnit.test("breadcrumbs are updated when switching between views", async function (assert) { assert.expect(15); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 3); assert.containsOnce( webClient.el, @@ -338,7 +339,7 @@ QUnit.module("ActionManager", (hooks) => { QUnit.test("switch buttons are updated when switching between views", async function (assert) { assert.expect(13); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 3); assert.containsN( webClient.el, @@ -424,7 +425,7 @@ QUnit.module("ActionManager", (hooks) => { }); QUnit.test("pager is updated when switching between views", async function (assert) { assert.expect(10); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 4); assert.strictEqual( $(webClient.el).find(".o_control_panel .o_pager_value").text(), @@ -492,8 +493,8 @@ QUnit.module("ActionManager", (hooks) => { QUnit.test("domain is kept when switching between views", async function (assert) { assert.expect(5); - testConfig.serverData.actions[3].search_view_id = [4, "a custom search view"]; - const webClient = await createWebClient({ testConfig }); + serverData.actions[3].search_view_id = [4, "a custom search view"]; + const webClient = await createWebClient({ serverData }); await doAction(webClient, 3); assert.containsN(webClient, ".o_data_row", 5); // activate a domain @@ -521,7 +522,7 @@ QUnit.module("ActionManager", (hooks) => { const mockRPC = async (route, args) => { await def; }; - const webClient = await createWebClient({ testConfig, mockRPC }); + const webClient = await createWebClient({ serverData, mockRPC }); await doAction(webClient, 3); // switch to kanban view def = testUtils.makeTestPromise(); @@ -597,7 +598,7 @@ QUnit.module("ActionManager", (hooks) => { QUnit.test("breadcrumbs are updated when display_name changes", async function (assert) { assert.expect(4); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 3); // open a record in form view await testUtils.dom.click(webClient.el.querySelector(".o_list_view .o_data_row")); @@ -637,7 +638,7 @@ QUnit.module("ActionManager", (hooks) => { QUnit.test('reverse breadcrumb works on accesskey "b"', async function (assert) { assert.expect(4); - const webClient = await createWebClient({ testConfig }); + const webClient = await createWebClient({ serverData }); await doAction(webClient, 3); // open a record in form view await testUtils.dom.click($(webClient.el).find(".o_list_view .o_data_row:first")); @@ -673,7 +674,7 @@ QUnit.module("ActionManager", (hooks) => { const mockRPC = async (route, args) => { assert.step((args && args.method) || route); }; - const webClient = await createWebClient({ testConfig, mockRPC }); + const webClient = await createWebClient({ serverData, mockRPC }); await doAction(webClient, 3); // create a new record await testUtils.dom.click($(webClient.el).find(".o_control_panel .o_list_button_add")); @@ -724,14 +725,14 @@ QUnit.module("ActionManager", (hooks) => { }, "should call route with correct arguments" ); - const record = testConfig.serverData.models.partner.records.find( + const record = serverData.models.partner.records.find( (r) => r.id === args.args[0][0] ); record.foo = "value changed"; return Promise.resolve(false); } }; - const webClient = await createWebClient({ testConfig, mockRPC }); + const webClient = await createWebClient({ serverData, mockRPC }); await doAction(webClient, 3); // open a record in form view await testUtils.dom.click($(webClient.el).find(".o_list_view .o_data_row:first")); @@ -766,12 +767,12 @@ QUnit.module("ActionManager", (hooks) => { "requests for execute_action of type object: disable buttons (2)", async function (assert) { assert.expect(6); - testConfig.serverData.views["pony,44,form"] = ` + serverData.views["pony,44,form"] = `