import { expect, test, beforeEach, describe } from "@odoo/hoot"; import { mockDate, animationFrame, runAllTimers } from "@odoo/hoot-mock"; import { click, queryOne } from "@odoo/hoot-dom"; import { mountView, onRpc } from "@web/../tests/web_test_helpers"; import { defineProjectModels, ProjectTask } from "./project_models"; describe.current.tags("desktop"); defineProjectModels(); beforeEach(() => { mockDate("2024-01-03 12:00:00", +0); ProjectTask._views["form,false"] = `
`; ProjectTask._records = [ { id: 1, name: "Task-1", date_deadline: "2024-01-09 07:00:00", create_date: "2024-01-03 12:00:00", project_id: 1, stage_id: 1, state: "01_in_progress", user_ids: [], display_name: "Task-1", }, ]; onRpc("has_access", () => true); }); const calendarMountParams = { resModel: "project.task", type: "calendar", arch: ` `, }; test("test Project Task Calendar Popover with task_stage_with_state_selection widget", async () => { await mountView(calendarMountParams); await click("a.fc-daygrid-event"); // Skipping setTimeout while clicking event in calendar for calendar popover to appear. // There is a timeout set in the useCalendarPopover. await runAllTimers(); expect(queryOne(".o_field_task_stage_with_state_selection div").childElementCount).toBe(2); }); test("test task_stage_with_state_selection widget with non-editable state", async () => { await mountView({ ...calendarMountParams, arch: ` `, }); await click("a.fc-daygrid-event"); // Skipping setTimeout while clicking event in calendar for calendar popover to appear. // There is a timeout set in the useCalendarPopover. await runAllTimers(); await click("button[title='In Progress']"); expect(".project_task_state_selection_menu").toHaveCount(0); }); test("test task_stage_with_state_selection widget with editable state", async () => { await mountView({ ...calendarMountParams, arch: ` `, }); await click("a.fc-daygrid-event"); // Skipping setTimeout while clicking event in calendar for calendar popover to appear. // There is a timeout set in the useCalendarPopover. await runAllTimers(); await click(".o-dropdown div[title='In Progress']"); await animationFrame(); expect(".project_task_state_selection_menu").toHaveCount(1); await click(".o_status_green"); // Checking if click on the state in selection menu works(changes in record) await animationFrame(); expect(".o-dropdown .o_status").toHaveStyle({ color: "rgb(0, 136, 24)" }); });