diff options
| author | Julien Mougenot <jum@odoo.com> | 2020-07-13 13:20:46 +0000 |
|---|---|---|
| committer | Mathieu Duckerts-Antoine <dam@odoo.com> | 2020-07-23 08:21:10 +0000 |
| commit | d3dd7b24b0ed55b02479f54f2320781f4f6297bc (patch) | |
| tree | f18d961c9f7117593d57762ade0237cc1d33b598 /addons/web/static/tests/helpers/test_utils_create.js | |
| parent | bb3bc7c9e4992dc07b10e87f87662bdd72f24d88 (diff) | |
[IMP] *: adapt tests to Owl search panel
Adaptation of the tests to the changes regarding the refactored search
panel and model.
Part of task 2228968
Co-authored-by: Julien Mougenot <jum@odoo.com>
Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Diffstat (limited to 'addons/web/static/tests/helpers/test_utils_create.js')
| -rw-r--r-- | addons/web/static/tests/helpers/test_utils_create.js | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/addons/web/static/tests/helpers/test_utils_create.js b/addons/web/static/tests/helpers/test_utils_create.js index 17debd413d0..86fc01b5a4c 100644 --- a/addons/web/static/tests/helpers/test_utils_create.js +++ b/addons/web/static/tests/helpers/test_utils_create.js @@ -15,11 +15,11 @@ odoo.define('web.test_utils_create', function (require) { const concurrency = require('web.concurrency'); const config = require('web.config'); const ControlPanel = require('web.ControlPanel'); - const ControlPanelModel = require('web.ControlPanelModel'); const customHooks = require('web.custom_hooks'); const DebugManager = require('web.DebugManager.Backend'); const dom = require('web.dom'); const makeTestEnvironment = require('web.test_env'); + const ActionModel = require('web/static/src/js/views/action_model.js'); const Registry = require('web.Registry'); const testUtilsMock = require('web.test_utils_mock'); const Widget = require('web.Widget'); @@ -173,7 +173,7 @@ odoo.define('web.test_utils_create', function (require) { * available event handlers respectively. * @param {Object} [params={}] * @param {Object} [params.cpProps] - * @param {Object} [params.cpStoreConfig] + * @param {Object} [params.cpModelConfig] * @param {boolean} [params.debug] * @param {Object} [params.env] * @returns {Object} useful control panel testing elements: @@ -183,61 +183,70 @@ odoo.define('web.test_utils_create', function (require) { * available helpers) */ async function createControlPanel(params = {}) { - const config = params.cpStoreConfig || {}; const debug = params.debug || false; - const env = params.env || {}; + const env = makeTestEnvironment(params.env || {}); const props = Object.assign({ action: {}, fields: {}, }, params.cpProps); + const globalConfig = Object.assign({ + context: {}, + domain: [], + }, params.cpModelConfig); - if (config.viewInfo && config.viewInfo.arch && config.viewInfo.fields) { - const { arch, fields } = config.viewInfo; + if (globalConfig.arch && globalConfig.fields) { const model = "__mockmodel__"; const serverParams = { model, - data: { [model]: { fields, records: [] } }, + data: { [model]: { fields: globalConfig.fields, records: [] } }, }; const mockServer = await testUtilsMock.addMockEnvironment( new Widget(), serverParams, ); - Object.assign(config.viewInfo, testUtilsMock.fieldsViewGet(mockServer, { - arch, - fields, + const { arch, fields } = testUtilsMock.fieldsViewGet(mockServer, { + arch: globalConfig.arch, + fields: globalConfig.fields, model, - viewOptions: { context: config.actionContext }, - })); + viewOptions: { context: globalConfig.context }, + }); + Object.assign(globalConfig, { arch, fields }); } + globalConfig.env = env; + const archs = (globalConfig.arch && { search: globalConfig.arch, }) || {}; + const { ControlPanel: controlPanelInfo, } = ActionModel.extractArchInfo(archs); + const extensions = { + ControlPanel: { archNodes: controlPanelInfo.children, }, + }; + class Parent extends Component { constructor() { super(); - config.env = this.env; - this._controlPanelModel = new ControlPanelModel(config); + this.searchModel = new ActionModel(extensions, globalConfig); this.state = useState(props); this.controlPanel = useRef("controlPanel"); } async willStart() { - await this._controlPanelModel.isReady; + await this.searchModel.load(); } mounted() { if (params['get-controller-query-params']) { - this._controlPanelModel.on('get-controller-query-params', this, + this.searchModel.on('get-controller-query-params', this, params['get-controller-query-params']); } if (params.search) { - this._controlPanelModel.on('search', this, params.search); + this.searchModel.on('search', this, params.search); } } } Parent.components = { ControlPanel }; - Parent.env = makeTestEnvironment(env); + Parent.env = env; Parent.template = xml` <ControlPanel t-ref="controlPanel" t-props="state" - controlPanelModel="_controlPanelModel" + searchModel="searchModel" />`; const parent = new Parent(); @@ -249,7 +258,7 @@ odoo.define('web.test_utils_create', function (require) { controlPanel.destroy = destroy; parent.destroy(); }; - controlPanel.getQuery = () => parent._controlPanelModel.getQuery(); + controlPanel.getQuery = () => parent.searchModel.get('query'); return controlPanel; } |
