summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/components/custom_file_input_tests.js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web/static/tests/components/custom_file_input_tests.js')
-rw-r--r--addons/web/static/tests/components/custom_file_input_tests.js90
1 files changed, 90 insertions, 0 deletions
diff --git a/addons/web/static/tests/components/custom_file_input_tests.js b/addons/web/static/tests/components/custom_file_input_tests.js
new file mode 100644
index 00000000..279bf67f
--- /dev/null
+++ b/addons/web/static/tests/components/custom_file_input_tests.js
@@ -0,0 +1,90 @@
+odoo.define('web.custom_file_input_tests', function (require) {
+ "use strict";
+
+ const CustomFileInput = require('web.CustomFileInput');
+ const testUtils = require('web.test_utils');
+
+ const { createComponent } = testUtils;
+
+ QUnit.module('Components', {}, function () {
+
+ // This module cannot be tested as thoroughly as we want it to be:
+ // browsers do not let scripts programmatically assign values to inputs
+ // of type file
+ QUnit.module('CustomFileInput');
+
+ QUnit.test("Upload a file: default props", async function (assert) {
+ assert.expect(6);
+
+ const customFileInput = await createComponent(CustomFileInput, {
+ env: {
+ services: {
+ async httpRequest(route, params) {
+ assert.deepEqual(params, {
+ csrf_token: odoo.csrf_token,
+ ufile: [],
+ });
+ assert.step(route);
+ return '[]';
+ },
+ },
+ },
+ });
+ const input = customFileInput.el.querySelector('input');
+
+ assert.strictEqual(customFileInput.el.innerText.trim().toUpperCase(), "CHOOSE FILE",
+ "File input total text should match its given inner element's text");
+ assert.strictEqual(input.accept, '*',
+ "Input should accept all files by default");
+
+ await testUtils.dom.triggerEvent(input, 'change');
+
+ assert.notOk(input.multiple, "'multiple' attribute should not be set");
+ assert.verifySteps(['/web/binary/upload']);
+
+ customFileInput.destroy();
+ });
+
+ QUnit.test("Upload a file: custom attachment", async function (assert) {
+ assert.expect(6);
+
+ const customFileInput = await createComponent(CustomFileInput, {
+ env: {
+ services: {
+ async httpRequest(route, params) {
+ assert.deepEqual(params, {
+ id: 5,
+ model: 'res.model',
+ csrf_token: odoo.csrf_token,
+ ufile: [],
+ });
+ assert.step(route);
+ return '[]';
+ },
+ },
+ },
+ props: {
+ accepted_file_extensions: '.png',
+ action: '/web/binary/upload_attachment',
+ id: 5,
+ model: 'res.model',
+ multi_upload: true,
+ },
+ intercepts: {
+ 'uploaded': ev => assert.strictEqual(ev.detail.files.length, 0,
+ "'files' property should be an empty array"),
+ },
+ });
+ const input = customFileInput.el.querySelector('input');
+
+ assert.strictEqual(input.accept, '.png', "Input should now only accept pngs");
+
+ await testUtils.dom.triggerEvent(input, 'change');
+
+ assert.ok(input.multiple, "'multiple' attribute should be set");
+ assert.verifySteps(['/web/binary/upload_attachment']);
+
+ customFileInput.destroy();
+ });
+ });
+});