summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/fields/basic_fields_tests.js
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2018-09-19 09:12:38 +0000
committerChristophe Simonis <chs@odoo.com>2018-09-19 09:12:38 +0000
commit77849703a13361e0acc7fac81fe69ab83bf8898a (patch)
treed208fa140d9be5c5eb73e8ffe34c913ad5593e29 /addons/web/static/tests/fields/basic_fields_tests.js
parent3117afbb7e4a4a762ff041f7797250d3b3bd9a05 (diff)
parent197119a37d19bf89f0c909f8efcfecdf6f7e17b5 (diff)
[MERGE] forward port branch saas-11.5 up to 197119a37d1
closes odoo/odoo#27088
Diffstat (limited to 'addons/web/static/tests/fields/basic_fields_tests.js')
-rw-r--r--addons/web/static/tests/fields/basic_fields_tests.js121
1 files changed, 100 insertions, 21 deletions
diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js
index 548a9cfec23..6e2188d2998 100644
--- a/addons/web/static/tests/fields/basic_fields_tests.js
+++ b/addons/web/static/tests/fields/basic_fields_tests.js
@@ -2306,6 +2306,45 @@ QUnit.module('basic_fields', {
assert.verifySteps(['destroy']);
});
+ QUnit.test('graph dashboard widget can be destroyed when nv is partially loaded', function (assert) {
+ // this test ensures that the JournalDashboardGraph widget doesn't crash
+ // when being destroyed before nv has been completely loaded
+ assert.expect(2);
+
+ testUtils.patch(basicFields.JournalDashboardGraph, {
+ destroy: function () {
+ assert.step('destroy');
+ // nv is fully loaded only when nvd3.js has been loaded
+ // which happens sequentially after nv.d3.js
+ // we simulate this race condition with:
+ var offWindowResize = window.nv.utils.offWindowResize;
+ window.nv.utils.offWindowResize = undefined;
+ this._super.apply(this, arguments);
+ window.nv.utils.offWindowResize = offWindowResize;
+ },
+ });
+
+ var kanban = createView({
+ View: KanbanView,
+ model: 'partner',
+ data: this.data,
+ arch: '<kanban class="o_kanban_test">' +
+ '<field name="graph_type"/>' +
+ '<templates><t t-name="kanban-box">' +
+ '<div>' +
+ '<field name="graph_data" t-att-graph_type="record.graph_type.raw_value" widget="dashboard_graph"/>' +
+ '</div>' +
+ '</t>' +
+ '</templates></kanban>',
+ domain: [['id', 'in', [1]]],
+ });
+
+ kanban.destroy();
+ testUtils.unpatch(basicFields.JournalDashboardGraph);
+
+ assert.verifySteps(['destroy']);
+ });
+
QUnit.module('AceEditor');
QUnit.test('ace widget on text fields works', function (assert) {
@@ -2393,6 +2432,36 @@ QUnit.module('basic_fields', {
QUnit.module('FieldDate');
+ QUnit.test('date field: toggle datepicker', function (assert) {
+ assert.expect(3);
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch:'<form><field name="foo"/><field name="date"/></form>',
+ translateParameters: { // Avoid issues due to localization formats
+ date_format: '%m/%d/%Y',
+ },
+ });
+
+ assert.strictEqual($('.bootstrap-datetimepicker-widget:visible').length, 0,
+ "datepicker should be closed initially");
+
+ testUtils.openDatepicker(form.$('.o_datepicker'));
+
+ assert.strictEqual($('.bootstrap-datetimepicker-widget:visible').length, 1,
+ "datepicker should be opened");
+
+ // focus another field
+ form.$('.o_field_widget[name=foo]').click().focus();
+
+ assert.strictEqual($('.bootstrap-datetimepicker-widget:visible').length, 0,
+ "datepicker should close itself when the user clicks outside");
+
+ form.destroy();
+ });
+
QUnit.test('date field is empty if no date is set', function (assert) {
assert.expect(2);
@@ -2419,12 +2488,19 @@ QUnit.module('basic_fields', {
arch:'<form string="Partners"><field name="date"/></form>',
res_id: 4,
});
+
form.$buttons.find('.o_form_button_edit').click();
- form.$('.o_datepicker_input').click();
+
+ // open datepicker and select a date
+ testUtils.openDatepicker(form.$('.o_datepicker'));
assert.strictEqual(form.$('.o_datepicker_input').val(), '', "date field's input should be empty on first click");
$('.day:contains(22)').click();
- form.$('.o_datepicker_input').click(); // Open Datepicker second time
- assert.strictEqual($('.day.active').text(), '22', 'datepicker should be highlight with 22nd day of month');
+
+ // re-open datepicker
+ testUtils.openDatepicker(form.$('.o_datepicker'));
+ assert.strictEqual($('.day.active').text(), '22',
+ "datepicker should be highlight with 22nd day of month");
+
form.destroy();
});
@@ -2461,8 +2537,8 @@ QUnit.module('basic_fields', {
assert.strictEqual(form.$('.o_datepicker_input').val(), '02/03/2017',
'the date should be correct in edit mode');
- // click on the input and select another value
- form.$('.o_datepicker_input').click();
+ // open datepicker and select another value
+ testUtils.openDatepicker(form.$('.o_datepicker'));
assert.ok($('.bootstrap-datetimepicker-widget').length, 'datepicker should be open');
assert.strictEqual($('.day.active').data('day'), '02/03/2017', 'datepicker should be highlight February 3');
$('.bootstrap-datetimepicker-widget .picker-switch').first().click(); // Month selection
@@ -2545,8 +2621,8 @@ QUnit.module('basic_fields', {
assert.strictEqual(list.$('input.o_datepicker_input').val(), '02/03/2017',
'the date should be correct in edit mode');
- // click on the input and select another value
- list.$('input.o_datepicker_input').click();
+ // open datepicker and select another value
+ testUtils.openDatepicker(list.$('.o_datepicker'));
assert.ok($('.bootstrap-datetimepicker-widget').length, 'datepicker should be open');
$('.bootstrap-datetimepicker-widget .picker-switch').first().click(); // Month selection
$('.bootstrap-datetimepicker-widget .picker-switch').first().click(); // Year selection
@@ -2590,13 +2666,15 @@ QUnit.module('basic_fields', {
assert.strictEqual(form.$('.o_datepicker_input').val(), '02/03/2017',
'the date should be correct in edit mode');
- $('.o_datepicker_input').val('').trigger('input').trigger('change');
- assert.ok(!form.$('.o_datepicker_input').val());
+ form.$('.o_datepicker_input').val('').trigger('input').trigger('change').trigger('focusout');
+ assert.strictEqual(form.$('.o_datepicker_input').val(), '',
+ 'should have correctly removed the value');
// save
form.$buttons.find('.o_form_button_save').click();
assert.strictEqual(form.$('.o_field_date').text(), '',
'the selected date should be displayed after saving');
+
form.destroy();
});
@@ -2625,7 +2703,8 @@ QUnit.module('basic_fields', {
assert.strictEqual(form.$('.o_datepicker_input').val(), '02/08/2017',
'the date should be correct');
- form.$('input[name="datetime"]').val('02/08/2017').trigger('input').trigger('change');
+ form.$('input[name="datetime"]').val('02/08/2017')
+ .trigger('input').trigger('change').trigger('focusout');
form.$buttons.find('.o_form_button_save').click();
assert.verifySteps(['read']); // should not have save as nothing changed
@@ -2694,7 +2773,7 @@ QUnit.module('basic_fields', {
});
QUnit.test('datetime field in form view 2', function (assert) {
- assert.expect(1);
+ assert.expect(2);
this.data.partner.fields.datetime.default = "2017-08-02 12:00:05";
this.data.partner.fields.datetime.required = true;
@@ -2704,23 +2783,21 @@ QUnit.module('basic_fields', {
model: 'partner',
data: this.data,
arch:'<form string="Partners"><field name="datetime"/></form>',
- res_id: 1,
translateParameters: { // Avoid issues due to localization formats
date_format: '%m/%d/%Y',
time_format: '%H:%M',
},
});
- testUtils.patch(basicFields.FieldDate, {
- _setValue: function () {
- throw "The time format of the language must be taken into account.";
- },
- });
- form.$buttons.find('.o_form_button_create').click();
+
var expectedDateString = "08/02/2017 12:00"; // 10:00:00 without timezone
assert.strictEqual(form.$('.o_field_date input').val(), expectedDateString,
'the datetime should be correctly displayed in readonly');
- testUtils.unpatch(basicFields.FieldDate);
+ form.$buttons.find('.o_form_button_cancel').click();
+
+ assert.strictEqual($('.modal').length, 0,
+ "there should not be a Warning dialog");
+
form.destroy();
});
@@ -2822,13 +2899,15 @@ QUnit.module('basic_fields', {
assert.strictEqual(form.$('.o_datepicker_input').val(), '02/08/2017 12:00:00',
'the date time should be correct in edit mode');
- $('.o_datepicker_input').val('').trigger('input').trigger('change');
- assert.ok(!form.$('.o_datepicker_input').val());
+ $('.o_datepicker_input').val('').trigger('input').trigger('change').trigger('focusout');
+ assert.strictEqual(form.$('.o_datepicker_input').val(), '',
+ "should have an empty input");
// save
form.$buttons.find('.o_form_button_save').click();
assert.strictEqual(form.$('.o_field_date').text(), '',
'the selected date should be displayed after saving');
+
form.destroy();
});