| 1 |
import { expect, test } from "@odoo/hoot"; |
| 2 |
import { |
| 3 |
clickSave, |
| 4 |
contains, |
| 5 |
defineModels, |
| 6 |
defineParams, |
| 7 |
fields, |
| 8 |
models, |
| 9 |
mountView, |
| 10 |
onRpc, |
| 11 |
} from "@web/../tests/web_test_helpers"; |
| 12 |
|
| 13 |
class Partner extends models.Model { |
| 14 |
qux = fields.Float(); |
| 15 |
|
| 16 |
_records = [{ id: 1, qux: 9.1 }]; |
| 17 |
} |
| 18 |
|
| 19 |
defineModels([Partner]); |
| 20 |
|
| 21 |
test("FloatFactorField in form view", async () => { |
| 22 |
expect.assertions(3); |
| 23 |
|
| 24 |
onRpc("partner", "web_save", ({ args }) => { |
| 25 |
// 2.3 / 0.5 = 4.6 |
| 26 |
expect(args[1].qux).toBe(4.6, { message: "the correct float value should be saved" }); |
| 27 |
}); |
| 28 |
await mountView({ |
| 29 |
type: "form", |
| 30 |
resModel: "partner", |
| 31 |
resId: 1, |
| 32 |
arch: ` |
| 33 |
<form> |
| 34 |
<sheet> |
| 35 |
<field name="qux" widget="float_factor" options="{'factor': 0.5}" digits="[16,2]" /> |
| 36 |
</sheet> |
| 37 |
</form>`, |
| 38 |
}); |
| 39 |
expect(".o_field_widget[name='qux'] input").toHaveValue("4.55", { |
| 40 |
message: "The value should be rendered correctly in the input.", |
| 41 |
}); |
| 42 |
|
| 43 |
await contains(".o_field_widget[name='qux'] input").edit("2.3"); |
| 44 |
await clickSave(); |
| 45 |
|
| 46 |
expect(".o_field_widget input").toHaveValue("2.30", { |
| 47 |
message: "The new value should be saved and displayed properly.", |
| 48 |
}); |
| 49 |
}); |
| 50 |
|
| 51 |
test("FloatFactorField comma as decimal point", async () => { |
| 52 |
expect.assertions(2); |
| 53 |
|
| 54 |
// patchWithCleanup(localization, { decimalPoint: ",", thousandsSep: "" }); |
| 55 |
defineParams({ |
| 56 |
lang_parameters: { |
| 57 |
decimal_point: ",", |
| 58 |
thousands_sep: "", |
| 59 |
}, |
| 60 |
}); |
| 61 |
onRpc("partner", "web_save", ({ args }) => { |
| 62 |
// 2.3 / 0.5 = 4.6 |
| 63 |
expect(args[1].qux).toBe(4.6); |
| 64 |
expect.step("save"); |
| 65 |
}); |
| 66 |
await mountView({ |
| 67 |
type: "form", |
| 68 |
resModel: "partner", |
| 69 |
resId: 1, |
| 70 |
arch: ` |
| 71 |
<form> |
| 72 |
<sheet> |
| 73 |
<field name="qux" widget="float_factor" options="{'factor': 0.5}" digits="[16,2]" /> |
| 74 |
</sheet> |
| 75 |
</form>`, |
| 76 |
}); |
| 77 |
|
| 78 |
await contains(".o_field_widget[name='qux'] input").edit("2,3"); |
| 79 |
await clickSave(); |
| 80 |
|
| 81 |
expect.verifySteps(["save"]); |
| 82 |
}); |