| 1 |
import { describe, expect, test } from "@odoo/hoot"; |
| 2 |
import { patchWithCleanup } from "@web/../tests/web_test_helpers"; |
| 3 |
|
| 4 |
import { createElement } from "@web/core/utils/xml"; |
| 5 |
import { FormCompiler } from "@web/views/form/form_compiler"; |
| 6 |
|
| 7 |
describe.current.tags("headless"); |
| 8 |
|
| 9 |
function compileTemplate(arch) { |
| 10 |
const parser = new DOMParser(); |
| 11 |
const xml = parser.parseFromString(arch, "text/xml"); |
| 12 |
const compiler = new FormCompiler({ form: xml.documentElement }); |
| 13 |
return compiler.compile("form"); |
| 14 |
} |
| 15 |
|
| 16 |
test("properly compile simple div", () => { |
| 17 |
const arch = /*xml*/ `<form><div>lol</div></form>`; |
| 18 |
const expected = /*xml*/ ` |
| 19 |
<t t-translation="off"> |
| 20 |
<div class="o_form_renderer o_form_nosheet" t-att-class="__comp__.props.class" t-attf-class="{{__comp__.props.record.isInEdition ? 'o_form_editable' : 'o_form_readonly'}} d-block {{ __comp__.props.record.dirty ? 'o_form_dirty' : !__comp__.props.record.isNew ? 'o_form_saved' : '' }}" t-ref="compiled_view_root"> |
| 21 |
<div>lol</div> |
| 22 |
</div> |
| 23 |
</t> |
| 24 |
`; |
| 25 |
expect(compileTemplate(arch)).toHaveOuterHTML(expected); |
| 26 |
}); |
| 27 |
|
| 28 |
test("label with empty string compiles to FormLabel with empty string", () => { |
| 29 |
const arch = /*xml*/ `<form><field field_id="test" name="test"/><label for="test" string=""/></form>`; |
| 30 |
const expected = /*xml*/ ` |
| 31 |
<t t-translation="off"> |
| 32 |
<div class="o_form_renderer o_form_nosheet" t-att-class="__comp__.props.class" t-attf-class="{{__comp__.props.record.isInEdition ? 'o_form_editable' : 'o_form_readonly'}} d-block {{ __comp__.props.record.dirty ? 'o_form_dirty' : !__comp__.props.record.isNew ? 'o_form_saved' : '' }}" t-ref="compiled_view_root"> |
| 33 |
<Field id="'test'" name="'test'" record="__comp__.props.record" fieldInfo="__comp__.props.archInfo.fieldNodes['test']" readonly="__comp__.props.readonly"/> |
| 34 |
<FormLabel id="'test'" fieldName="'test'" record="__comp__.props.record" fieldInfo="__comp__.props.archInfo.fieldNodes['test']" className="""" string="\`\`" /> |
| 35 |
</div> |
| 36 |
</t> |
| 37 |
`; |
| 38 |
expect(compileTemplate(arch)).toHaveOuterHTML(expected); |
| 39 |
}); |
| 40 |
|
| 41 |
test("properly compile simple div with field", () => { |
| 42 |
const arch = /*xml*/ `<form><div class="someClass">lol<field field_id="display_name" name="display_name"/></div></form>`; |
| 43 |
const expected = /*xml*/ ` |
| 44 |
<t t-translation="off"> |
| 45 |
<div class="o_form_renderer o_form_nosheet" t-att-class="__comp__.props.class" t-attf-class="{{__comp__.props.record.isInEdition ? 'o_form_editable' : 'o_form_readonly'}} d-block {{ __comp__.props.record.dirty ? 'o_form_dirty' : !__comp__.props.record.isNew ? 'o_form_saved' : '' }}" t-ref="compiled_view_root"> |
| 46 |
<div class="someClass"> |
| 47 |
lol |
| 48 |
<Field id="'display_name'" name="'display_name'" record="__comp__.props.record" fieldInfo="__comp__.props.archInfo.fieldNodes['display_name']" readonly="__comp__.props.readonly"/> |
| 49 |
</div> |
| 50 |
</div> |
| 51 |
</t> |
| 52 |
`; |
| 53 |
expect(compileTemplate(arch)).toHaveOuterHTML(expected); |
| 54 |
}); |
| 55 |
|
| 56 |
test("properly compile inner groups", () => { |
| 57 |
const arch = /*xml*/ ` |
| 58 |
<form> |
| 59 |
<group> |
| 60 |
<group><field field_id="display_name" name="display_name"/></group> |
| 61 |
<group><field field_id="charfield" name="charfield"/></group> |
| 62 |
</group> |
| 63 |
</form> |
| 64 |
`; |
| 65 |
const expected = /*xml*/ ` |
| 66 |
<t t-translation="off"> |
| 67 |
<div class="o_form_renderer o_form_nosheet" t-att-class="__comp__.props.class" t-attf-class="{{__comp__.props.record.isInEdition ? 'o_form_editable' : 'o_form_readonly'}} d-block {{ __comp__.props.record.dirty ? 'o_form_dirty' : !__comp__.props.record.isNew ? 'o_form_saved' : '' }}" t-ref="compiled_view_root"> |
| 68 |
<OuterGroup> |
| 69 |
<t t-set-slot="item_0" type="'item'" sequence="0" t-slot-scope="scope" isVisible="true" itemSpan="1"> |
| 70 |
<InnerGroup class="scope && scope.className"> |
| 71 |
<t t-set-slot="item_0" type="'item'" sequence="0" t-slot-scope="scope" props="{id:'display_name',fieldName:'display_name',record:__comp__.props.record,string:__comp__.props.record.fields.display_name.string,fieldInfo:__comp__.props.archInfo.fieldNodes['display_name']}" Component="__comp__.constructor.components.FormLabel" subType="'item_component'" isVisible="true" itemSpan="2"> |
| 72 |
<Field id="'display_name'" name="'display_name'" record="__comp__.props.record" fieldInfo="__comp__.props.archInfo.fieldNodes['display_name']" readonly="__comp__.props.readonly" class="scope && scope.className"/> |
| 73 |
</t> |
| 74 |
</InnerGroup> |
| 75 |
</t> |
| 76 |
<t t-set-slot="item_1" type="'item'" sequence="1" t-slot-scope="scope" isVisible="true" itemSpan="1"> |
| 77 |
<InnerGroup class="scope && scope.className"> |
| 78 |
<t t-set-slot="item_0" type="'item'" sequence="0" t-slot-scope="scope" props="{id:'charfield',fieldName:'charfield',record:__comp__.props.record,string:__comp__.props.record.fields.charfield.string,fieldInfo:__comp__.props.archInfo.fieldNodes['charfield']}" Component="__comp__.constructor.components.FormLabel" subType="'item_component'" isVisible="true" itemSpan="2"> |
| 79 |
<Field id="'charfield'" name="'charfield'" record="__comp__.props.record" fieldInfo="__comp__.props.archInfo.fieldNodes['charfield']" readonly="__comp__.props.readonly" class="scope && scope.className"/> |
| 80 |
</t> |
| 81 |
</InnerGroup> |
| 82 |
</t> |
| 83 |
</OuterGroup> |
| 84 |
</div> |
| 85 |
</t> |
| 86 |
`; |
| 87 |
expect(compileTemplate(arch)).toHaveOuterHTML(expected); |
| 88 |
}); |
| 89 |
|
| 90 |
test("properly compile attributes with nested forms", () => { |
| 91 |
const arch = /*xml*/ ` |
| 92 |
<form> |
| 93 |
<group> |
| 94 |
<group> |
| 95 |
<form> |
| 96 |
<div> |
| 97 |
<field field_id="test" name="test"/> |
| 98 |
</div> |
| 99 |
</form> |
| 100 |
</group> |
| 101 |
</group> |
| 102 |
</form> |
| 103 |
`; |
| 104 |
const expected = /*xml*/ ` |
| 105 |
<t t-translation="off"> |
| 106 |
<div class="o_form_renderer o_form_nosheet" t-att-class="__comp__.props.class" t-attf-class="{{__comp__.props.record.isInEdition ? 'o_form_editable' : 'o_form_readonly'}} d-block {{ __comp__.props.record.dirty ? 'o_form_dirty' : !__comp__.props.record.isNew ? 'o_form_saved' : '' }}" t-ref="compiled_view_root"> |
| 107 |
<OuterGroup> |
| 108 |
<t t-set-slot="item_0" type="'item'" sequence="0" t-slot-scope="scope" isVisible="true" itemSpan="1"> |
| 109 |
<InnerGroup class="scope && scope.className"> |
| 110 |
<t t-set-slot="item_0" type="'item'" sequence="0" t-slot-scope="scope" isVisible="true" itemSpan="1"> |
| 111 |
<div class="o_form_renderer o_form_nosheet" t-att-class="__comp__.props.class" t-attf-class="{{__comp__.props.record.isInEdition ? 'o_form_editable' : 'o_form_readonly'}} d-block {{ __comp__.props.record.dirty ? 'o_form_dirty' : !__comp__.props.record.isNew ? 'o_form_saved' : '' }} {{scope && scope.className || "" }}"> |
| 112 |
<div><Field id="'test'" name="'test'" record="__comp__.props.record" fieldInfo="__comp__.props.archInfo.fieldNodes['test']" readonly="__comp__.props.readonly"/></div> |
| 113 |
</div> |
| 114 |
</t> |
| 115 |
</InnerGroup> |
| 116 |
</t> |
| 117 |
</OuterGroup> |
| 118 |
</div> |
| 119 |
</t> |
| 120 |
`; |
| 121 |
expect(compileTemplate(arch)).toHaveOuterHTML(expected); |
| 122 |
}); |
| 123 |
|
| 124 |
test("properly compile notebook", () => { |
| 125 |
const arch = /*xml*/ ` |
| 126 |
<form> |
| 127 |
<notebook> |
| 128 |
<page name="p1" string="Page1"><field field_id="charfield" name="charfield"/></page> |
| 129 |
<page name="p2" string="Page2"><field field_id="display_name" name="display_name"/></page> |
| 130 |
</notebook> |
| 131 |
</form> |
| 132 |
`; |
| 133 |
const expected = /*xml*/ ` |
| 134 |
<t t-translation="off"> |
| 135 |
<div class="o_form_renderer o_form_nosheet" t-att-class="__comp__.props.class" t-attf-class="{{__comp__.props.record.isInEdition ? 'o_form_editable' : 'o_form_readonly'}} d-block {{ __comp__.props.record.dirty ? 'o_form_dirty' : !__comp__.props.record.isNew ? 'o_form_saved' : '' }}" t-ref="compiled_view_root"> |
| 136 |
<Notebook defaultPage="__comp__.props.record.isNew ? undefined : __comp__.props.activeNotebookPages[0]" onPageUpdate="(page) => __comp__.props.onNotebookPageChange(0, page)"> |
| 137 |
<t t-set-slot="page_1" title="\`Page1\`" name="\`p1\`" isVisible="true" fieldnames="["charfield"]"> |
| 138 |
<Field id="'charfield'" name="'charfield'" record="__comp__.props.record" fieldInfo="__comp__.props.archInfo.fieldNodes['charfield']" readonly="__comp__.props.readonly"/> |
| 139 |
</t> |
| 140 |
<t t-set-slot="page_2" title="\`Page2\`" name="\`p2\`" isVisible="true" fieldnames="["display_name"]"> |
| 141 |
<Field id="'display_name'" name="'display_name'" record="__comp__.props.record" fieldInfo="__comp__.props.archInfo.fieldNodes['display_name']" readonly="__comp__.props.readonly"/> |
| 142 |
</t> |
| 143 |
</Notebook> |
| 144 |
</div> |
| 145 |
</t> |
| 146 |
`; |
| 147 |
expect(compileTemplate(arch)).toHaveOuterHTML(expected); |
| 148 |
}); |
| 149 |
|
| 150 |
test("properly compile field without placeholder", () => { |
| 151 |
const arch = /*xml*/ ` |
| 152 |
<form> |
| 153 |
<field field_id="display_name" name="display_name" placeholder="e.g. Contact's Name or //someinfo..."/> |
| 154 |
</form> |
| 155 |
`; |
| 156 |
const expected = /*xml*/ ` |
| 157 |
<t t-translation="off"> |
| 158 |
<div class="o_form_renderer o_form_nosheet" t-att-class="__comp__.props.class" t-attf-class="{{__comp__.props.record.isInEdition ? 'o_form_editable' : 'o_form_readonly'}} d-block {{ __comp__.props.record.dirty ? 'o_form_dirty' : !__comp__.props.record.isNew ? 'o_form_saved' : '' }}" t-ref="compiled_view_root"> |
| 159 |
<Field id="'display_name'" name="'display_name'" record="__comp__.props.record" fieldInfo="__comp__.props.archInfo.fieldNodes['display_name']" readonly="__comp__.props.readonly"/> |
| 160 |
</div> |
| 161 |
</t> |
| 162 |
`; |
| 163 |
expect(compileTemplate(arch)).toHaveOuterHTML(expected); |
| 164 |
}); |
| 165 |
|
| 166 |
test("properly compile no sheet", () => { |
| 167 |
const arch = /*xml*/ ` |
| 168 |
<form> |
| 169 |
<header>someHeader</header> |
| 170 |
<div>someDiv</div> |
| 171 |
</form> |
| 172 |
`; |
| 173 |
const expected = /*xml*/ ` |
| 174 |
<t t-translation="off"> |
| 175 |
<div class="o_form_renderer o_form_nosheet" t-att-class="__comp__.props.class" t-attf-class="{{__comp__.props.record.isInEdition ? 'o_form_editable' : 'o_form_readonly'}} d-block {{ __comp__.props.record.dirty ? 'o_form_dirty' : !__comp__.props.record.isNew ? 'o_form_saved' : '' }}" t-ref="compiled_view_root"> |
| 176 |
<div t-att-class="{ 'shadow-sm': __comp__.state.isStatusbarStickyPinned }" class="o_form_statusbar d-flex justify-content-between py-2"> |
| 177 |
<StatusBarButtons/> |
| 178 |
</div> |
| 179 |
<div>someDiv</div> |
| 180 |
</div> |
| 181 |
</t> |
| 182 |
`; |
| 183 |
expect(compileTemplate(arch)).toHaveOuterHTML(expected); |
| 184 |
}); |
| 185 |
|
| 186 |
test("properly compile sheet", () => { |
| 187 |
const arch = /*xml*/ ` |
| 188 |
<form> |
| 189 |
<header>someHeader</header> |
| 190 |
<div>someDiv</div> |
| 191 |
<sheet> |
| 192 |
<div>inside sheet</div> |
| 193 |
</sheet> |
| 194 |
<div>after sheet</div> |
| 195 |
</form> |
| 196 |
`; |
| 197 |
const expected = /*xml*/ ` |
| 198 |
<t t-translation="off"> |
| 199 |
<div class="o_form_renderer" t-att-class="__comp__.props.class" t-attf-class="{{__comp__.props.record.isInEdition ? 'o_form_editable' : 'o_form_readonly'}} d-flex d-print-block {{ __comp__.uiService.size < 5 ? "flex-column" : "flex-nowrap h-100" }} {{ __comp__.props.record.dirty ? 'o_form_dirty' : !__comp__.props.record.isNew ? 'o_form_saved' : '' }}" t-ref="compiled_view_root"> |
| 200 |
<div t-on-scroll="__comp__.onScrollThrottled" class="o_form_sheet_bg"> |
| 201 |
<div t-att-class="{ 'shadow-sm': __comp__.state.isStatusbarStickyPinned }" class="o_form_statusbar d-flex justify-content-between py-2"><StatusBarButtons/></div> |
| 202 |
<div>someDiv</div> |
| 203 |
<div class="o_form_sheet position-relative"> |
| 204 |
<div>inside sheet</div> |
| 205 |
</div> |
| 206 |
</div> |
| 207 |
<div>after sheet</div> |
| 208 |
</div> |
| 209 |
</t> |
| 210 |
`; |
| 211 |
expect(compileTemplate(arch)).toHaveOuterHTML(expected); |
| 212 |
}); |
| 213 |
|
| 214 |
test("properly compile buttonBox invisible in sheet", () => { |
| 215 |
const arch = /*xml*/ ` |
| 216 |
<form> |
| 217 |
<sheet> |
| 218 |
<div class="oe_button_box" name="button_box" invisible="'display_name' == 'plop'"> |
| 219 |
<div>Hello</div> |
| 220 |
</div> |
| 221 |
</sheet> |
| 222 |
</form> |
| 223 |
`; |
| 224 |
const expected = /*xml*/ ` |
| 225 |
<t t-translation="off"> |
| 226 |
<div class="o_form_renderer" |
| 227 |
t-att-class="__comp__.props.class" |
| 228 |
t-attf-class="{{__comp__.props.record.isInEdition ? 'o_form_editable' : 'o_form_readonly'}} d-flex d-print-block {{ __comp__.uiService.size < 5 ? "flex-column" : "flex-nowrap h-100" }} {{ __comp__.props.record.dirty ? 'o_form_dirty' : !__comp__.props.record.isNew ? 'o_form_saved' : '' }}" |
| 229 |
t-ref="compiled_view_root"> |
| 230 |
<div t-on-scroll="__comp__.onScrollThrottled" class="o_form_sheet_bg"> |
| 231 |
<div class="o_form_sheet position-relative"> |
| 232 |
</div> |
| 233 |
</div> |
| 234 |
</div> |
| 235 |
</t> |
| 236 |
`; |
| 237 |
expect(compileTemplate(arch)).toHaveOuterHTML(expected); |
| 238 |
}); |
| 239 |
|
| 240 |
test("properly compile invisible", () => { |
| 241 |
// cf python side: def transfer_node_to_modifiers |
| 242 |
// modifiers' string are evaluated to their boolean or array form |
| 243 |
// So the following arch may actually be written as: |
| 244 |
// ```<form> |
| 245 |
// <field name="display_name" invisible="1" /> |
| 246 |
// <div class="visible3" invisible="0"/> |
| 247 |
// <div invisible="display_name == 'take'"/> |
| 248 |
// </form>```` |
| 249 |
const arch = /*xml*/ ` |
| 250 |
<form> |
| 251 |
<field field_id="display_name" name="display_name" invisible="True" /> |
| 252 |
<div class="visible3" invisible="False"/> |
| 253 |
<div invisible="display_name == "take""/> |
| 254 |
</form> |
| 255 |
`; |
| 256 |
const expected = /*xml*/ ` |
| 257 |
<t t-translation="off"> |
| 258 |
<div class="o_form_renderer o_form_nosheet" t-att-class="__comp__.props.class" t-attf-class="{{__comp__.props.record.isInEdition ? 'o_form_editable' : 'o_form_readonly'}} d-block {{ __comp__.props.record.dirty ? 'o_form_dirty' : !__comp__.props.record.isNew ? 'o_form_saved' : '' }}" t-ref="compiled_view_root"> |
| 259 |
<div class="visible3"/> |
| 260 |
<div t-if="!__comp__.evaluateBooleanExpr("display_name == \\"take\\"",__comp__.props.record.evalContextWithVirtualIds)"/> |
| 261 |
</div> |
| 262 |
</t> |
| 263 |
`; |
| 264 |
expect(compileTemplate(arch)).toHaveOuterHTML(expected); |
| 265 |
}); |
| 266 |
|
| 267 |
test("compile invisible containing string as domain", () => { |
| 268 |
const arch = /*xml*/ ` |
| 269 |
<form> |
| 270 |
<field name="display_name" invisible="True"/> |
| 271 |
<div class="visible3" invisible="False"/> |
| 272 |
<div invisible="display_name == 'take'"/> |
| 273 |
</form> |
| 274 |
`; |
| 275 |
const expected = /*xml*/ ` |
| 276 |
<t t-translation="off"> |
| 277 |
<div class="o_form_renderer o_form_nosheet" t-att-class="__comp__.props.class" t-attf-class="{{__comp__.props.record.isInEdition ? 'o_form_editable' : 'o_form_readonly'}} d-block {{ __comp__.props.record.dirty ? 'o_form_dirty' : !__comp__.props.record.isNew ? 'o_form_saved' : '' }}" t-ref="compiled_view_root"> |
| 278 |
<div class="visible3" /> |
| 279 |
<div t-if="!__comp__.evaluateBooleanExpr("display_name == 'take'",__comp__.props.record.evalContextWithVirtualIds)"/> |
| 280 |
</div> |
| 281 |
</t> |
| 282 |
`; |
| 283 |
expect(compileTemplate(arch)).toHaveOuterHTML(expected); |
| 284 |
}); |
| 285 |
|
| 286 |
test("properly compile status bar with content", () => { |
| 287 |
const arch = /*xml*/ ` |
| 288 |
<form> |
| 289 |
<header><div>someDiv</div></header> |
| 290 |
</form> |
| 291 |
`; |
| 292 |
const expected = /*xml*/ ` |
| 293 |
<t t-translation="off"> |
| 294 |
<div class="o_form_renderer o_form_nosheet" t-att-class="__comp__.props.class" t-attf-class="{{__comp__.props.record.isInEdition ? 'o_form_editable' : 'o_form_readonly'}} d-block {{ __comp__.props.record.dirty ? 'o_form_dirty' : !__comp__.props.record.isNew ? 'o_form_saved' : '' }}" t-ref="compiled_view_root"> |
| 295 |
<div t-att-class="{ 'shadow-sm': __comp__.state.isStatusbarStickyPinned }" class="o_form_statusbar d-flex justify-content-between py-2"> |
| 296 |
<StatusBarButtons> |
| 297 |
<t t-set-slot="button_0" isVisible="true"> |
| 298 |
<div>someDiv</div> |
| 299 |
</t> |
| 300 |
</StatusBarButtons> |
| 301 |
</div> |
| 302 |
</div> |
| 303 |
</t> |
| 304 |
`; |
| 305 |
expect(compileTemplate(arch)).toHaveOuterHTML(expected); |
| 306 |
}); |
| 307 |
|
| 308 |
test("properly compile status bar without content", () => { |
| 309 |
const arch = /*xml*/ ` |
| 310 |
<form> |
| 311 |
<header></header> |
| 312 |
</form> |
| 313 |
`; |
| 314 |
const expected = /*xml*/ ` |
| 315 |
<t t-translation="off"> |
| 316 |
<div class="o_form_renderer o_form_nosheet" t-att-class="__comp__.props.class" t-attf-class="{{__comp__.props.record.isInEdition ? 'o_form_editable' : 'o_form_readonly'}} d-block {{ __comp__.props.record.dirty ? 'o_form_dirty' : !__comp__.props.record.isNew ? 'o_form_saved' : '' }}" t-ref="compiled_view_root"> |
| 317 |
<div t-att-class="{ 'shadow-sm': __comp__.state.isStatusbarStickyPinned }" class="o_form_statusbar d-flex justify-content-between py-2"> |
| 318 |
<StatusBarButtons/> |
| 319 |
</div> |
| 320 |
</div> |
| 321 |
</t> |
| 322 |
`; |
| 323 |
expect(compileTemplate(arch)).toHaveOuterHTML(expected); |
| 324 |
}); |
| 325 |
|
| 326 |
test("properly compile settings", () => { |
| 327 |
const arch = /*xml*/ ` |
| 328 |
<form> |
| 329 |
<setting help="this is bar" |
| 330 |
documentation="/applications/technical/web/settings/this_is_a_test.html" |
| 331 |
company_dependent="1"> |
| 332 |
<field field_id="bar" name="bar"/> |
| 333 |
<label>label with content</label> |
| 334 |
</setting> |
| 335 |
</form> |
| 336 |
`; |
| 337 |
const expected = /*xml*/ ` |
| 338 |
<t t-translation="off"> |
| 339 |
<div class="o_form_renderer o_form_nosheet" t-att-class="__comp__.props.class" t-attf-class="{{__comp__.props.record.isInEdition ? 'o_form_editable' : 'o_form_readonly'}} d-block {{ __comp__.props.record.dirty ? 'o_form_dirty' : !__comp__.props.record.isNew ? 'o_form_saved' : '' }}" t-ref="compiled_view_root"> |
| 340 |
<Setting info="\`\`" |
| 341 |
title="\`\`" |
| 342 |
help="\`this is bar\`" |
| 343 |
companyDependent="true" |
| 344 |
documentation="\`/applications/technical/web/settings/this_is_a_test.html\`" |
| 345 |
record="__comp__.props.record" |
| 346 |
fieldInfo="__comp__.props.archInfo.fieldNodes['bar']" |
| 347 |
fieldName="\`bar\`" |
| 348 |
fieldId="\`bar\`" |
| 349 |
string="\`\`" |
| 350 |
addLabel="true"> |
| 351 |
<t t-set-slot="fieldSlot"> |
| 352 |
<Field id="'bar'" |
| 353 |
name="'bar'" |
| 354 |
record="__comp__.props.record" |
| 355 |
fieldInfo="__comp__.props.archInfo.fieldNodes['bar']" |
| 356 |
readonly="__comp__.props.readonly"/> |
| 357 |
</t> |
| 358 |
<label>label with content</label> |
| 359 |
</Setting> |
| 360 |
</div> |
| 361 |
</t> |
| 362 |
`; |
| 363 |
expect(compileTemplate(arch)).toHaveOuterHTML(expected); |
| 364 |
}); |
| 365 |
|
| 366 |
test("properly compile empty ButtonBox", () => { |
| 367 |
const arch = /*xml*/ ` |
| 368 |
<form> |
| 369 |
<sheet> |
| 370 |
<div class="oe_button_box" name="button_box"> |
| 371 |
</div> |
| 372 |
</sheet> |
| 373 |
</form> |
| 374 |
`; |
| 375 |
const expected = /*xml*/ ` |
| 376 |
<t t-translation="off"> |
| 377 |
<div class="o_form_renderer" t-att-class="__comp__.props.class" t-attf-class="{{__comp__.props.record.isInEdition ? 'o_form_editable' : 'o_form_readonly'}} d-flex d-print-block {{ __comp__.uiService.size < 5 ? "flex-column" : "flex-nowrap h-100" }} {{ __comp__.props.record.dirty ? 'o_form_dirty' : !__comp__.props.record.isNew ? 'o_form_saved' : '' }}" t-ref="compiled_view_root"> |
| 378 |
<div t-on-scroll="__comp__.onScrollThrottled" class="o_form_sheet_bg"> |
| 379 |
<div class="o_form_sheet position-relative"> |
| 380 |
<div class="oe_button_box" name="button_box"> |
| 381 |
</div> |
| 382 |
</div> |
| 383 |
</div> |
| 384 |
</div> |
| 385 |
</t> |
| 386 |
`; |
| 387 |
expect(compileTemplate(arch)).toHaveOuterHTML(expected); |
| 388 |
}); |
| 389 |
|
| 390 |
test("invisible is correctly computed with another t-if", () => { |
| 391 |
patchWithCleanup(FormCompiler.prototype, { |
| 392 |
setup() { |
| 393 |
super.setup(); |
| 394 |
this.compilers.push({ |
| 395 |
selector: "myNode", |
| 396 |
fn: () => { |
| 397 |
const div = createElement("div"); |
| 398 |
div.className = "myNode"; |
| 399 |
div.setAttribute("t-if", "myCondition or myOtherCondition"); |
| 400 |
return div; |
| 401 |
}, |
| 402 |
}); |
| 403 |
}, |
| 404 |
}); |
| 405 |
|
| 406 |
const arch = `<myNode invisible="field == 'value'"/>`; |
| 407 |
const expected = `<t t-translation="off"><div class="myNode" t-if="( myCondition or myOtherCondition ) and !__comp__.evaluateBooleanExpr("field == 'value'",__comp__.props.record.evalContextWithVirtualIds)" t-ref="compiled_view_root"/></t>`; |
| 408 |
expect(compileTemplate(arch)).toHaveOuterHTML(expected); |
| 409 |
}); |
| 410 |
|
| 411 |
test("keep nosheet style if a sheet is part of a nested form", () => { |
| 412 |
const arch = ` |
| 413 |
<form> |
| 414 |
<field name="move_line_ids" field_id="move_line_ids"> |
| 415 |
<form> |
| 416 |
<sheet/> |
| 417 |
</form> |
| 418 |
</field> |
| 419 |
</form>`; |
| 420 |
|
| 421 |
const expected = `<t t-translation="off"> |
| 422 |
<div |
| 423 |
class="o_form_renderer o_form_nosheet" |
| 424 |
t-att-class="__comp__.props.class" |
| 425 |
t-attf-class="{{__comp__.props.record.isInEdition ? 'o_form_editable' : 'o_form_readonly'}} d-block {{ __comp__.props.record.dirty ? 'o_form_dirty' : !__comp__.props.record.isNew ? 'o_form_saved' : '' }}" |
| 426 |
t-ref="compiled_view_root" |
| 427 |
> |
| 428 |
<Field |
| 429 |
id="'move_line_ids'" |
| 430 |
name="'move_line_ids'" |
| 431 |
record="__comp__.props.record" |
| 432 |
fieldInfo="__comp__.props.archInfo.fieldNodes['move_line_ids']" |
| 433 |
readonly="__comp__.props.readonly" |
| 434 |
/> |
| 435 |
</div> |
| 436 |
</t>`; |
| 437 |
expect(compileTemplate(arch)).toHaveOuterHTML(expected); |
| 438 |
}); |
| 439 |
|
| 440 |
test("form with t-translation directive", () => { |
| 441 |
patchWithCleanup(console, { warn: (message) => expect.step(message) }); |
| 442 |
const arch = ` |
| 443 |
<form> |
| 444 |
<div t-translation="off">Hello</div> |
| 445 |
</form>`; |
| 446 |
|
| 447 |
const expected = `<t t-translation="off"> |
| 448 |
<div |
| 449 |
class="o_form_renderer o_form_nosheet" |
| 450 |
t-att-class="__comp__.props.class" |
| 451 |
t-attf-class="{{__comp__.props.record.isInEdition ? 'o_form_editable' : 'o_form_readonly'}} d-block {{ __comp__.props.record.dirty ? 'o_form_dirty' : !__comp__.props.record.isNew ? 'o_form_saved' : '' }}" |
| 452 |
t-ref="compiled_view_root"> |
| 453 |
<div> Hello </div> |
| 454 |
</div> |
| 455 |
</t>`; |
| 456 |
expect(compileTemplate(arch)).toHaveOuterHTML(expected); |
| 457 |
expect.verifySteps([]); // should no log any warning |
| 458 |
}); |