Skip to content

Commit

Permalink
[IMP] Project: add JS tests for widgets
Browse files Browse the repository at this point in the history
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#148835

X-original-commit: 8b0aff1
Signed-off-by: Xavier Bol (xbo) <[email protected]>
  • Loading branch information
bastvdn committed Jan 11, 2024
1 parent 30a1a98 commit fc4562a
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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: `
<kanban class="o_kanban_test">
<field name="status"/>
<field name="id"/>
<template>
<t t-name="kanban-box">
<div>
<field name="status" widget="status_with_color" readonly="1" status_label="test status label"/>
</div>
</t>
</template>
</kanban>`,
};
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")
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ QUnit.module('Subtask Kanban List tests', {
<templates>
<t t-name="kanban-box">
<div>
<field name="display_name"/>
<field name="display_name" widget="name_with_subtask_count"/>
<field name="user_ids" invisible="1" widget="many2many_avatar_user"/>
<field name="state" invisible="1" widget="project_task_state_selection"/>
<t t-if="record.project_id.raw_value and record.subtask_count.raw_value">
Expand All @@ -78,7 +78,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 } });
Expand All @@ -87,6 +87,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");

Expand Down
51 changes: 51 additions & 0 deletions addons/project/static/tests/project_task_priority_switch_tests.js
Original file line number Diff line number Diff line change
@@ -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: `
<form class="o_kanban_test">
<field name="priority" widget="priority_switch"/>
</form>`,
};
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");
});
});
});

0 comments on commit fc4562a

Please sign in to comment.