flectra.define('web.basic_fields_tests', function (require) { "use strict"; var basicFields = require('web.basic_fields'); var concurrency = require('web.concurrency'); var core = require('web.core'); var FormView = require('web.FormView'); var KanbanView = require('web.KanbanView'); var ListView = require('web.ListView'); var session = require('web.session'); var testUtils = require('web.test_utils'); var createView = testUtils.createView; var DebouncedField = basicFields.DebouncedField; var _t = core._t; QUnit.module('fields', {}, function () { QUnit.module('basic_fields', { beforeEach: function () { this.data = { partner: { fields: { date: {string: "A date", type: "date", searchable: true}, datetime: {string: "A datetime", type: "datetime", searchable: true}, display_name: {string: "Displayed name", type: "char", searchable: true}, foo: {string: "Foo", type: "char", default: "My little Foo Value", searchable: true}, bar: {string: "Bar", type: "boolean", default: true, searchable: true}, txt: {string: "txt", type: "text", default: "My little txt Value\nHo-ho-hoooo Merry Christmas"}, int_field: {string: "int_field", type: "integer", sortable: true, searchable: true}, qux: {string: "Qux", type: "float", digits: [16,1], searchable: true}, p: {string: "one2many field", type: "one2many", relation: 'partner', searchable: true}, trululu: {string: "Trululu", type: "many2one", relation: 'partner', searchable: true}, timmy: {string: "pokemon", type: "many2many", relation: 'partner_type', searchable: true}, product_id: {string: "Product", type: "many2one", relation: 'product', searchable: true}, sequence: {type: "integer", string: "Sequence", searchable: true}, currency_id: {string: "Currency", type: "many2one", relation: "currency", searchable: true}, selection: {string: "Selection", type: "selection", searchable:true, selection: [['normal', 'Normal'],['blocked', 'Blocked'],['done', 'Done']]}, document: {string: "Binary", type: "binary"}, image_selection: {string: "Image Selection", type: "selection", searchable:true, selection: [['background', 'Background'],['boxed', 'Boxed'],['clean', 'Clean'],['standard', 'Standard']]}, }, records: [{ id: 1, date: "2017-02-03", datetime: "2017-02-08 10:00:00", display_name: "first record", bar: true, foo: "yop", int_field: 10, qux: 0.44444, p: [], timmy: [], trululu: 4, selection: 'blocked', document: 'coucou==\n', }, { id: 2, display_name: "second record", bar: true, foo: "blip", int_field: 0, qux: 0, p: [], timmy: [], trululu: 1, sequence: 4, currency_id: 2, selection: 'normal', }, { id: 4, display_name: "aaa", foo: "abc", sequence: 9, int_field: false, qux: false, selection: 'done', }, {id: 3, bar: true, foo: "gnap", int_field: 80, qux: -3.89859, m2o: 1, m2m: []}, {id: 5, bar: false, foo: "blop", int_field: -4, qux: 9.1, m2o: 1, m2m: [1], currency_id: 1}], onchanges: {}, }, product: { fields: { name: {string: "Product Name", type: "char", searchable: true} }, records: [{ id: 37, display_name: "xphone", }, { id: 41, display_name: "xpad", }] }, partner_type: { fields: { name: {string: "Partner Type", type: "char", searchable: true}, color: {string: "Color index", type: "integer", searchable: true}, }, records: [ {id: 12, display_name: "gold", color: 2}, {id: 14, display_name: "silver", color: 5}, ] }, currency: { fields: { symbol: {string: "Currency Sumbol", type: "char", searchable: true}, position: {string: "Currency Position", type: "char", searchable: true}, }, records: [{ id: 1, display_name: "$", symbol: "$", position: "before", }, { id: 2, display_name: "€", symbol: "€", position: "after", }] }, }; } }, function () { QUnit.module('DebouncedField'); QUnit.test('debounced fields do not trigger call _setValue once destroyed', function (assert) { var done = assert.async(); assert.expect(4); var def = $.Deferred(); var _doAction = DebouncedField.prototype._doAction; DebouncedField.prototype._doAction = function () { _doAction.apply(this, arguments); def.resolve(); }; var _setValue = DebouncedField.prototype._setValue; DebouncedField.prototype._setValue = function () { assert.step('_setValue'); _setValue.apply(this, arguments); }; var form = createView({ View: FormView, model: 'partner', data: this.data, arch: '
' + '' + '' + '' + '' + '' + '
', res_id: 1, fieldDebounce: 3, viewOptions: { mode: 'edit', }, }); // change the value form.$('input').val('new value').trigger('input'); assert.verifySteps([], "_setValue shouldn't have been called yet"); // save form.$buttons.find('.o_form_button_save').click(); assert.verifySteps(['_setValue'], "_setValue should have been called once"); // destroy the form view def = $.Deferred(); form.destroy(); // wait for the debounced callback to be called def.then(function () { assert.verifySteps(['_setValue'], "_setValue should not have been called after widget destruction"); DebouncedField.prototype._doAction = _doAction; DebouncedField.prototype._setValue = _setValue; done(); }); }); QUnit.module('FieldBoolean'); QUnit.test('boolean field in form view', function (assert) { assert.expect(12); var form = createView({ View: FormView, model: 'partner', data: this.data, arch: '