import { expect, test } from "@odoo/hoot"; import { contains, defineModels, fields, models, mountView } from "@web/../tests/web_test_helpers"; class Partner extends models.Model { foo = fields.Char({ default: "My little Foo Value" }); int_field = fields.Integer({ string: "int_field" }); qux = fields.Float({ digits: [16, 1] }); monetary = fields.Monetary({ currency_field: "" }); _records = [{ id: 1, foo: "yop", int_field: 10, qux: 0.44444, monetary: 9.999999 }]; } defineModels([Partner]); test("StatInfoField formats decimal precision", async () => { // sometimes the round method can return numbers such as 14.000001 // when asked to round a number to 2 decimals, as such is the behaviour of floats. // we check that even in that eventuality, only two decimals are displayed await mountView({ type: "form", resModel: "partner", resId: 1, arch: /* xml */ `
`, }); // formatFloat renders according to this.field.digits expect("button.oe_stat_button .o_field_widget .o_stat_value:eq(0)").toHaveText("0.4", { message: "Default precision should be [16,1]", }); expect("button.oe_stat_button .o_field_widget .o_stat_value:eq(1)").toHaveText("10.00", { message: "Currency decimal precision should be 2", }); }); test.tags("desktop"); test("StatInfoField in form view on desktop", async () => { await mountView({ type: "form", resModel: "partner", resId: 1, arch: /* xml */ ` `, }); expect("button.oe_stat_button .o_field_widget .o_stat_info").toHaveCount(1, { message: "should have one stat button", }); expect("button.oe_stat_button .o_field_widget .o_stat_value").toHaveText("10", { message: "should have 10 as value", }); expect("button.oe_stat_button .o_field_widget .o_stat_text").toHaveText("int_field", { message: "should have 'int_field' as text", }); }); test.tags("mobile"); test("StatInfoField in form view on mobile", async () => { await mountView({ type: "form", resModel: "partner", resId: 1, arch: /* xml */ ` `, }); await contains(".o-form-buttonbox .o_button_more").click(); expect("button.oe_stat_button .o_field_widget .o_stat_info").toHaveCount(1, { message: "should have one stat button", }); expect("button.oe_stat_button .o_field_widget .o_stat_value").toHaveText("10", { message: "should have 10 as value", }); expect("button.oe_stat_button .o_field_widget .o_stat_text").toHaveText("int_field", { message: "should have 'int_field' as text", }); }); test.tags("desktop"); test("StatInfoField in form view with specific label_field on desktop", async () => { await mountView({ type: "form", resModel: "partner", resId: 1, arch: /* xml */ ` `, }); expect("button.oe_stat_button .o_field_widget .o_stat_info").toHaveCount(1, { message: "should have one stat button", }); expect("button.oe_stat_button .o_field_widget .o_stat_value").toHaveText("10", { message: "should have 10 as value", }); expect("button.oe_stat_button .o_field_widget .o_stat_text").toHaveText("yop", { message: "should have 'yop' as text, since it is the value of field foo", }); }); test.tags("mobile"); test("StatInfoField in form view with specific label_field on mobile", async () => { await mountView({ type: "form", resModel: "partner", resId: 1, arch: /* xml */ ` `, }); await contains(".o-form-buttonbox .o_button_more").click(); expect("button.oe_stat_button .o_field_widget .o_stat_info").toHaveCount(1, { message: "should have one stat button", }); expect("button.oe_stat_button .o_field_widget .o_stat_value").toHaveText("10", { message: "should have 10 as value", }); expect("button.oe_stat_button .o_field_widget .o_stat_text").toHaveText("yop", { message: "should have 'yop' as text, since it is the value of field foo", }); }); test.tags("desktop"); test("StatInfoField in form view with no label on desktop", async () => { await mountView({ type: "form", resModel: "partner", resId: 1, arch: /* xml */ ` `, }); expect("button.oe_stat_button .o_field_widget .o_stat_info").toHaveCount(1, { message: "should have one stat button", }); expect("button.oe_stat_button .o_field_widget .o_stat_value").toHaveText("10", { message: "should have 10 as value", }); expect("button.oe_stat_button .o_field_widget .o_stat_text").toHaveCount(0, { message: "should not have any label", }); }); test.tags("mobile"); test("StatInfoField in form view with no label on mobile", async () => { await mountView({ type: "form", resModel: "partner", resId: 1, arch: /* xml */ ` `, }); await contains(".o-form-buttonbox .o_button_more").click(); expect("button.oe_stat_button .o_field_widget .o_stat_info").toHaveCount(1, { message: "should have one stat button", }); expect("button.oe_stat_button .o_field_widget .o_stat_value").toHaveText("10", { message: "should have 10 as value", }); expect("button.oe_stat_button .o_field_widget .o_stat_text").toHaveCount(0, { message: "should not have any label", }); });