summaryrefslogtreecommitdiff
path: root/addons/web/static/tests
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web/static/tests')
-rw-r--r--addons/web/static/tests/chrome/action_manager_tests.js35
-rw-r--r--addons/web/static/tests/fields/relational_fields_tests.js12
-rw-r--r--addons/web/static/tests/views/form_tests.js59
-rw-r--r--addons/web/static/tests/views/list_tests.js135
-rw-r--r--addons/web/static/tests/views/pivot_tests.js68
5 files changed, 291 insertions, 18 deletions
diff --git a/addons/web/static/tests/chrome/action_manager_tests.js b/addons/web/static/tests/chrome/action_manager_tests.js
index 5724da4b2f8..b98a973695f 100644
--- a/addons/web/static/tests/chrome/action_manager_tests.js
+++ b/addons/web/static/tests/chrome/action_manager_tests.js
@@ -880,6 +880,41 @@ QUnit.module('ActionManager', {
actionManager.destroy();
});
+ QUnit.test('lazy loaded multi record view with failing mono record one', async function (assert) {
+ assert.expect(4);
+
+ var actionManager = await createActionManager({
+ actions: this.actions,
+ archs: this.archs,
+ data: this.data,
+ mockRPC: function (route, args) {
+ if (args.method === 'read') {
+ return Promise.reject();
+ }
+ return this._super.apply(this, arguments);
+ },
+ });
+
+ await actionManager.loadState({
+ action: 3,
+ id: 2,
+ view_type: 'form',
+ }).then(function () {
+ assert.ok(false, 'should not resolve the deferred');
+ }).catch(function () {
+ assert.ok(true, 'should reject the deferred');
+ });
+
+ assert.containsNone(actionManager, '.o_form_view');
+ assert.containsNone(actionManager, '.o_list_view');
+
+ await actionManager.doAction(1);
+
+ assert.containsOnce(actionManager, '.o_kanban_view');
+
+ actionManager.destroy();
+ });
+
QUnit.test('change the viewType of the current action', async function (assert) {
assert.expect(13);
diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js
index b5e098d230c..9c649cc0173 100644
--- a/addons/web/static/tests/fields/relational_fields_tests.js
+++ b/addons/web/static/tests/fields/relational_fields_tests.js
@@ -313,8 +313,8 @@ QUnit.module('relational_fields', {
await testUtils.form.clickEdit(form);
await testUtils.dom.click(form.$('.o_external_button'));
- var $originalModal = $('.modal-dialog');
- var $focusedModal = $(document.activeElement).closest('.modal-dialog');
+ var $originalModal = $('.modal');
+ var $focusedModal = $(document.activeElement).closest('.modal');
assert.equal($originalModal.length, 1, 'There should be one modal');
assert.equal($originalModal[0], $focusedModal[0], 'Modal is focused');
@@ -322,8 +322,8 @@ QUnit.module('relational_fields', {
// Open many2one modal of field in many2one modal
await testUtils.dom.click($originalModal.find('.o_external_button'));
- var $modals = $('.modal-dialog');
- $focusedModal = $(document.activeElement).closest('.modal-dialog');
+ var $modals = $('.modal');
+ $focusedModal = $(document.activeElement).closest('.modal');
assert.equal($modals.length, 2, 'There should be two modals');
assert.equal($modals[1], $focusedModal[0], 'Last modal is focused');
@@ -331,8 +331,8 @@ QUnit.module('relational_fields', {
// Close second modal
await testUtils.dom.click($modals.last().find('button[class="close"]'));
- var $modal = $('.modal-dialog');
- $focusedModal = $(document.activeElement).closest('.modal-dialog');
+ var $modal = $('.modal');
+ $focusedModal = $(document.activeElement).closest('.modal');
assert.equal($modal.length, 1, 'There should be one modal');
assert.equal($modal[0], $originalModal[0], 'First modal is still opened');
diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js
index cd9659aceed..1fa82e3f238 100644
--- a/addons/web/static/tests/views/form_tests.js
+++ b/addons/web/static/tests/views/form_tests.js
@@ -4881,6 +4881,65 @@ QUnit.module('Views', {
form.destroy();
});
+ QUnit.module('focus and scroll test', async function () {
+ QUnit.test('no focus set on form when closing many2one modal if lastActivatedFieldIndex is not set', async function (assert) {
+ assert.expect(8);
+
+ var form = await createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: '<form string="Partners">' +
+ '<field name="display_name"/>' +
+ '<field name="foo"/>' +
+ '<field name="bar"/>' +
+ '<field name="p"/>' +
+ '<field name="timmy"/>' +
+ '<field name="product_ids"/>' +
+ '<field name="trululu"/>' +
+ '</form>',
+ res_id: 2,
+ archs: {
+ 'partner,false,list': '<tree><field name="display_name"/></tree>',
+ 'partner_type,false,list': '<tree><field name="name"/></tree>',
+ 'partner,false,form': '<form><field name="trululu"/></form>',
+ 'product,false,list': '<tree><field name="name"/></tree>',
+ },
+ mockRPC: function (route, args) {
+ if (args.method === 'get_formview_id') {
+ return Promise.resolve(false);
+ }
+ return this._super(route, args);
+ },
+ });
+
+ // set max-height to have scroll forcefully so that we can test scroll position after modal close
+ $('.o_content').css({'overflow': 'auto', 'max-height': '300px'});
+ // Open many2one modal, lastActivatedFieldIndex will not set as we directly click on external button
+ await testUtils.form.clickEdit(form);
+ assert.strictEqual($(".o_content").scrollTop(), 0, "scroll position should be 0");
+
+ form.$(".o_field_many2one[name='trululu'] .o_input").focus();
+ assert.notStrictEqual($(".o_content").scrollTop(), 0, "scroll position should not be 0");
+
+ await testUtils.dom.click(form.$('.o_external_button'));
+ // Close modal
+ await testUtils.dom.click($('.modal').last().find('button[class="close"]'));
+ assert.notStrictEqual($(".o_content").scrollTop(), 0,
+ "scroll position should not be 0 after closing modal");
+ assert.containsNone(document.body, '.modal', 'There should be no modal');
+ assert.doesNotHaveClass($('body'), 'modal-open', 'Modal is not said opened');
+ assert.strictEqual(form.renderer.lastActivatedFieldIndex, -1,
+ "lastActivatedFieldIndex is -1");
+ assert.equal(document.activeElement, $('body')[0],
+ 'body is focused, should not set focus on form widget');
+ assert.notStrictEqual(document.activeElement, form.$('.o_field_many2one[name="trululu"] .o_input'),
+ 'field widget should not be focused when lastActivatedFieldIndex is -1');
+
+ form.destroy();
+ });
+ });
+
QUnit.test('in create mode, autofocus fields are focused', async function (assert) {
assert.expect(1);
diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js
index 4e324762372..5dd64d6a074 100644
--- a/addons/web/static/tests/views/list_tests.js
+++ b/addons/web/static/tests/views/list_tests.js
@@ -553,10 +553,29 @@ QUnit.module('Views', {
hasSelectors: false,
});
- assert.strictEqual(list.$('.o_group_header:first').children().length, 1,
- "group header should have exactly 1 column");
+ assert.strictEqual(list.$('.o_group_header:first').children().length, 2,
+ "group header should have exactly 2 column");
+ assert.strictEqual(list.$('.o_group_header:first th').attr('colspan'), "1",
+ "the header should not span the whole table");
+ list.destroy();
+ });
+
+ QUnit.test('basic grouped list rendering 3 cols without selector', async function (assert) {
+ assert.expect(2);
+
+ var list = await createView({
+ View: ListView,
+ model: 'foo',
+ data: this.data,
+ arch: '<tree ><field name="foo"/><field name="bar"/><field name="text"/></tree>',
+ groupBy: ['bar'],
+ hasSelectors: false,
+ });
+
+ assert.strictEqual(list.$('.o_group_header:first').children().length, 2,
+ "group header should have exactly 2 columns");
assert.strictEqual(list.$('.o_group_header:first th').attr('colspan'), "2",
- "the header should span the whole table");
+ "the first header should span two columns");
list.destroy();
});
@@ -572,10 +591,29 @@ QUnit.module('Views', {
hasSelectors: true,
});
- assert.strictEqual(list.$('.o_group_header:first').children().length, 1,
- "group header should have exactly 1 column");
+ assert.strictEqual(list.$('.o_group_header:first').children().length, 2,
+ "group header should have exactly 2 columns");
+ assert.strictEqual(list.$('.o_group_header:first th').attr('colspan'), "2",
+ "the header should not span the whole table");
+ list.destroy();
+ });
+
+ QUnit.test('basic grouped list rendering 3 cols with selector', async function (assert) {
+ assert.expect(2);
+
+ var list = await createView({
+ View: ListView,
+ model: 'foo',
+ data: this.data,
+ arch: '<tree ><field name="foo"/><field name="bar"/><field name="text"/></tree>',
+ groupBy: ['bar'],
+ hasSelectors: true,
+ });
+
+ assert.strictEqual(list.$('.o_group_header:first').children().length, 2,
+ "group header should have exactly 2 columns");
assert.strictEqual(list.$('.o_group_header:first th').attr('colspan'), "3",
- "the header should span the whole table");
+ "the header should not span the whole table");
list.destroy();
});
@@ -1391,6 +1429,39 @@ QUnit.module('Views', {
list.destroy();
});
+ QUnit.test('width of some of the fields should be hardcoded', async function (assert) {
+ const assertions = [
+ { field: 'bar', expected: 40, type: 'Boolean' },
+ { field: 'int_field', expected: 80, type: 'Integer' },
+ { field: 'qux', expected: 100, type: 'Float' },
+ { field: 'date', expected: 100, type: 'Date' },
+ { field: 'datetime', expected: 150, type: 'Datetime' },
+ ];
+ assert.expect(assertions.length + 1);
+
+ var list = await createView({
+ View: ListView,
+ model: 'foo',
+ data: this.data,
+ arch: '<tree editable="top">' +
+ '<field name="bar"/>' +
+ '<field name="foo"/>' +
+ '<field name="int_field"/>' +
+ '<field name="qux"/>' +
+ '<field name="date"/>' +
+ '<field name="datetime"/>' +
+ '</tree>',
+ });
+
+ assertions.forEach(a => {
+ assert.strictEqual(list.$(`th[data-name="${a.field}"]`)[0].offsetWidth, a.expected,
+ `Field ${a.type} should have a fixed width of ${a.expected} pixels`);
+ });
+ assert.strictEqual(list.$('th[data-name="foo"]')[0].style.width, '100%', "Char field should occupy the remaining space");
+
+ list.destroy();
+ });
+
QUnit.test('row height should not change when switching mode', async function (assert) {
// Warning: this test is css dependant
assert.expect(3);
@@ -1414,7 +1485,7 @@ QUnit.module('Views', {
'<field name="int_field" readonly="1"/>' +
'<field name="boolean"/>' +
'<field name="date"/>' +
- '<field name="text" width_factor="2"/>' +
+ '<field name="text" width_factor="1"/>' +
'<field name="amount"/>' +
'<field name="currency_id" invisible="1"/>' +
'<field name="m2o"/>' +
@@ -1424,6 +1495,11 @@ QUnit.module('Views', {
currencies: currencies,
},
});
+
+ // the width is hardcoded to make sure we have the same condition
+ // between debug mode and non debug mode (#qunit-fixture is limited to
+ // 1000px)
+ list.$el.width('1000px');
var startHeight = list.$('.o_data_row:first').height();
// start edition of first row
@@ -2094,8 +2170,8 @@ QUnit.module('Views', {
await testUtils.dom.click(list.$('tbody:eq(1) .o_group_header:eq(0)'));
- assert.containsNone(list, '.o_group_header button',
- "there should be no button in the header");
+ assert.containsOnce(list, '.o_group_header button',
+ "there should be one button in the header");
list.destroy();
});
@@ -2759,8 +2835,8 @@ QUnit.module('Views', {
await testUtils.dom.click(list.$('.o_group_header'));
assert.strictEqual(list.$('.o_group_header').css('height'), headerHeight,
"height of group header shouldn't have changed");
- assert.hasClass(list.$('.o_group_header th'), 'o_group_pager',
- "last cell of open group header should have classname 'o_group_header'");
+ assert.hasClass(list.$('.o_group_header th:eq(1) > div'), 'o_pager',
+ "last cell of open group header should have classname 'o_pager'");
assert.strictEqual(list.$('.o_group_header .o_pager_value').text(), '1-3',
"pager's value should be correct");
assert.containsN(list, '.o_data_row', 3,
@@ -4299,6 +4375,43 @@ QUnit.module('Views', {
list.destroy();
});
+ QUnit.test('editable list view: contexts with multiple edit', async function (assert) {
+ assert.expect(4);
+
+ var list = await createView({
+ View: ListView,
+ model: 'foo',
+ data: this.data,
+ arch: '<tree editable="top">' +
+ '<field name="foo"/>' +
+ '</tree>',
+ mockRPC: function (route, args) {
+ if (route === '/web/dataset/call_kw/foo/write' ||
+ route === '/web/dataset/call_kw/foo/read') {
+ var context = args.kwargs.context;
+ assert.strictEqual(context.active_field, 2, "context should be correct");
+ assert.strictEqual(context.someKey, 'some value', "context should be correct");
+ }
+ return this._super.apply(this, arguments);
+ },
+ session: {
+ user_context: {someKey: 'some value'},
+ },
+ viewOptions: {
+ context: {active_field: 2},
+ },
+ });
+
+ // Uses the main selector to select all lines.
+ await testUtils.dom.click(list.$('.o_content input:first'));
+ await testUtils.dom.click(list.$('.o_data_cell:first'));
+ // Edits first record then confirms changes.
+ await testUtils.fields.editInput(list.$('.o_field_widget[name=foo]'), 'legion');
+ await testUtils.dom.click($('.modal-dialog button.btn-primary'));
+
+ list.destroy();
+ });
+
QUnit.test('editable list view: multi edition', async function (assert) {
assert.expect(19);
diff --git a/addons/web/static/tests/views/pivot_tests.js b/addons/web/static/tests/views/pivot_tests.js
index 333f51f75ba..3a83a23b64e 100644
--- a/addons/web/static/tests/views/pivot_tests.js
+++ b/addons/web/static/tests/views/pivot_tests.js
@@ -4,6 +4,7 @@ odoo.define('web.pivot_tests', function (require) {
var core = require('web.core');
var PivotView = require('web.PivotView');
var testUtils = require('web.test_utils');
+var testUtilsDom = require('web.test_utils_dom');
var createActionManager = testUtils.createActionManager;
var patchDate = testUtils.mock.patchDate;
@@ -16,7 +17,7 @@ QUnit.module('Views', {
this.data = {
partner: {
fields: {
- foo: {string: "Foo", type: "integer"},
+ foo: {string: "Foo", type: "integer", searchable: true},
bar: {string: "bar", type: "boolean"},
date: {string: "Date", type: "date", store: true, sortable: true},
product_id: {string: "Product", type: "many2one", relation: 'product', store: true},
@@ -1880,6 +1881,71 @@ QUnit.module('Views', {
actionManager.destroy();
});
+ QUnit.test('Navigation list view for a group and back with breadcrumbs', async function (assert) {
+ assert.expect(16);
+ // create an action manager to test the interactions with the search view
+ var readGroupCount = 0;
+ var actionManager = await createActionManager({
+ data: this.data,
+ archs: {
+ 'partner,false,pivot': '<pivot>' +
+ '<field name="customer" type="row"/>' +
+ '</pivot>',
+ 'partner,false,search': '<search><filter name="bayou" string="Bayou" domain="[(\'foo\',\'=\', 12)]"/></search>',
+ 'partner,false,list': '<tree><field name="foo"/></tree>',
+ 'partner,false,form': '<form><field name="foo"/></form>',
+ },
+ intercepts: {
+ do_action: function (event) {
+ var action = event.data.action;
+ actionManager.doAction(action);
+ }
+ },
+ mockRPC: function (route, args) {
+ if (args.method === 'read_group') {
+ assert.step('read_group');
+ var domain = args.kwargs.domain;
+ if ([0,1].indexOf(readGroupCount) !== -1) {
+ assert.deepEqual(domain, [], 'initial domain empty');
+ } else if ([2,3,4,5].indexOf(readGroupCount) !== -1) {
+ assert.deepEqual(domain, [['foo', '=', 12]],
+ 'domain conserved when back with breadcrumbs');
+ }
+ readGroupCount++;
+ }
+ if (route === '/web/dataset/search_read') {
+ assert.step('search_read');
+ var domain = args.domain;
+ assert.deepEqual(domain, [['foo', '=', 12], ['customer', '=', 1], ['foo', '=', 12]],
+ 'list domain is correct');
+ }
+ return this._super.apply(this, arguments);
+ }
+ });
+
+ await actionManager.doAction({
+ res_model: 'partner',
+ type: 'ir.actions.act_window',
+ views: [[false, 'pivot']],
+ });
+
+ await testUtilsDom.click(actionManager.$('.o_filters_menu_button'));
+ await testUtilsDom.click(actionManager.$('.o_menu_item:contains("Bayou")'));
+
+ await testUtilsDom.click(actionManager.$('.o_pivot_cell_value:nth(1)'))
+
+ assert.containsOnce(actionManager, '.o_list_view');
+
+ await testUtilsDom.click(actionManager.$('.o_control_panel .breadcrumb-item:first() a'));
+
+ assert.verifySteps([
+ 'read_group', 'read_group',
+ 'read_group', 'read_group',
+ 'search_read',
+ 'read_group', 'read_group'])
+ actionManager.destroy();
+ });
+
QUnit.module('Sort in comparison mode', {
beforeEach: async function () {
this.data.partner.records[0].date = '2016-12-15';