odoo.define('web.action_manager_mobile_tests', function (require) { "use strict"; var testUtils = require('web.test_utils'); var createActionManager = testUtils.createActionManager; QUnit.module('ActionManager', { beforeEach: function () { this.data = { partner: { fields: { foo: {string: "Foo", type: "char"}, }, records: [ {id: 1, display_name: "First record", foo: "yop"}, ], }, }; this.actions = [{ id: 1, name: 'Partners Action 1', res_model: 'partner', type: 'ir.actions.act_window', views: [[false, 'list'], [false, 'kanban'], [false, 'form']], }, { id: 2, name: 'Partners Action 2', res_model: 'partner', type: 'ir.actions.act_window', views: [[false, 'list'], [false, 'form']], }]; this.archs = { // kanban views 'partner,false,kanban': '' + '
' + '
', // list views 'partner,false,list': '', // form views 'partner,false,form': '
' + '' + '' + '' + '
', // search views 'partner,false,search': '', }; }, }, function () { QUnit.test('uses a mobile-friendly view by default (if possible)', function (assert) { assert.expect(4); var actionManager = createActionManager({ actions: this.actions, archs: this.archs, data: this.data, }); // should default on a mobile-friendly view (kanban) for action 1 actionManager.doAction(1); assert.strictEqual(actionManager.$('.o_list_view').length, 0, "should not have rendered the list view"); assert.strictEqual(actionManager.$('.o_kanban_view').length, 1, "should have rendered the kanban view"); // there is no mobile-friendly view for action 2, should use the first one (list) actionManager.doAction(2); assert.strictEqual(actionManager.$('.o_list_view').length, 1, "should have rendered the list view"); assert.strictEqual(actionManager.$('.o_kanban_view').length, 0, "there should be no kanban view in the DOM"); actionManager.destroy(); }); QUnit.test('lazy load mobile-friendly view', function (assert) { assert.expect(11); var actionManager = createActionManager({ actions: this.actions, archs: this.archs, data: this.data, mockRPC: function (route, args) { assert.step(args.method || route); return this._super.apply(this, arguments); }, }); actionManager.loadState({ action: 1, view_type: 'form', }); assert.strictEqual(actionManager.$('.o_list_view').length, 0, "should not have rendered a list view"); assert.strictEqual(actionManager.$('.o_kanban_view').length, 0, "should not have rendered a kanban view either"); assert.strictEqual(actionManager.$('.o_form_view').length, 1, "should have rendered a form view"); // go back to lazy loaded view $('.o_control_panel .breadcrumb a').click(); assert.strictEqual(actionManager.$('.o_form_view').length, 0, "should not display the form view anymore"); assert.strictEqual(actionManager.$('.o_list_view').length, 0, "should not display the list view either"); assert.strictEqual(actionManager.$('.o_kanban_view').length, 1, "should have lazy loaded the kanban view"); assert.verifySteps([ '/web/action/load', 'load_views', 'default_get', // default_get to open form view '/web/dataset/search_read', // search read when coming back to Kanban ]); actionManager.destroy(); }); }); });