From 8b0aff12a53b8022cfbbb75f7d4c8afcaf9b7656 Mon Sep 17 00:00:00 2001 From: "Bastien (bvdn)" Date: Wed, 3 Jan 2024 17:35:04 +0100 Subject: [PATCH] [IMP] Project: add JS tests for widgets Added JS tests for the following widgets: - status_with_color (project.project, project.update) - name_with_subtask_count (project.task) - priority_switch (project.task) Task-3660956 closes odoo/odoo#148104 Signed-off-by: Xavier Bol (xbo) --- ...oject_status_with_color_selection_tests.js | 62 +++++++++++++++++++ .../project_subtask_kanban_list_form_tests.js | 5 +- .../project_task_priority_switch_tests.js | 51 +++++++++++++++ 3 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 addons/project/static/tests/project_status_with_color_selection_tests.js create mode 100644 addons/project/static/tests/project_task_priority_switch_tests.js diff --git a/addons/project/static/tests/project_status_with_color_selection_tests.js b/addons/project/static/tests/project_status_with_color_selection_tests.js new file mode 100644 index 00000000000..050292909db --- /dev/null +++ b/addons/project/static/tests/project_status_with_color_selection_tests.js @@ -0,0 +1,62 @@ +/** @odoo-module */ + +import { getFixture } from "@web/../tests/helpers/utils"; +import { makeView, setupViewRegistries } from "@web/../tests/views/helpers"; + +let makeViewParams, target; + +QUnit.module("Project", (hooks) => { + hooks.beforeEach(() => { + makeViewParams = { + type: "kanban", + resModel: "project.update", + serverData: { + models: { + "project.update": { + fields: { + id: {string: "Id", type: "integer"}, + status: { + string: "Status", + type: "selection", + selection: [ + ["on_track", "On Track"], + ["at_risk", "At Risk"], + ["off_track", "Off Track"], + ["on_hold", "On Hold"], + ["done", "Done"], + ], + }, + }, + records: [ + {id: 1, status: "on_track"}, + ], + }, + }, + }, + arch: ` + + + + + `, + }; + target = getFixture(); + setupViewRegistries(); + }); + QUnit.module("Components", (hooks) => { + QUnit.module("ProjectStatusWithColorSelection"); + QUnit.test("Check that ProjectStatusWithColorSelectionField is displaying the correct informations", async function (assert) { + await makeView(makeViewParams); + + assert.containsOnce(target, 'div[name="status"] .o_color_bubble_20', "In readonly a status bubble should be displayed") + assert.containsOnce(target, 'div[name="status"] .o_stat_text:contains("test status label")', "If the status_label prop has been set, its value should be displayed as well") + assert.containsOnce(target, 'div[name="status"] .o_stat_value:contains("On Track")', "The value of the selection should be displayed") + }); + }); +}); diff --git a/addons/project/static/tests/project_subtask_kanban_list_form_tests.js b/addons/project/static/tests/project_subtask_kanban_list_form_tests.js index f0b21b41a00..0d572b369ba 100644 --- a/addons/project/static/tests/project_subtask_kanban_list_form_tests.js +++ b/addons/project/static/tests/project_subtask_kanban_list_form_tests.js @@ -51,7 +51,7 @@ QUnit.module('Subtask Kanban List tests', {
- + @@ -79,7 +79,7 @@ QUnit.module('Subtask Kanban List tests', { } }, function () { QUnit.test("Check whether subtask list functionality works as intended", async function (assert) { - assert.expect(8); + assert.expect(9); const views = this.views; const { openView } = await start({ serverData: { views } }); @@ -88,6 +88,7 @@ QUnit.module('Subtask Kanban List tests', { views: [[false, "kanban"]], }); + assert.containsOnce(target, '.o_field_name_with_subtask_count:contains("(1/4 sub-tasks)")', "Task title should also display the number of (closed) sub-tasks linked to the task"); assert.containsOnce(target, '.subtask_list_button', "Only kanban boxes of parent tasks having open subtasks should have the drawdown button, in this case this is 1"); assert.containsNone(target, '.subtask_list', "If the drawdown button is not clicked, the subtasks list should be hidden"); diff --git a/addons/project/static/tests/project_task_priority_switch_tests.js b/addons/project/static/tests/project_task_priority_switch_tests.js new file mode 100644 index 00000000000..594293cad4b --- /dev/null +++ b/addons/project/static/tests/project_task_priority_switch_tests.js @@ -0,0 +1,51 @@ +/* @odoo-module */ + +import { getFixture, triggerHotkey } from "@web/../tests/helpers/utils"; +import { makeView, setupViewRegistries } from "@web/../tests/views/helpers"; + +let makeViewParams, target; + +QUnit.module("Project", (hooks) => { + hooks.beforeEach(() => { + makeViewParams = { + type: "form", + resModel: "project.task", + serverData: { + models: { + "project.task": { + fields: { + id: {string: "Id", type: "integer"}, + priority: { + string: "Priority", + type: "selection", + selection: [ + ["0", "Low"], + ["1", "High"], + ], + }, + }, + records: [ + { id: 1, priority: "0" }, + ], + }, + }, + }, + arch: ` +
+ + `, + }; + target = getFixture(); + setupViewRegistries(); + }); + QUnit.module("Components", (hooks) => { + QUnit.module("ProjectTaskPrioritySwitch"); + QUnit.test("Check whether task priority shortcut works as intended", async function (assert) { + await makeView(makeViewParams); + + assert.containsOnce(target, 'div[name="priority"] .fa-star-o', "The low priority should display the fa-star-o (empty) icon"); + await triggerHotkey("alt+r"); + assert.containsOnce(target, 'div[name="priority"] .fa-star', "After using the alt+r hotkey the priority should be set to high and the widget should display the fa-star (filled) icon"); + }); + }); +});