[MERGE] forward port branch saas-11.3 up to 0de06a4132

This commit is contained in:
Christophe Simonis
2018-10-17 10:54:19 +02:00
65 changed files with 889 additions and 300 deletions
@@ -10,6 +10,7 @@ var KanbanView = require('web.KanbanView');
var ListView = require('web.ListView');
var session = require('web.session');
var testUtils = require('web.test_utils');
var field_registry = require('web.field_registry');
var createView = testUtils.createView;
var DebouncedField = basicFields.DebouncedField;
@@ -1653,6 +1654,49 @@ QUnit.module('basic_fields', {
form.destroy();
});
QUnit.test("pdf_viewer: upload rendering", function (assert) {
assert.expect(6);
testUtils.patch(field_registry.map.pdf_viewer, {
on_file_change: function (ev) {
ev.target = {files: [new Blob()]};
this._super.apply(this, arguments);
},
_getURI: function (fileURI) {
var res = this._super.apply(this, arguments);
assert.step('_getURI');
assert.ok(_.str.startsWith(fileURI, 'blob:'));
this.PDFViewerApplication = {
open: function (URI) {
assert.step('open');
assert.ok(_.str.startsWith(URI, 'blob:'));
},
};
return 'about:blank';
},
});
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch:
'<form>' +
'<field name="document" widget="pdf_viewer"/>' +
'</form>',
});
// first upload initialize iframe
form.$('input[type="file"]').trigger('change');
assert.verifySteps(['_getURI']);
// second upload call pdfjs method inside iframe
form.$('input[type="file"]').trigger('change');
assert.verifySteps(['_getURI', 'open']);
testUtils.unpatch(field_registry.map.pdf_viewer);
form.destroy();
});
QUnit.test('text field rendering in list view', function (assert) {
assert.expect(1);
@@ -1852,6 +1896,40 @@ QUnit.module('basic_fields', {
form.destroy();
});
QUnit.test('image fields in x2many list are loaded correctly', function (assert) {
assert.expect(2);
this.data.partner_type.fields.image = {name: 'image', type: 'binary'};
this.data.partner_type.records[0].image = 'product_image';
this.data.partner.records[0].timmy = [12];
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<field name="timmy" widget="many2many">' +
'<tree>' +
'<field name="image" widget="image"/>' +
'</tree>' +
'</field>' +
'</form>',
res_id: 1,
mockRPC: function (route, args) {
if (route === 'data:image/png;base64,product_image') {
assert.ok(true, "The list's image should have been fetched");
return $.when();
}
return this._super.apply(this, arguments);
},
});
assert.strictEqual(form.$('tr.o_data_row').length, 1,
'There should be one record in the many2many');
form.destroy();
});
QUnit.test('image fields with required attribute', function (assert) {
assert.expect(2);
@@ -2148,7 +2226,7 @@ QUnit.module('basic_fields', {
});
QUnit.test('date field value should not set on first click', function (assert) {
assert.expect(2);
assert.expect(3);
var form = createView({
View: FormView,
@@ -2158,10 +2236,10 @@ QUnit.module('basic_fields', {
res_id: 4,
});
form.$buttons.find('.o_form_button_edit').click();
form.$('.o_datepicker_input').click();
assert.strictEqual($('.bootstrap-datetimepicker-widget').length, 1, "there should be a datepicker (autofocus)");
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
form.$('.o_datepicker_input').focus(); // Open Datepicker second time
assert.strictEqual($('.day.active').text(), '22', 'datepicker should be highlight with 22nd day of month');
form.destroy();
});
@@ -2199,8 +2277,7 @@ 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();
// select another value
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
@@ -2283,8 +2360,7 @@ 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();
// select another value
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
@@ -2401,8 +2477,7 @@ QUnit.module('basic_fields', {
form.$buttons.find('.o_form_button_edit').click();
assert.strictEqual(form.$('.o_datepicker_input').val(), expectedDateString,
'the datetime should be correct in edit mode');
// click on the input and select 22 February at 8:23:33
form.$('.o_datepicker_input').click();
// select 22 February at 8:23:33
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
@@ -2500,8 +2575,7 @@ QUnit.module('basic_fields', {
assert.strictEqual(list.$('input.o_datepicker_input').val(), expectedDateString,
'the date should be correct in edit mode');
// click on the input and select 22 February at 8:23:33
list.$('input.o_datepicker_input').click();
// select 22 February at 8:23:33
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
@@ -2659,6 +2733,32 @@ QUnit.module('basic_fields', {
form.destroy();
});
QUnit.test('datepicker option: daysOfWeekDisabled', function (assert) {
assert.expect(2);
this.data.partner.fields.datetime.default = "2017-08-02 12:00:05";
this.data.partner.fields.datetime.required = true;
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch:'<form string="Partners">' +
'<field name="datetime" ' +
'options=\'{"datepicker": {"daysOfWeekDisabled": [0, 6]}}\'/>' +
'</form>',
res_id: 1,
});
form.$buttons.find('.o_form_button_create').click();
assert.ok($('.day:last-child(),.day:nth-child(2)').hasClass('disabled'),
'first and last days must be disabled');
assert.notOk($('.day:not(:last-child()):not(:nth-child(2))').hasClass('disabled'),
'other days must stay clickable');
form.destroy();
});
QUnit.module('FieldMonetary');
QUnit.test('monetary field in form view', function (assert) {