diff options
Diffstat (limited to 'addons/web/static/tests/fields/basic_fields_tests.js')
| -rw-r--r-- | addons/web/static/tests/fields/basic_fields_tests.js | 138 |
1 files changed, 89 insertions, 49 deletions
diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index 08b7826b4c8..f2a49cbc387 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -1595,6 +1595,64 @@ QUnit.module('basic_fields', { session.get_file = oldGetFile; }); + QUnit.module('FieldPdfViewer'); + + QUnit.test("pdf_viewer without data", function (assert) { + assert.expect(4); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: + '<form>' + + '<field name="document" widget="pdf_viewer"/>' + + '</form>', + }); + + assert.ok(form.$('.o_field_widget').hasClass('o_field_pdfviewer')); + assert.strictEqual(form.$('.o_select_file_button:not(.o_hidden)').length, 1, + "there should be a visible 'Upload' button"); + assert.ok(form.$('.o_field_widget iframe.o_pdfview_iframe').hasClass('o_hidden'), + "there should be an invisible iframe"); + assert.strictEqual(form.$('input[type="file"]').length, 1, + "there should be one input"); + + form.destroy(); + }); + + QUnit.test("pdf_viewer: basic rendering", function (assert) { + assert.expect(4); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + res_id: 1, + arch: + '<form>' + + '<field name="document" widget="pdf_viewer"/>' + + '</form>', + mockRPC: function (route) { + if (route.indexOf('/web/static/lib/pdfjs/web/viewer.html') !== -1) { + return $.when(); + } + return this._super.apply(this, arguments); + } + }); + + assert.ok(form.$('.o_field_widget').hasClass('o_field_pdfviewer')); + assert.strictEqual(form.$('.o_select_file_button:not(.o_hidden)').length, 0, + "there should not be a any visible 'Upload' button"); + assert.notOk(form.$('.o_field_widget iframe.o_pdfview_iframe').hasClass('o_hidden'), + "there should be an visible iframe"); + assert.strictEqual(form.$('.o_field_widget iframe.o_pdfview_iframe').attr('data-src'), + '/web/static/lib/pdfjs/web/viewer.html?file=%2Fweb%2Fimage%3Fmodel%3Dpartner%26field%3Ddocument%26id%3D1#page=1', + "the src attribute should be correctly set on the iframe"); + + form.destroy(); + }); + QUnit.test('text field rendering in list view', function (assert) { assert.expect(1); @@ -1702,7 +1760,7 @@ QUnit.module('basic_fields', { QUnit.module('FieldImage'); QUnit.test('image fields are correctly rendered', function (assert) { - assert.expect(6); + assert.expect(7); this.data.partner.records[0].__last_update = '2017-02-08 10:00:00'; this.data.partner.records[0].document = 'myimage'; @@ -1735,11 +1793,13 @@ QUnit.module('basic_fields', { "the image should have the correct class"); assert.strictEqual(form.$('div[name="document"] > img').attr('width'), "90", "the image should correctly set its attributes"); + assert.strictEqual(form.$('div[name="document"] > img').css('max-width'), "90px", + "the image should correctly set its attributes"); form.destroy(); }); QUnit.test('image fields in subviews are loaded correctly', function (assert) { - assert.expect(5); + assert.expect(6); this.data.partner.records[0].__last_update = '2017-02-08 10:00:00'; this.data.partner.records[0].document = 'myimage'; @@ -1768,6 +1828,10 @@ QUnit.module('basic_fields', { assert.step("The view's image should have been fetched"); return $.when('wow'); } + if (route === 'data:image/png;base64,product_image') { + assert.step("The dialog's image should have been fetched"); + return $.when(); + } return this._super.apply(this, arguments); }, }); @@ -1780,9 +1844,10 @@ QUnit.module('basic_fields', { form.$('tbody td:contains(gold)').click(); assert.strictEqual($('.modal-dialog').length, 1, 'The modal should have opened'); - assert.strictEqual($('.modal-dialog').find('.o_field_image > img')[0].src, - 'data:image/png;base64,product_image', - 'The image of the many2many in its form view should be present'); + assert.verifySteps([ + "The view's image should have been fetched", + "The dialog's image should have been fetched", + ]); form.destroy(); }); @@ -3107,7 +3172,7 @@ QUnit.module('basic_fields', { QUnit.module('PhoneWidget'); QUnit.test('phone field in form view on extra small screens', function (assert) { - assert.expect(8); + assert.expect(7); var form = createView({ View: FormView, @@ -3131,8 +3196,8 @@ QUnit.module('basic_fields', { var $phoneLink = form.$('a.o_form_uri.o_field_widget'); assert.strictEqual($phoneLink.length, 1, "should have a anchor with correct classes"); - assert.strictEqual($phoneLink.text(), 'y\u00ADop', - "value should be displayed properly as text with the skype obfuscation"); + assert.strictEqual($phoneLink.text(), 'yop', + "value should be displayed properly"); assert.strictEqual($phoneLink.attr('href'), 'tel:yop', "should have proper tel prefix"); @@ -3149,20 +3214,11 @@ QUnit.module('basic_fields', { // save form.$buttons.find('.o_form_button_save').click(); $phoneLink = form.$('a.o_form_uri.o_field_widget'); - assert.strictEqual($phoneLink.text(), 'n\u00ADew', - "new value should be displayed properly as text with the skype obfuscation"); + assert.strictEqual($phoneLink.text(), 'new', + "new value should be displayed properly"); assert.strictEqual($phoneLink.attr('href'), 'tel:new', "should still have proper tel prefix"); - // NOT NEEDED AS OF SAAS-11.3 - // save phone with ­ and verify it is removed - form.$buttons.find('.o_form_button_edit').click(); - form.$('input[type="text"].o_field_widget').val('h\u00ADi').trigger('input'); - form.$buttons.find('.o_form_button_save').click(); - $phoneLink = form.$('a.o_form_uri.o_field_widget'); - assert.strictEqual($phoneLink.attr('href'), 'tel:hi', - "U+00AD should have been removed"); - form.destroy(); }); @@ -3183,8 +3239,8 @@ QUnit.module('basic_fields', { assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').length, 5, "should have 5 cells"); - assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'y\u00ADop', - "value should be displayed properly as text with the skype obfuscation"); + assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'yop', + "value should be displayed properly"); var $phoneLink = list.$('a.o_form_uri.o_field_widget'); assert.strictEqual($phoneLink.length, 5, @@ -3204,7 +3260,7 @@ QUnit.module('basic_fields', { list.$buttons.find('.o_list_button_save').click(); $cell = list.$('tbody td:not(.o_list_record_selector)').first(); assert.ok(!$cell.parent().hasClass('o_selected_row'), 'should not be in edit mode anymore'); - assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'n\u00ADew', + assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'new', "value should be properly updated"); $phoneLink = list.$('a.o_form_uri.o_field_widget'); assert.strictEqual($phoneLink.length, 5, @@ -3216,14 +3272,6 @@ QUnit.module('basic_fields', { }); QUnit.test('phone field in form view on normal screens', function (assert) { - // The behavior of this widget is completely altered by voip so this - // test is irrelevant and fails if voip is installed. The enterprise - // module is responsible for testing its own behavior in its own tests. - if ('voip.user_agent' in odoo.__DEBUG__.services) { - assert.expect(0); - return; - } - assert.expect(5); var form = createView({ @@ -3245,11 +3293,11 @@ QUnit.module('basic_fields', { }, }); - var $phone = form.$('span.o_field_widget:not(.o_form_uri)'); + var $phone = form.$('a.o_field_widget.o_form_uri'); assert.strictEqual($phone.length, 1, - "should have a simple span rather than a link"); + "should have rendered the phone number as a link with correct classes"); assert.strictEqual($phone.text(), 'yop', - "value should be displayed properly as text without skype obfuscation"); + "value should be displayed properly"); // switch to edit mode and check the result form.$buttons.find('.o_form_button_edit').click(); @@ -3263,21 +3311,13 @@ QUnit.module('basic_fields', { // save form.$buttons.find('.o_form_button_save').click(); - assert.strictEqual(form.$('span.o_field_widget:not(.o_form_uri)').text(), 'new', - "new value should be displayed properly as text without skype obfuscation"); + assert.strictEqual(form.$('a.o_field_widget.o_form_uri').text(), 'new', + "new value should be displayed properly"); form.destroy(); }); QUnit.test('phone field in editable list view on normal screens', function (assert) { - // The behavior of this widget is completely altered by voip so this - // test is irrelevant and fails if voip is installed. The enterprise - // module is responsible for testing its own behavior in its own tests. - if ('voip.user_agent' in odoo.__DEBUG__.services) { - assert.expect(0); - return; - } - assert.expect(8); var list = createView({ @@ -3295,10 +3335,10 @@ QUnit.module('basic_fields', { assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').length, 5, "should have 5 cells"); assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'yop', - "value should be displayed properly as text without skype obfuscation"); + "value should be displayed properly"); - assert.strictEqual(list.$('span.o_field_widget:not(.o_form_uri)').length, 5, - "should have spans with correct classes"); + assert.strictEqual(list.$('a.o_field_widget.o_form_uri').length, 5, + "should have the correct classnames"); // Edit a line and check the result var $cell = list.$('tbody td:not(.o_list_record_selector)').first(); @@ -3314,8 +3354,8 @@ QUnit.module('basic_fields', { assert.ok(!$cell.parent().hasClass('o_selected_row'), 'should not be in edit mode anymore'); assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'new', "value should be properly updated"); - assert.strictEqual(list.$('span.o_field_widget:not(.o_form_uri)').length, 5, - "should still have spans with correct classes"); + assert.strictEqual(list.$('a.o_field_widget.o_form_uri').length, 5, + "should still have links with correct classes"); list.destroy(); }); @@ -3350,7 +3390,7 @@ QUnit.module('basic_fields', { // save form.$buttons.find('.o_form_button_save').click(); - assert.strictEqual(form.$('.o_field_widget').text().split('\u00AD').join(''), val, + assert.strictEqual(form.$('.o_field_widget').text(), val, "value should have been correctly escaped"); form.destroy(); |
