| 1 |
import { expect, test } from "@odoo/hoot"; |
| 2 |
import { click, edit, queryFirst } from "@odoo/hoot-dom"; |
| 3 |
import { animationFrame } from "@odoo/hoot-mock"; |
| 4 |
import { defineModels, fields, models, mountView } from "@web/../tests/web_test_helpers"; |
| 5 |
|
| 6 |
class Report extends models.Model { |
| 7 |
int_field = fields.Integer(); |
| 8 |
html_field = fields.Html(); |
| 9 |
|
| 10 |
_records = [ |
| 11 |
{ |
| 12 |
id: 1, |
| 13 |
html_field: /* html */ ` |
| 14 |
<html> |
| 15 |
<head> |
| 16 |
<style> |
| 17 |
body { color : rgb(255, 0, 0); } |
| 18 |
</style> |
| 19 |
</head> |
| 20 |
<body> |
| 21 |
<div class="nice_div"><p>Some content</p></div> |
| 22 |
</body> |
| 23 |
</html> |
| 24 |
`, |
| 25 |
}, |
| 26 |
]; |
| 27 |
} |
| 28 |
|
| 29 |
defineModels([Report]); |
| 30 |
|
| 31 |
test("IframeWrapperField in form view with onchange", async () => { |
| 32 |
Report._onChanges.int_field = (record) => { |
| 33 |
record.html_field = record.html_field.replace("Some content", "New content"); |
| 34 |
}; |
| 35 |
await mountView({ |
| 36 |
type: "form", |
| 37 |
resModel: "report", |
| 38 |
resId: 1, |
| 39 |
arch: /* xml */ ` |
| 40 |
<form> |
| 41 |
<field name="int_field"/> |
| 42 |
<field name="html_field" widget="iframe_wrapper"/> |
| 43 |
</form> |
| 44 |
`, |
| 45 |
}); |
| 46 |
|
| 47 |
expect("iframe:iframe .nice_div:first").toHaveInnerHTML("<p>Some content</p>"); |
| 48 |
expect("iframe:iframe .nice_div p:first").toHaveStyle({ |
| 49 |
color: "rgb(255, 0, 0)", |
| 50 |
}); |
| 51 |
await click(".o_field_widget[name=int_field] input"); |
| 52 |
await edit(264, { confirm: "enter" }); |
| 53 |
await animationFrame(); |
| 54 |
expect(queryFirst("iframe:iframe .nice_div")).toHaveInnerHTML("<p>New content</p>"); |
| 55 |
}); |