diff options
| author | Martin Geubelle <mge@odoo.com> | 2017-04-25 16:09:03 +0200 |
|---|---|---|
| committer | Martin Geubelle <mge@odoo.com> | 2017-04-27 16:56:46 +0200 |
| commit | 776cd64aa357134c46e9a1376b45147bb1a4886a (patch) | |
| tree | 8bbcefb13d6f47782d3467ba33c149c76ffe7623 /addons/web/static/tests/fields/basic_fields_tests.js | |
| parent | 0b3b34ae4c0a721bb3a463b457caa74f124cd350 (diff) | |
[FIX] web: BasicField: use `getSession`
`session` is not an field widget attribute anymore.
One should use `getSession` instead.
This commit also introduces tests for the `binary` field.
Diffstat (limited to 'addons/web/static/tests/fields/basic_fields_tests.js')
| -rw-r--r-- | addons/web/static/tests/fields/basic_fields_tests.js | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index c4884658508..7ac38cad25f 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -5,6 +5,7 @@ var concurrency = require('web.concurrency'); 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; @@ -31,6 +32,7 @@ QUnit.module('basic_fields', { 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"}, }, records: [{ id: 1, @@ -45,6 +47,7 @@ QUnit.module('basic_fields', { timmy: [], trululu: 4, selection: 'blocked', + document: 'coucou==\n', }, { id: 2, display_name: "second record", @@ -755,6 +758,61 @@ QUnit.module('basic_fields', { form.destroy(); }); + QUnit.module('FieldBinary'); + + QUnit.test('binary fields are correctly rendered', function (assert) { + assert.expect(9); + + // save the session function + var oldGetFile = session.get_file; + session.get_file = function (option) { + assert.strictEqual(option.data.field, 'document', + "we should download the field document"); + assert.strictEqual(option.data.data, 'coucou==\n', + "we should download the correct data"); + option.complete(); + return $.when(); + }; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form string="Partners">' + + '<field name="document"/>' + + '</form>', + res_id: 1, + }); + + assert.strictEqual(form.$('a.o_form_field[name="document"] > .fa-download').length, 1, + "the binary field should be rendered as a downloadable link in readonly"); + + form.$('a.o_form_field[name="document"]').click(); + + form.$buttons.find('.o_form_button_edit').click(); + + assert.strictEqual(form.$('a.o_form_field[name="document"] > .fa-download').length, 0, + "the binary field should not be rendered as a downloadable link in edit"); + assert.strictEqual(form.$('div.o_form_field_binary_file[name="document"]').length, 1, + "the binary field should be correctly rendered in edit"); + assert.strictEqual(form.$('.o_form_field_binary_file > input').attr('readonly'), 'readonly', + "the input should be readonly"); + assert.strictEqual(form.$('.o_form_field_binary_file > .o_clear_file_button').length, 1, + "there shoud be a button to clear the file"); + + form.$('.o_form_field_binary_file > .o_clear_file_button').click(); + + assert.ok(form.$('.o_form_field_binary_file > input').hasClass('o_hidden'), + "the input should be hidden"); + assert.strictEqual(form.$('.o_form_field_binary_file > .o_select_file_button:not(.o_hidden)').length, 1, + "there shoud be a button to upload the file"); + + form.destroy(); + + // restore the session function + session.get_file = oldGetFile; + }); + QUnit.test('text field rendering in list view', function (assert) { assert.expect(1); |
