summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/fields
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web/static/tests/fields')
-rw-r--r--addons/web/static/tests/fields/basic_fields_tests.js34
-rw-r--r--addons/web/static/tests/fields/field_utils_tests.js9
2 files changed, 43 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 9ea423250e4..a2f59a68e2a 100644
--- a/addons/web/static/tests/fields/basic_fields_tests.js
+++ b/addons/web/static/tests/fields/basic_fields_tests.js
@@ -1481,6 +1481,40 @@ QUnit.module('basic_fields', {
session.get_file = oldGetFile;
});
+ QUnit.test('download_link widget in list view', function (assert) {
+ assert.expect(5);
+
+ this.data.partner.fields.filename = { string: "Filename", type: "char" };
+ this.data.partner.records[0].filename = "document.txt";
+
+ var form = createView({
+ View: ListView,
+ model: 'partner',
+ data: this.data,
+ arch: '<tree string="Partners">' +
+ '<field name="document" widget="download_link" options="{\'filename\': \'filename\'}"/>' +
+ '<field name="filename"/>' +
+ '</tree>',
+ res_id: 1,
+ });
+
+ assert.ok(form.$('.o_data_cell').first().hasClass("o_download_link_cell"),
+ "this should be a download link cell");
+ assert.ok(form.$('.o_data_cell').first().find('a').eq(0),
+ "there should be a link in the cell");
+ assert.strictEqual(form.$('.o_data_cell').first().find('a').eq(0).attr('download'),
+ "document.txt",
+ "it should download a file named 'document.txt'");
+ assert.strictEqual(form.$('.o_data_cell').first().find('a').eq(0).attr('href').trim(),
+ "data:application/octet-stream;base64,coucou==",
+ "it should have the appropriate link of a binary");
+ assert.strictEqual(form.$('.o_data_cell').first().find('a').eq(0).text(),
+ "Download",
+ "the text of the link should be 'Download'");
+
+ form.destroy();
+ });
+
QUnit.test('text field rendering in list view', function (assert) {
assert.expect(1);
diff --git a/addons/web/static/tests/fields/field_utils_tests.js b/addons/web/static/tests/fields/field_utils_tests.js
index 1f8c27e7192..e24571ea1d8 100644
--- a/addons/web/static/tests/fields/field_utils_tests.js
+++ b/addons/web/static/tests/fields/field_utils_tests.js
@@ -127,6 +127,15 @@ QUnit.test('format one2many', function(assert) {
assert.strictEqual(fieldUtils.format.one2many({data: [1, 2]}), '2 records');
});
+QUnit.test('format binary', function (assert) {
+ assert.expect(1);
+
+ // base64 estimated size (bytes) = value.length / 1.37 (http://en.wikipedia.org/wiki/Base64#MIME)
+ // Here: 4 / 1.37 = 2.91970800 => 2.92 (rounded 2 decimals by utils.human_size)
+ assert.strictEqual(fieldUtils.format.binary('Cg=='), '2.92 Bytes');
+
+});
+
QUnit.test('parse float', function(assert) {
assert.expect(10);