diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/web/static/tests/components/custom_file_input_tests.js | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
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.js | 90 |
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(); + }); + }); +}); |
