import { expect, test } from "@odoo/hoot"; import { click, edit, queryOne, queryText, queryValue } from "@odoo/hoot-dom"; import { animationFrame } from "@odoo/hoot-mock"; import { clickSave, defineModels, defineParams, fields, models, mountView, onRpc, } from "@web/../tests/web_test_helpers"; class Partner extends models.Model { name = fields.Char({ string: "Display Name" }); int_field = fields.Integer({ string: "int_field", }); int_field2 = fields.Integer({ string: "int_field", }); int_field3 = fields.Integer({ string: "int_field", }); float_field = fields.Float({ string: "Float_field", digits: [16, 1], }); _records = [ { int_field: 10, float_field: 0.44444, }, ]; } defineModels([Partner]); test("ProgressBarField: max_value should update", async () => { expect.assertions(3); Partner._records[0].float_field = 2; Partner._onChanges.name = (record) => { record.int_field = 999; record.float_field = 5; }; onRpc("web_save", ({ args }) => { expect(args[1]).toEqual( { int_field: 999, float_field: 5, name: "new name" }, { message: "New value of progress bar saved" } ); }); await mountView({ type: "form", resModel: "partner", arch: /* xml */ `
`, resId: 1, }); expect(".o_progressbar").toHaveText("10\n/\n2"); await click(".o_field_widget[name=name] input"); await edit("new name", { confirm: "enter" }); await clickSave(); await animationFrame(); expect(".o_progressbar").toHaveText("999\n/\n5"); }); test("ProgressBarField: value should update in edit mode when typing in input", async () => { expect.assertions(4); Partner._records[0].int_field = 99; onRpc("web_save", ({ args }) => expect(args[1].int_field).toBe(69)); await mountView({ type: "form", resModel: "partner", arch: /* xml */ ` `, resId: 1, }); expect(queryValue(".o_progressbar_value .o_input") + queryText(".o_progressbar")).toBe("99%", { message: "Initial value should be correct", }); await click(".o_progressbar_value .o_input"); // wait for apply dom change await animationFrame(); await edit("69", { confirm: "enter" }); expect(".o_progressbar_value .o_input").toHaveValue("69", { message: "New value should be different after focusing out of the field", }); // wait for apply dom change await animationFrame(); await clickSave(); // wait for rpc await animationFrame(); expect(".o_progressbar_value .o_input").toHaveValue("69", { message: "New value is still displayed after save", }); }); test("ProgressBarField: value should update in edit mode when typing in input with field max value", async () => { expect.assertions(4); Partner._records[0].int_field = 99; onRpc("web_save", ({ args }) => expect(args[1].int_field).toBe(69)); await mountView({ type: "form", resModel: "partner", arch: /* xml */ ` `, resId: 1, }); expect(".o_form_view .o_form_editable").toHaveCount(1, { message: "Form in edit mode" }); expect(queryValue(".o_progressbar_value .o_input") + queryText(".o_progressbar")).toBe( "99/\n0", { message: "Initial value should be correct" } ); await click(".o_progressbar_value .o_input"); await animationFrame(); await edit("69", { confirm: "enter" }); await animationFrame(); await clickSave(); await animationFrame(); expect(queryValue(".o_progressbar_value .o_input") + queryText(".o_progressbar")).toBe( "69/\n0", { message: "New value should be different than initial after click" } ); }); test("ProgressBarField: max value should update in edit mode when typing in input with field max value", async () => { expect.assertions(5); Partner._records[0].int_field = 99; onRpc("web_save", ({ args }) => expect(args[1].float_field).toBe(69)); await mountView({ type: "form", resModel: "partner", arch: /* xml */ ` `, resId: 1, }); expect(queryText(".o_progressbar") + queryValue(".o_progressbar_value .o_input")).toBe( "99\n/0", { message: "Initial value should be correct" } ); expect(".o_form_view .o_form_editable").toHaveCount(1, { message: "Form in edit mode" }); queryOne(".o_progressbar input").focus(); await animationFrame(); expect(queryText(".o_progressbar") + queryValue(".o_progressbar_value .o_input")).toBe( "99\n/0.44", { message: "Initial value is not formatted when focused" } ); await click(".o_progressbar_value .o_input"); await edit("69", { confirm: "enter" }); await clickSave(); expect(queryText(".o_progressbar") + queryValue(".o_progressbar_value .o_input")).toBe( "99\n/69", { message: "New value should be different than initial after click" } ); }); test("ProgressBarField: Standard readonly mode is readonly", async () => { Partner._records[0].int_field = 99; onRpc(({ method }) => expect.step(method)); await mountView({ type: "form", resModel: "partner", arch: /* xml */ ` `, resId: 1, }); expect(".o_progressbar").toHaveText("99\n/\n0", { message: "Initial value should be correct", }); await click(".o_progress"); await animationFrame(); expect(".o_progressbar_value .o_input").toHaveCount(0, { message: "no input in readonly mode", }); expect.verifySteps(["get_views", "web_read"]); }); test("ProgressBarField: field is editable in kanban", async () => { expect.assertions(7); Partner._records[0].int_field = 99; onRpc("web_save", ({ args }) => expect(args[1].int_field).toBe(69)); await mountView({ type: "kanban", resModel: "partner", arch: /* xml */ `