[REF] web: remove qweb.add_template

This commit removes the qweb.add_template method, which was used to
add a template to qweb. Now we add the templates to the owl app.

Part of task~3443861

Part-of: odoo/odoo#130467
This commit is contained in:
Jorge Pinna Puissant
2023-08-11 14:32:28 +02:00
committed by Samuel Degueldre
parent 7b1d82aa9b
commit 8d16aec14c
@@ -1,13 +1,12 @@
/** @odoo-module **/
import AjaxService from "@web/legacy/js/services/ajax_service";
import core from "@web/legacy/js/services/core";
import Dialog from "@web/legacy/js/core/dialog";
import QWeb from "@web/legacy/js/core/qweb";
import Widget from "@web/legacy/js/core/widget";
import session from "web.session";
import { patchWithCleanup } from "@web/../tests/helpers/utils";
import testUtils from "@web/../tests/legacy/helpers/test_utils";
import { renderToString } from "@web/core/utils/render";
QUnit.module('core', {}, function () {
@@ -180,22 +179,18 @@ QUnit.module('core', {}, function () {
QUnit.test('template', function (assert) {
assert.expect(3);
core.qweb.add_template(
'<no>' +
'<t t-name="test.widget.template">' +
'<ol>' +
'<li t-foreach="5" t-as="counter" ' +
't-attf-class="class-#{counter}">' +
'<input/>' +
'<t t-esc="counter"/>' +
'</li>' +
'</ol>' +
'</t>' +
'</no>'
renderToString.app.addTemplate(
"test.widget.template.1",
`<ol>
<li t-foreach="[0, 1, 2, 3, 4]" t-as="counter" t-key="counter_index" t-attf-class="class-#{counter}">
<input/>
<t t-esc="counter"/>
</li>
</ol>`
);
var widget = new (Widget.extend({
template: 'test.widget.template'
template: 'test.widget.template.1'
}))();
widget.renderElement();
@@ -209,15 +204,14 @@ QUnit.module('core', {}, function () {
assert.expect(4);
var $fix = $( "#qunit-fixture");
core.qweb.add_template(
'<no>' +
'<t t-name="test.widget.template">' +
'<p><t t-esc="widget.value"/></p>' +
'</t>' +
'</no>'
renderToString.app.addTemplate(
"test.widget.template.2",
`<p>
<t t-esc="widget.value"/>
</p>`
);
var widget = new (Widget.extend({
template: 'test.widget.template'
template: 'test.widget.template.2'
}))();
widget.value = 42;
@@ -234,35 +228,23 @@ QUnit.module('core', {}, function () {
});
QUnit.module('Widgets, with QWeb', {
beforeEach: function() {
this.oldQWeb = core.qweb;
core.qweb = new QWeb();
core.qweb.add_template(
'<no>' +
'<t t-name="test.widget.template">' +
'<ol>' +
'<li t-foreach="5" t-as="counter" ' +
't-attf-class="class-#{counter}">' +
'<input/>' +
'<t t-esc="counter"/>' +
'</li>' +
'</ol>' +
'</t>' +
'</no>'
);
},
afterEach: function() {
core.qweb = this.oldQWeb;
},
});
QUnit.module('Widgets, with QWeb');
QUnit.test('basic-alias', function (assert) {
assert.expect(1);
renderToString.app.addTemplate(
"test.widget.template.3",
`<ol>
<li t-foreach="[0,1,2,3,4]" t-as="counter" t-key="counter_index" t-attf-class="class-#{counter}">
<input/>
<t t-esc="counter"/>
</li>
</ol>`
);
var widget = new (Widget.extend({
template: 'test.widget.template'
template: 'test.widget.template.3'
}))();
widget.renderElement();
@@ -275,9 +257,19 @@ QUnit.module('core', {}, function () {
QUnit.test('delegate', async function (assert) {
assert.expect(5);
renderToString.app.addTemplate(
"test.widget.template.4",
`<ol>
<li t-foreach="[0,1,2,3,4]" t-as="counter" t-key="counter_index" t-attf-class="class-#{counter}">
<input/>
<t t-esc="counter"/>
</li>
</ol>`
);
var a = [];
var widget = new (Widget.extend({
template: 'test.widget.template',
template: 'test.widget.template.4',
events: {
'click': function () {
a[0] = true;
@@ -303,11 +295,21 @@ QUnit.module('core', {}, function () {
QUnit.test('undelegate', async function (assert) {
assert.expect(4);
renderToString.app.addTemplate(
"test.widget.template.5",
`<ol>
<li t-foreach="[0,1,2,3,4]" t-as="counter" t-key="counter_index" t-attf-class="class-#{counter}">
<input/>
<t t-esc="counter"/>
</li>
</ol>`
);
var clicked = false;
var newclicked = false;
var widget = new (Widget.extend({
template: 'test.widget.template',
template: 'test.widget.template.5',
events: { 'click li': function () { clicked = true; } }
}))();