summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/components/custom_file_input_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/components/custom_file_input_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/components/custom_file_input_tests.js')
-rw-r--r--addons/web/static/tests/components/custom_file_input_tests.js141
1 files changed, 64 insertions, 77 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
index 0131213f6e9..279bf67f11b 100644
--- a/addons/web/static/tests/components/custom_file_input_tests.js
+++ b/addons/web/static/tests/components/custom_file_input_tests.js
@@ -2,102 +2,89 @@ odoo.define('web.custom_file_input_tests', function (require) {
"use strict";
const CustomFileInput = require('web.CustomFileInput');
- const makeTestEnvironment = require('web.test_env');
const testUtils = require('web.test_utils');
- const { Component, tags, useState } = owl;
- const { xml } = tags;
+ 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', {}, function () {
- QUnit.test("Rendering of all props", async function (assert) {
- assert.expect(12);
-
- class Parent extends Component {
- constructor() {
- super(...arguments);
- this.state = useState({ innerContent: '<a href="#">Trigger</a>' });
- }
- // Handlers
- _onFileUploaded(ev) {
- assert.strictEqual(ev.detail.files.length, 0,
- "'files' property should be an empty array");
- }
- }
- Parent.components = { CustomFileInput };
- Parent.env = makeTestEnvironment({
+ 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: {
- httpRequest: (route, params) => {
- if (route === '/web/binary/upload') {
- assert.deepEqual(params, {
- csrf_token: odoo.csrf_token,
- ufile: [],
- });
- assert.step(route);
- return Promise.resolve('[]');
- } else if (route === '/web/binary/upload_attachment') {
- assert.deepEqual(params, {
- id: 5,
- model: 'res.model',
- csrf_token: odoo.csrf_token,
- ufile: [],
- });
- assert.step(route);
- return Promise.resolve('[]');
- }
+ async httpRequest(route, params) {
+ assert.deepEqual(params, {
+ id: 5,
+ model: 'res.model',
+ csrf_token: odoo.csrf_token,
+ ufile: [],
+ });
+ assert.step(route);
+ return '[]';
},
},
- });
- Parent.template = xml`
- <CustomFileInput
- accepted_file_extensions="state.accepted_file_extensions"
- action="state.action"
- id="state.id"
- model="state.model"
- multi_upload="state.multi_upload"
- t-on-uploaded="_onFileUploaded"
- >
- <t t-raw="state.innerContent"/>
- </CustomFileInput>`;
-
- const parent = new Parent();
- await parent.mount(testUtils.prepareTarget());
- const fileInput = parent.el;
- const input = fileInput.querySelector('input');
-
- // Default props
- assert.strictEqual(fileInput.innerText.trim(), "Trigger",
- "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");
-
- // Change props
- Object.assign(parent.state, {
+ },
+ props: {
accepted_file_extensions: '.png',
action: '/web/binary/upload_attachment',
id: 5,
model: 'res.model',
multi_upload: true,
- });
- await testUtils.nextTick();
+ },
+ 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.strictEqual(input.accept, '.png', "Input should now only accept pngs");
- assert.verifySteps(['/web/binary/upload', '/web/binary/upload_attachment']);
+ await testUtils.dom.triggerEvent(input, 'change');
- parent.destroy();
- });
+ assert.ok(input.multiple, "'multiple' attribute should be set");
+ assert.verifySteps(['/web/binary/upload_attachment']);
+
+ customFileInput.destroy();
});
});
});