| 1 |
import { describe, expect, test } from "@odoo/hoot"; |
| 2 |
import { click, edit } from "@odoo/hoot-dom"; |
| 3 |
import { animationFrame } from "@odoo/hoot-mock"; |
| 4 |
import { mountView } from "@web/../tests/web_test_helpers"; |
| 5 |
|
| 6 |
import { HRTimesheet, defineTimesheetModels } from "./hr_timesheet_models"; |
| 7 |
|
| 8 |
HRTimesheet._views.list = ` |
| 9 |
<list editable="bottom"> |
| 10 |
<field name="project_id"/> |
| 11 |
<field name="task_id" widget="task_with_hours" context="{ 'default_project_id': project_id }"/> |
| 12 |
<field name="unit_amount"/> |
| 13 |
</list> |
| 14 |
`; |
| 15 |
defineTimesheetModels(); |
| 16 |
describe.current.tags("desktop"); |
| 17 |
|
| 18 |
async function _expectCreateAndEdit(rowN) { |
| 19 |
const taskField = `.o_list_table .o_data_row:nth-of-type(${rowN}) .o_list_many2one[name=task_id]`; |
| 20 |
await click(taskField); |
| 21 |
await animationFrame(); |
| 22 |
await edit("NonExistingTask", { confirm: false }); |
| 23 |
await click(`${taskField} input`); |
| 24 |
await animationFrame(); |
| 25 |
return expect( |
| 26 |
'.o_list_many2one[name=task_id] .dropdown ul li:contains(Create "NonExistingTask")' |
| 27 |
); |
| 28 |
} |
| 29 |
|
| 30 |
test("hr.timesheet (tree): quick create is enabled when project_id is set", async () => { |
| 31 |
await mountView({ |
| 32 |
resModel: "account.analytic.line", |
| 33 |
type: "list", |
| 34 |
}); |
| 35 |
(await _expectCreateAndEdit(2)).toBeVisible(); |
| 36 |
}); |
| 37 |
|
| 38 |
test("hr.timesheet (tree): quick create is no enabled when project_id is not set", async () => { |
| 39 |
await mountView({ |
| 40 |
resModel: "account.analytic.line", |
| 41 |
type: "list", |
| 42 |
}); |
| 43 |
(await _expectCreateAndEdit(3)).not.toHaveCount(); |
| 44 |
}); |
| 45 |
|
| 46 |
test("hr.timesheet (tree): the text of the task includes hours in the drop down but not in the line", async () => { |
| 47 |
await mountView({ |
| 48 |
resModel: "account.analytic.line", |
| 49 |
type: "list", |
| 50 |
}); |
| 51 |
const taskField = ".o_list_table .o_data_row:first-of-type .o_list_many2one[name=task_id]"; |
| 52 |
expect(taskField).toHaveText("Task 3"); |
| 53 |
await click(taskField); |
| 54 |
await animationFrame(); |
| 55 |
await click(`${taskField} input`); |
| 56 |
await animationFrame(); |
| 57 |
expect(`${taskField} .dropdown ul li:contains("AdditionalInfo")`).toHaveCount(3); |
| 58 |
}); |
| 59 |
|
| 60 |
test("project.task (tree): progress bar color", async () => { |
| 61 |
await mountView({ |
| 62 |
resModel: "project.task", |
| 63 |
type: "list", |
| 64 |
arch: ` |
| 65 |
<list> |
| 66 |
<field name="name"/> |
| 67 |
<field name="project_id"/> |
| 68 |
<field name="progress" widget="project_task_progressbar" options="{'overflow_class': 'bg-danger'}"/> |
| 69 |
</list> |
| 70 |
`, |
| 71 |
}); |
| 72 |
|
| 73 |
expect("div.o_progressbar .bg-success").toHaveCount(1, { |
| 74 |
message: "Task 1 having progress = 50 < 80 => green color", |
| 75 |
}); |
| 76 |
expect("div.o_progressbar .bg-warning").toHaveCount(1, { |
| 77 |
message: "Task 2 having progress = 80 >= 80 => orange color", |
| 78 |
}); |
| 79 |
expect("div.o_progressbar .bg-success").toHaveCount(1, { |
| 80 |
message: "Task 3 having progress = 101 > 100 => red color", |
| 81 |
}); |
| 82 |
}); |