This commit refactors discuss code to use OWL components and new tools and services in web/. Functionally, Discuss app should work relatively the same as before this commit. closes https://github.com/odoo/odoo/pull/110188 Related: https://github.com/odoo/enterprise/pull/38058 https://github.com/odoo/upgrade/pull/4423 closes odoo/odoo#110188 Related: odoo/upgrade#4423 Related: odoo/enterprise#38058 Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com> Co-authored-by: Alexandre (aku) <aku@odoo.com> Co-authored-by: Didier (did) <did@odoo.com> Co-authored-by: Géry (ged) <ged@odoo.com> Co-authored-by: Louis (wil) <wil@odoo.com> Co-authored-by: Maël (mapa) <mapa@odoo.com> Co-authored-by: Maryam (maki) <maki@odoo.com> Co-authored-by: Sébastien (seb) <seb@odoo.com> Co-authored-by: Thanh (tso) <tso@odoo.com> Co-authored-by: Matthieu (tsm) <tsm@odoo.com> Co-authored-by: Zelong (zel) <zel@odoo.com>
96 lines
4.6 KiB
JavaScript
96 lines
4.6 KiB
JavaScript
/** @odoo-module **/
|
|
|
|
import * as utils from "@mail/js/utils";
|
|
|
|
QUnit.module("Mail utils");
|
|
|
|
QUnit.test("add_link utility function", function (assert) {
|
|
const testInputs = {
|
|
"http://admin:password@example.com:8/%2020": true,
|
|
"https://admin:password@example.com/test": true,
|
|
"www.example.com:8/test": true,
|
|
"https://127.0.0.5:8069": true,
|
|
"www.127.0.0.5": false,
|
|
"should.notmatch": false,
|
|
"fhttps://test.example.com/test": false,
|
|
"https://www.transifex.com/odoo/odoo-11/translate/#fr/lunch?q=text%3A'La+Tartiflette'": true,
|
|
"https://www.transifex.com/odoo/odoo-11/translate/#fr/$/119303430?q=text%3ATartiflette": true,
|
|
"https://tenor.com/view/chỗgiặt-dog-smile-gif-13860250": true,
|
|
"http://www.boîtenoire.be": true,
|
|
};
|
|
_.each(testInputs, function (willLinkify, content) {
|
|
const output = utils.parseAndTransform(content, utils.addLink);
|
|
if (willLinkify) {
|
|
assert.strictEqual(output.indexOf("<a "), 0);
|
|
assert.strictEqual(output.indexOf("</a>"), output.length - 4);
|
|
} else {
|
|
assert.strictEqual(output.indexOf("<a "), -1);
|
|
}
|
|
});
|
|
});
|
|
|
|
QUnit.test("addLink: utility function and special entities", function (assert) {
|
|
const testInputs = {
|
|
// textContent not unescaped
|
|
"<p>https://example.com/?&currency_id</p>":
|
|
'<p><a target="_blank" rel="noreferrer noopener" href="https://example.com/?&currency_id">https://example.com/?&currency_id</a></p>',
|
|
// entities not unescaped
|
|
"& &amp; > <": "& &amp; > <",
|
|
// > and " not linkified since they are not in URL regex
|
|
"<p>https://example.com/></p>":
|
|
'<p><a target="_blank" rel="noreferrer noopener" href="https://example.com/">https://example.com/</a>></p>',
|
|
'<p>https://example.com/"hello"></p>':
|
|
'<p><a target="_blank" rel="noreferrer noopener" href="https://example.com/">https://example.com/</a>"hello"></p>',
|
|
// & and ' linkified since they are in URL regex
|
|
"<p>https://example.com/&hello</p>":
|
|
'<p><a target="_blank" rel="noreferrer noopener" href="https://example.com/&hello">https://example.com/&hello</a></p>',
|
|
"<p>https://example.com/'yeah'</p>":
|
|
'<p><a target="_blank" rel="noreferrer noopener" href="https://example.com/\'yeah\'">https://example.com/\'yeah\'</a></p>',
|
|
// normal character should not be escaped
|
|
":'(": ":'(",
|
|
// special character in smileys should be escaped
|
|
"<3": "<3",
|
|
};
|
|
_.each(testInputs, function (result, content) {
|
|
const output = utils.parseAndTransform(content, utils.addLink);
|
|
assert.strictEqual(output, result);
|
|
});
|
|
});
|
|
|
|
QUnit.test("addLink: linkify inside text node (1 occurrence)", function (assert) {
|
|
const content = "<p>some text https://somelink.com</p>";
|
|
const linkified = utils.parseAndTransform(content, utils.addLink);
|
|
assert.ok(linkified.startsWith("<p>some text <a"));
|
|
assert.ok(linkified.endsWith("</a></p>"));
|
|
|
|
// linkify may add some attributes. Since we do not care of their exact
|
|
// stringified representation, we continue deeper assertion with query
|
|
// selectors.
|
|
const fragment = document.createDocumentFragment();
|
|
const div = document.createElement("div");
|
|
fragment.appendChild(div);
|
|
div.innerHTML = linkified;
|
|
assert.strictEqual(div.textContent, "some text https://somelink.com");
|
|
assert.containsOnce(div, "a");
|
|
assert.strictEqual(div.querySelector(":scope a").textContent, "https://somelink.com");
|
|
});
|
|
|
|
QUnit.test("addLink: linkify inside text node (2 occurrences)", function (assert) {
|
|
// linkify may add some attributes. Since we do not care of their exact
|
|
// stringified representation, we continue deeper assertion with query
|
|
// selectors.
|
|
const content = "<p>some text https://somelink.com and again https://somelink2.com ...</p>";
|
|
const linkified = utils.parseAndTransform(content, utils.addLink);
|
|
const fragment = document.createDocumentFragment();
|
|
const div = document.createElement("div");
|
|
fragment.appendChild(div);
|
|
div.innerHTML = linkified;
|
|
assert.strictEqual(
|
|
div.textContent,
|
|
"some text https://somelink.com and again https://somelink2.com ..."
|
|
);
|
|
assert.strictEqual(div.querySelectorAll(":scope a").length, 2);
|
|
assert.strictEqual(div.querySelectorAll(":scope a")[0].textContent, "https://somelink.com");
|
|
assert.strictEqual(div.querySelectorAll(":scope a")[1].textContent, "https://somelink2.com");
|
|
});
|