diff options
| author | Xavier Dubuc <xdu@odoo.com> | 2020-08-04 14:38:02 +0000 |
|---|---|---|
| committer | Sébastien Theys <seb@odoo.com> | 2020-08-13 10:23:25 +0000 |
| commit | a17725e99899ff1e06996f7c9ab93704c840131e (patch) | |
| tree | b82159288fd50294aeb28f17ac260a59c48cc736 /addons/web/static/tests/helpers/test_utils_file.js | |
| parent | b0107e9230da5cb5c90819e5bee3e9cd323816ee (diff) | |
[FIX] mail: fix full composer opening with attachments
task-2307201
closes odoo/odoo#55678
X-original-commit: 9c47bb0b0034a3419a0c6e3267d90cb520a59535
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
Diffstat (limited to 'addons/web/static/tests/helpers/test_utils_file.js')
| -rw-r--r-- | addons/web/static/tests/helpers/test_utils_file.js | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/addons/web/static/tests/helpers/test_utils_file.js b/addons/web/static/tests/helpers/test_utils_file.js index df577347bb0..ecdd85e52d6 100644 --- a/addons/web/static/tests/helpers/test_utils_file.js +++ b/addons/web/static/tests/helpers/test_utils_file.js @@ -29,7 +29,7 @@ function _createFakeDataTransfer(files) { effectAllowed: 'all', files, getData: function () { - return file; + return files; }, items: [], types: ['Files'], @@ -115,6 +115,34 @@ function dropFiles($el, files) { $el[0].dispatchEvent(ev); } +/** + * Set files in a file input + * + * @param {DOM.Element} el + * @param {Object[]} files must have been created beforehand + * @see testUtils.file.createFile + */ +function inputFiles(el, files) { + // could not use _createFakeDataTransfer as el.files assignation will only + // work with a real FileList object. + const dataTransfer = new window.DataTransfer(); + for (const file of files) { + dataTransfer.items.add(file); + } + el.files = dataTransfer.files; + /** + * Changing files programatically is not supposed to trigger the event but + * it does in Chrome versions before 73 (which is on runbot), so in that + * case there is no need to make a manual dispatch, because it would lead to + * the files being added twice. + */ + const versionRaw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./); + const chromeVersion = versionRaw ? parseInt(versionRaw[2], 10) : false; + if (!chromeVersion || chromeVersion >= 73) { + el.dispatchEvent(new Event('change')); + } +} + //------------------------------------------------------------------------------ // Exposed API //------------------------------------------------------------------------------ @@ -124,6 +152,7 @@ return { dragoverFile: dragoverFile, dropFile: dropFile, dropFiles, + inputFiles, }; }); |
