summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/fields/basic_fields_tests.js
diff options
context:
space:
mode:
authorJulien Mougenot <jum@odoo.com>2020-03-11 09:38:30 +0000
committerJulien Mougenot <jum@odoo.com>2020-03-13 14:08:33 +0000
commit804507ef4925cafdf5349a3b7fa1e41dbca87ff7 (patch)
tree09a097ffb347dae1c9dc7879be261ec734f70d4f /addons/web/static/tests/fields/basic_fields_tests.js
parentbb8eb766a84b9fd06007d3fb4ab9a29b70097738 (diff)
[REF] *: Adapt all module tests to the new control panel
Use of the new control panel helpers to increase consistency and change the assertions according to the new DOM/behaviour (e.g. components removed instead of turning invisible). Part of task 2196029 Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Diffstat (limited to 'addons/web/static/tests/fields/basic_fields_tests.js')
-rw-r--r--addons/web/static/tests/fields/basic_fields_tests.js91
1 files changed, 74 insertions, 17 deletions
diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js
index ada71b91429..eaa41651c20 100644
--- a/addons/web/static/tests/fields/basic_fields_tests.js
+++ b/addons/web/static/tests/fields/basic_fields_tests.js
@@ -19,6 +19,10 @@ var DebouncedField = basicFields.DebouncedField;
var JournalDashboardGraph = basicFields.JournalDashboardGraph;
var _t = core._t;
+// Base64 images for testing purpose
+const MY_IMAGE = 'iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==';
+const PRODUCT_IMAGE = 'R0lGODlhDAAMAKIFAF5LAP/zxAAAANyuAP/gaP///wAAAAAAACH5BAEAAAUALAAAAAAMAAwAAAMlWLPcGjDKFYi9lxKBOaGcF35DhWHamZUW0K4mAbiwWtuf0uxFAgA7';
+
QUnit.module('fields', {}, function () {
QUnit.module('basic_fields', {
@@ -2516,7 +2520,7 @@ QUnit.module('basic_fields', {
assert.expect(7);
this.data.partner.records[0].__last_update = '2017-02-08 10:00:00';
- this.data.partner.records[0].document = 'myimage';
+ this.data.partner.records[0].document = MY_IMAGE;
var form = await createView({
View: FormView,
@@ -2526,13 +2530,13 @@ QUnit.module('basic_fields', {
'<field name="document" widget="image" options="{\'size\': [90, 90]}"/> ' +
'</form>',
res_id: 1,
- mockRPC: function (route, args) {
+ async mockRPC(route, args) {
if (route === '/web/dataset/call_kw/partner/read') {
assert.deepEqual(args.args[1], ['document', '__last_update', 'display_name'], "The fields document, display_name and __last_update should be present when reading an image");
}
- if (route === 'data:image/png;base64,myimage') {
+ if (route === `data:image/png;base64,${MY_IMAGE}`) {
assert.ok(true, "should called the correct route");
- return Promise.resolve('wow');
+ return 'wow';
}
return this._super.apply(this, arguments);
},
@@ -2551,6 +2555,59 @@ QUnit.module('basic_fields', {
form.destroy();
});
+ QUnit.test('image fields are correctly replaced when given an incorrect value', async function (assert) {
+ assert.expect(7);
+
+ this.data.partner.records[0].__last_update = '2017-02-08 10:00:00';
+ this.data.partner.records[0].document = 'incorrect_base64_value';
+
+ testUtils.mock.patch(basicFields.FieldBinaryImage, {
+ // Delay the _render function: this will ensure that the error triggered
+ // by the incorrect base64 value is dispatched before the src is replaced
+ // (see test_utils_mock.removeSrcAttribute), since that function is called
+ // when the element is inserted into the DOM.
+ async _render() {
+ const result = this._super.apply(this, arguments);
+ await concurrency.delay(100);
+ return result;
+ },
+ });
+
+ const form = await createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: `
+ <form string="Partners">
+ <field name="document" widget="image" options="{'size': [90, 90]}"/>
+ </form>`,
+ res_id: 1,
+ async mockRPC(route, args) {
+ const _super = this._super;
+ if (route === '/web/static/src/img/placeholder.png') {
+ assert.step('call placeholder route');
+ }
+ return _super.apply(this, arguments);
+ },
+ });
+
+ assert.hasClass(form.$('div[name="document"]'),'o_field_image',
+ "the widget should have the correct class");
+ assert.containsOnce(form, 'div[name="document"] > img',
+ "the widget should contain an image");
+ assert.hasClass(form.$('div[name="document"] > img'), 'img-fluid',
+ "the image should have the correct class");
+ assert.hasAttrValue(form.$('div[name="document"] > img'), '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");
+
+ assert.verifySteps(['call placeholder route']);
+
+ form.destroy();
+ testUtils.mock.unpatch(basicFields.FieldBinaryImage);
+ });
+
QUnit.test('image: option accepted_file_extensions', async function (assert) {
assert.expect(2);
@@ -2583,9 +2640,9 @@ QUnit.module('basic_fields', {
assert.expect(6);
this.data.partner.records[0].__last_update = '2017-02-08 10:00:00';
- this.data.partner.records[0].document = 'myimage';
+ this.data.partner.records[0].document = MY_IMAGE;
this.data.partner_type.fields.image = {name: 'image', type: 'binary'};
- this.data.partner_type.records[0].image = 'product_image';
+ this.data.partner_type.records[0].image = PRODUCT_IMAGE;
this.data.partner.records[0].timmy = [12];
var form = await createView({
@@ -2604,14 +2661,14 @@ QUnit.module('basic_fields', {
'</field>' +
'</form>',
res_id: 1,
- mockRPC: function (route) {
- if (route === 'data:image/png;base64,myimage') {
+ async mockRPC(route) {
+ if (route === `data:image/png;base64,${MY_IMAGE}`) {
assert.step("The view's image should have been fetched");
- return Promise.resolve('wow');
+ return 'wow';
}
- if (route === 'data:image/png;base64,product_image') {
+ if (route === `data:image/gif;base64,${PRODUCT_IMAGE}`) {
assert.step("The dialog's image should have been fetched");
- return Promise.resolve();
+ return;
}
return this._super.apply(this, arguments);
},
@@ -2634,7 +2691,7 @@ QUnit.module('basic_fields', {
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_type.records[0].image = PRODUCT_IMAGE;
this.data.partner.records[0].timmy = [12];
var form = await createView({
@@ -2649,10 +2706,10 @@ QUnit.module('basic_fields', {
'</field>' +
'</form>',
res_id: 1,
- mockRPC: function (route) {
- if (route === 'data:image/png;base64,product_image') {
+ async mockRPC(route) {
+ if (route === `data:image/gif;base64,${PRODUCT_IMAGE}`) {
assert.ok(true, "The list's image should have been fetched");
- return Promise.resolve();
+ return;
}
return this._super.apply(this, arguments);
},
@@ -2961,7 +3018,7 @@ QUnit.module('basic_fields', {
QUnit.module('FieldDateRange');
- QUnit.test('Datetime field', async function (assert) {
+ QUnit.test('Datetime field [REQUIRE FOCUS]', async function (assert) {
assert.expect(20);
this.data.partner.fields.datetime_end = {string: 'Datetime End', type: 'datetime'};
@@ -3039,7 +3096,7 @@ QUnit.module('basic_fields', {
form.destroy();
});
- QUnit.test('Date field', async function (assert) {
+ QUnit.test('Date field [REQUIRE FOCUS]', async function (assert) {
assert.expect(18);
this.data.partner.fields.date_end = {string: 'Date End', type: 'date'};