From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- .../web/static/tests/helpers/test_utils_kanban.js | 102 +++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 addons/web/static/tests/helpers/test_utils_kanban.js (limited to 'addons/web/static/tests/helpers/test_utils_kanban.js') diff --git a/addons/web/static/tests/helpers/test_utils_kanban.js b/addons/web/static/tests/helpers/test_utils_kanban.js new file mode 100644 index 00000000..76af632b --- /dev/null +++ b/addons/web/static/tests/helpers/test_utils_kanban.js @@ -0,0 +1,102 @@ +odoo.define('web.test_utils_kanban', function (require) { +"use strict"; + +/** + * Kanban Test Utils + * + * This module defines various utility functions to help testing kanban views. + * + * Note that all methods defined in this module are exported in the main + * testUtils file. + */ + +var testUtilsDom = require('web.test_utils_dom'); +var testUtilsFields = require('web.test_utils_fields'); + +/** + * Clicks on the Create button in a kanban view. Note that this method checks that + * the Create button is visible. + * + * @param {KanbanController} kanban + * @returns {Promise} + */ +function clickCreate(kanban) { + return testUtilsDom.click(kanban.$buttons.find('.o-kanban-button-new')); +} + +/** + * Open the settings menu for a column (in a grouped kanban view) + * + * @param {jQuery} $column + * @returns {Promise} + */ +function toggleGroupSettings($column) { + var $dropdownToggler = $column.find('.o_kanban_config > a.dropdown-toggle'); + if (!$dropdownToggler.is(':visible')) { + $dropdownToggler.css('display', 'block'); + } + return testUtilsDom.click($dropdownToggler); +} + +/** + * Edit a value in a quickcreate form view (this method assumes that the quick + * create feature is active, and a sub form view is open) + * + * @param {kanbanController} kanban + * @param {string|number} value + * @param {[string]} fieldName + * @returns {Promise} + */ +function quickCreate(kanban, value, fieldName) { + var additionalSelector = fieldName ? ('[name=' + fieldName + ']'): ''; + var enterEvent = $.Event( + 'keydown', + { + which: $.ui.keyCode.ENTER, + keyCode: $.ui.keyCode.ENTER, + } + ); + return testUtilsFields.editAndTrigger( + kanban.$('.o_kanban_quick_create input' + additionalSelector), + value, + ['input', enterEvent] + ); +} + +/** + * Reloads a kanban view. + * + * @param {KanbanController} kanban + * @param {[Object]} params given to the controller reload method + * @returns {Promise} + */ +function reload(kanban, params) { + return kanban.reload(params); +} + +/** + * Open the setting dropdown of a kanban record. Note that the template of a + * kanban record is not standardized, so this method will fail if the template + * does not comply with the usual dom structure. + * + * @param {jQuery} $record + * @returns {Promise} + */ +function toggleRecordDropdown($record) { + var $dropdownToggler = $record.find('.o_dropdown_kanban > a.dropdown-toggle'); + if (!$dropdownToggler.is(':visible')) { + $dropdownToggler.css('display', 'block'); + } + return testUtilsDom.click($dropdownToggler); +} + + +return { + clickCreate: clickCreate, + quickCreate: quickCreate, + reload: reload, + toggleGroupSettings: toggleGroupSettings, + toggleRecordDropdown: toggleRecordDropdown, +}; + +}); -- cgit v1.2.3