summaryrefslogtreecommitdiff
path: root/addons/web/static/tests
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2019-04-12 13:37:44 +0200
committerChristophe Simonis <chs@odoo.com>2019-04-12 13:37:44 +0200
commit0a09a4d8a819ef06db47e798f0465e500004e4c1 (patch)
treeb9d66d60a1e9b5ff6030be62fff89df410b744ee /addons/web/static/tests
parentdb97bb7f1136dc3ebde9924b79364a698a63765d (diff)
parent120359bf0c98191051ac19ae2e5fde53ca7d2ae5 (diff)
[MERGE] forward port branch saas-12.3 up to 120359bf0c9
Diffstat (limited to 'addons/web/static/tests')
-rw-r--r--addons/web/static/tests/chrome/systray_tests.js43
-rw-r--r--addons/web/static/tests/helpers/test_utils_create.js1
-rw-r--r--addons/web/static/tests/views/calendar_tests.js36
-rw-r--r--addons/web/static/tests/views/list_tests.js156
4 files changed, 235 insertions, 1 deletions
diff --git a/addons/web/static/tests/chrome/systray_tests.js b/addons/web/static/tests/chrome/systray_tests.js
new file mode 100644
index 00000000000..c5238ceff04
--- /dev/null
+++ b/addons/web/static/tests/chrome/systray_tests.js
@@ -0,0 +1,43 @@
+odoo.define('web.systray_tests', function (require) {
+ "use strict";
+
+ var testUtils = require('web.test_utils');
+ var SystrayMenu = require('web.SystrayMenu');
+ var Widget = require('web.Widget');
+
+ QUnit.test('Adding async components to the registry respects the sequence', async function (assert) {
+ assert.expect(2);
+ var parent = testUtils.createParent({
+ });
+ var prom = testUtils.makeTestPromise();
+
+ var synchronousFirstWidget = Widget.extend({
+ sequence: 3, // bigger sequence means more to the left
+ start: function () {
+ this.$el.addClass('first');
+ }
+ });
+ var asynchronousSecondWidget = Widget.extend({
+ sequence: 1, // smaller sequence means more to the right
+ willStart: function () {
+ return prom;
+ },
+ start: function () {
+ this.$el.addClass('second');
+ }
+ });
+
+ SystrayMenu.Items = [synchronousFirstWidget, asynchronousSecondWidget];
+ var menu = new SystrayMenu(parent);
+
+ menu.appendTo($('#qunit-fixture'));
+ await testUtils.nextTick();
+ prom.resolve();
+ await testUtils.nextTick();
+
+ assert.hasClass(menu.$('div:eq(0)'), 'first');
+ assert.hasClass(menu.$('div:eq(1)'), 'second');
+
+ parent.destroy();
+ })
+});
diff --git a/addons/web/static/tests/helpers/test_utils_create.js b/addons/web/static/tests/helpers/test_utils_create.js
index 097d46e93f7..f1c67284707 100644
--- a/addons/web/static/tests/helpers/test_utils_create.js
+++ b/addons/web/static/tests/helpers/test_utils_create.js
@@ -392,7 +392,6 @@ function createParent(params) {
return {
createActionManager: createActionManager,
- createView: createView,
createCalendarView: createCalendarView,
createControlPanel: createControlPanel,
createDebugManager: createDebugManager,
diff --git a/addons/web/static/tests/views/calendar_tests.js b/addons/web/static/tests/views/calendar_tests.js
index 9f637c4fdc5..01f431589fc 100644
--- a/addons/web/static/tests/views/calendar_tests.js
+++ b/addons/web/static/tests/views/calendar_tests.js
@@ -2371,6 +2371,42 @@ QUnit.module('Views', {
calendar.destroy();
});
+ QUnit.test('form_view_id attribute works with popup (for creating events)', async function (assert) {
+ assert.expect(1);
+
+ var calendar = await createCalendarView({
+ View: CalendarView,
+ model: 'event',
+ data: this.data,
+ arch: '<calendar class="o_calendar_test" '+
+ 'date_start="start" '+
+ 'date_stop="stop" '+
+ 'mode="month" '+
+ 'event_open_popup="true" ' +
+ 'quick_add="false" ' +
+ 'form_view_id="1">'+
+ '<field name="name"/>'+
+ '</calendar>',
+ archs: archs,
+ viewOptions: {
+ initialDate: initialDate,
+ },
+ mockRPC: function (route, args) {
+ if (args.method === "load_views") {
+ assert.strictEqual(args.kwargs.views[0][0], 1,
+ "should load view with id 1");
+ }
+ return this._super(route, args);
+ },
+ });
+
+ var $cell = calendar.$('.fc-day-grid .fc-row:eq(2) .fc-day:eq(2)');
+ testUtils.dom.triggerMouseEvent($cell, "mousedown");
+ testUtils.dom.triggerMouseEvent($cell, "mouseup");
+ await testUtils.nextTick();
+ calendar.destroy();
+ });
+
QUnit.test('calendar fallback to form view id in action if necessary', 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 5e5a0c7b7a1..7aff294fb97 100644
--- a/addons/web/static/tests/views/list_tests.js
+++ b/addons/web/static/tests/views/list_tests.js
@@ -1957,6 +1957,37 @@ QUnit.module('Views', {
list.destroy();
});
+ QUnit.test('editable list view with groupby node and modifiers', async function (assert) {
+ assert.expect(3);
+
+ var list = await createView({
+ View: ListView,
+ model: 'foo',
+ data: this.data,
+ arch: '<tree expand="1" editable="bottom">' +
+ '<field name="foo"/>' +
+ '<groupby name="currency_id">' +
+ '<field name="position"/>' +
+ '<button string="Button 1" type="object" name="button_method" attrs=\'{"invisible": [("position", "=", "after")]}\'/>' +
+ '</groupby>' +
+ '</tree>',
+ groupBy: ['currency_id'],
+ });
+
+ assert.doesNotHaveClass(list.$('.o_data_row:first'), 'o_selected_row',
+ "first row should be in readonly mode");
+
+ await testUtils.dom.click(list.$('.o_data_row:first .o_data_cell'));
+ assert.hasClass(list.$('.o_data_row:first'), 'o_selected_row',
+ "the row should be in edit mode");
+
+ await testUtils.fields.triggerKeydown($(document.activeElement), 'escape');
+ assert.doesNotHaveClass(list.$('.o_data_row:first'), 'o_selected_row',
+ "the row should be back in readonly mode");
+
+ list.destroy();
+ });
+
QUnit.test('groupby node with edit button', async function (assert) {
assert.expect(1);
@@ -3212,6 +3243,90 @@ QUnit.module('Views', {
list.destroy();
});
+ QUnit.test('pressing SHIFT-TAB in editable list with a readonly field [REQUIRE FOCUS]', async function (assert) {
+ assert.expect(4);
+
+ var list = await createView({
+ View: ListView,
+ model: 'foo',
+ data: this.data,
+ arch: '<tree editable="bottom">' +
+ '<field name="foo"/>' +
+ '<field name="int_field" readonly="1"/>' +
+ '<field name="qux"/>' +
+ '</tree>',
+ });
+
+ // start on 'qux', line 3
+ await testUtils.dom.click(list.$('.o_data_row:nth(2) .o_data_cell:nth(2)'));
+ assert.hasClass(list.$('.o_data_row:nth(2)'), 'o_selected_row');
+ assert.strictEqual(document.activeElement, list.$('.o_data_row:nth(2) .o_data_cell input[name=qux]')[0]);
+
+ // Press 'shift-Tab' -> should go to first cell (same line)
+ $(document.activeElement).trigger({type: 'keydown', which: $.ui.keyCode.TAB, shiftKey: true});
+ await testUtils.nextTick();
+ assert.hasClass(list.$('.o_data_row:nth(2)'), 'o_selected_row');
+ assert.strictEqual(document.activeElement, list.$('.o_data_row:nth(2) .o_data_cell input[name=foo]')[0]);
+
+ list.destroy();
+ });
+
+ QUnit.test('pressing SHIFT-TAB in editable list with a readonly field in first column [REQUIRE FOCUS]', async function (assert) {
+ assert.expect(4);
+
+ var list = await createView({
+ View: ListView,
+ model: 'foo',
+ data: this.data,
+ arch: '<tree editable="bottom">' +
+ '<field name="int_field" readonly="1"/>' +
+ '<field name="foo"/>' +
+ '<field name="qux"/>' +
+ '</tree>',
+ });
+
+ // start on 'foo', line 3
+ await testUtils.dom.click(list.$('.o_data_row:nth(2) .o_data_cell:nth(1)'));
+ assert.hasClass(list.$('.o_data_row:nth(2)'), 'o_selected_row');
+ assert.strictEqual(document.activeElement, list.$('.o_data_row:nth(2) .o_data_cell input[name=foo]')[0]);
+
+ // Press 'shift-Tab' -> should go to previous line (last cell)
+ $(document.activeElement).trigger({type: 'keydown', which: $.ui.keyCode.TAB, shiftKey: true});
+ await testUtils.nextTick();
+ assert.hasClass(list.$('.o_data_row:nth(1)'), 'o_selected_row');
+ assert.strictEqual(document.activeElement, list.$('.o_data_row:nth(1) .o_data_cell input[name=qux]')[0]);
+
+ list.destroy();
+ });
+
+ QUnit.test('pressing SHIFT-TAB in editable list with a readonly field in last column [REQUIRE FOCUS]', async function (assert) {
+ assert.expect(4);
+
+ var list = await createView({
+ View: ListView,
+ model: 'foo',
+ data: this.data,
+ arch: '<tree editable="bottom">' +
+ '<field name="int_field"/>' +
+ '<field name="foo"/>' +
+ '<field name="qux" readonly="1"/>' +
+ '</tree>',
+ });
+
+ // start on 'int_field', line 3
+ await testUtils.dom.click(list.$('.o_data_row:nth(2) .o_data_cell:first'));
+ assert.hasClass(list.$('.o_data_row:nth(2)'), 'o_selected_row');
+ assert.strictEqual(document.activeElement, list.$('.o_data_row:nth(2) .o_data_cell input[name=int_field]')[0]);
+
+ // Press 'shift-Tab' -> should go to previous line ('foo' field)
+ $(document.activeElement).trigger({type: 'keydown', which: $.ui.keyCode.TAB, shiftKey: true});
+ await testUtils.nextTick();
+ assert.hasClass(list.$('.o_data_row:nth(1)'), 'o_selected_row');
+ assert.strictEqual(document.activeElement, list.$('.o_data_row:nth(1) .o_data_cell input[name=foo]')[0]);
+
+ list.destroy();
+ });
+
QUnit.test('skip invisible fields when navigating list view with TAB', async function (assert) {
assert.expect(2);
@@ -4460,6 +4575,47 @@ QUnit.module('Views', {
list.destroy();
});
+ QUnit.test('create record on list with modifiers depending on id', async function (assert) {
+ assert.expect(8);
+
+ var list = await createView({
+ View: ListView,
+ model: 'foo',
+ data: this.data,
+ arch: '<tree editable="top">' +
+ '<field name="id" invisible="1"/>' +
+ '<field name="foo" attrs="{\'readonly\': [[\'id\',\'!=\',False]]}"/>' +
+ '<field name="int_field" attrs="{\'invisible\': [[\'id\',\'!=\',False]]}"/>' +
+ '</tree>',
+ });
+
+ // add a new record
+ await testUtils.dom.click(list.$buttons.find('.o_list_button_add'));
+
+ // modifiers should be evaluted to false
+ assert.containsOnce(list, '.o_selected_row');
+ assert.doesNotHaveClass(list.$('.o_selected_row .o_data_cell:first'), 'o_readonly_modifier');
+ assert.doesNotHaveClass(list.$('.o_selected_row .o_data_cell:nth(1)'), 'o_invisible_modifier');
+
+ // set a value and save
+ await testUtils.fields.editInput(list.$('.o_selected_row input[name=foo]'), 'some value');
+ await testUtils.dom.click(list.$buttons.find('.o_list_button_save'));
+
+ // modifiers should be evaluted to true
+ assert.hasClass(list.$('.o_data_row:first .o_data_cell:first'), 'o_readonly_modifier');
+ assert.hasClass(list.$('.o_data_row:first .o_data_cell:nth(1)'), 'o_invisible_modifier');
+
+ // edit again the just created record
+ await testUtils.dom.click(list.$('.o_data_row:first .o_data_cell:first'));
+
+ // modifiers should be evaluted to true
+ assert.containsOnce(list, '.o_selected_row');
+ assert.hasClass(list.$('.o_selected_row .o_data_cell:first'), 'o_readonly_modifier');
+ assert.hasClass(list.$('.o_selected_row .o_data_cell:nth(1)'), 'o_invisible_modifier');
+
+ list.destroy();
+ });
+
QUnit.test('grouped list with async widget', async function (assert) {
assert.expect(4);