Files
odoo_source/addons/mail/static/tests/web/attachment_box_tests.js
T
7710c3331e [REF] mail, *: refactor Discuss
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>
2023-03-17 11:47:09 +01:00

209 lines
6.9 KiB
JavaScript

/** @odoo-module **/
import { patchUiSize, SIZES } from "@mail/../tests/helpers/patch_ui_size";
import { afterNextRender, click, start, startServer } from "@mail/../tests/helpers/test_utils";
QUnit.module("attachment box");
QUnit.test("base empty rendering", async (assert) => {
const pyEnv = await startServer();
const partnerId = pyEnv["res.partner"].create({});
const views = {
"res.partner,false,form": `
<form>
<sheet></sheet>
<div class="oe_chatter">
<field name="message_ids" options="{'open_attachments': True}"/>
</div>
</form>
`,
};
const { openView } = await start({ serverData: { views } });
await openView({
res_id: partnerId,
res_model: "res.partner",
views: [[false, "form"]],
});
assert.containsOnce($, ".o-mail-AttachmentBox");
assert.containsOnce($, "button:contains('Attach files')");
assert.containsNone($, ".o-mail-Chatter .o-mail-AttachmentImage");
});
QUnit.test("base non-empty rendering", async (assert) => {
const pyEnv = await startServer();
const partnerId = pyEnv["res.partner"].create({});
pyEnv["ir.attachment"].create([
{
mimetype: "text/plain",
name: "Blah.txt",
res_id: partnerId,
res_model: "res.partner",
},
{
mimetype: "text/plain",
name: "Blu.txt",
res_id: partnerId,
res_model: "res.partner",
},
]);
const views = {
"res.partner,false,form": `
<form>
<sheet></sheet>
<div class="oe_chatter">
<field name="message_ids" options="{'open_attachments': True}"/>
</div>
</form>
`,
};
const { openView } = await start({ serverData: { views } });
await openView({
res_id: partnerId,
res_model: "res.partner",
views: [[false, "form"]],
});
assert.containsOnce($, ".o-mail-AttachmentBox");
assert.containsOnce($, "button:contains('Attach files')");
assert.containsOnce($, ".o-mail-Chatter input[type='file']");
assert.containsOnce($, ".o-mail-AttachmentList");
});
QUnit.test("remove attachment should ask for confirmation", async (assert) => {
const pyEnv = await startServer();
const partnerId = pyEnv["res.partner"].create({});
pyEnv["ir.attachment"].create({
mimetype: "text/plain",
name: "Blah.txt",
res_id: partnerId,
res_model: "res.partner",
});
const views = {
"res.partner,false,form": `
<form>
<sheet></sheet>
<div class="oe_chatter">
<field name="message_ids" options="{'open_attachments': True}"/>
</div>
</form>
`,
};
const { openView } = await start({ serverData: { views } });
await openView({
res_id: partnerId,
res_model: "res.partner",
views: [[false, "form"]],
});
assert.containsOnce($, ".o-mail-AttachmentCard");
assert.containsOnce($, "button[title='Remove']");
await click("button[title='Remove']");
assert.containsOnce($, ".modal-body:contains('Do you really want to delete \"Blah.txt\"?')");
// Confirm the deletion
await click(".modal-footer .btn-primary");
assert.containsNone($, ".o-mail-AttachmentImage");
});
QUnit.test("view attachments", async (assert) => {
const pyEnv = await startServer();
const partnerId = pyEnv["res.partner"].create({});
pyEnv["ir.attachment"].create([
{
mimetype: "text/plain",
name: "Blah.txt",
res_id: partnerId,
res_model: "res.partner",
},
{
mimetype: "text/plain",
name: "Blu.txt",
res_id: partnerId,
res_model: "res.partner",
},
]);
const views = {
"res.partner,false,form": `<form>
<sheet></sheet>
<div class="oe_chatter">
<field name="message_ids" options="{'open_attachments': True}"/>
</div>
</form>`,
};
const { openView } = await start({ serverData: { views } });
await openView({
res_id: partnerId,
res_model: "res.partner",
views: [[false, "form"]],
});
await click('.o-mail-AttachmentCard[aria-label="Blah.txt"] .o-mail-AttachmentCard-image');
assert.containsOnce($, ".o-mail-AttachmentViewer");
assert.containsOnce($, ".o-mail-AttachmentViewer-header:contains(Blah.txt)");
assert.containsOnce($, ".o-mail-AttachmentViewer div[aria-label='Next']");
await click(".o-mail-AttachmentViewer div[aria-label='Next']");
assert.containsOnce($, ".o-mail-AttachmentViewer-header:contains(Blu.txt)");
assert.containsOnce($, ".o-mail-AttachmentViewer div[aria-label='Next']");
await click(".o-mail-AttachmentViewer div[aria-label='Next']");
assert.containsOnce($, ".o-mail-AttachmentViewer-header:contains(Blah.txt)");
});
QUnit.test("scroll to attachment box when toggling on", async (assert) => {
patchUiSize({ size: SIZES.XXL });
const pyEnv = await startServer();
const partnerId = pyEnv["res.partner"].create({});
for (let i = 0; i < 30; i++) {
pyEnv["mail.message"].create({
body: "not empty".repeat(50),
model: "res.partner",
res_id: partnerId,
});
}
pyEnv["ir.attachment"].create({
mimetype: "text/plain",
name: "Blah.txt",
res_id: partnerId,
res_model: "res.partner",
});
const { openView } = await start();
await openView({
res_id: partnerId,
res_model: "res.partner",
views: [[false, "form"]],
});
$(".o-mail-Chatter-scrollable").scrollTop(10 * 1000); // to bottom
assert.notEqual($(".o-mail-Chatter-scrollable").scrollTop(), 0);
await click("i.fa-paperclip");
assert.strictEqual($(".o-mail-Chatter-scrollable").scrollTop(), 0);
});
QUnit.test("scroll to attachment box when toggling on", async (assert) => {
patchUiSize({ size: SIZES.XXL });
const pyEnv = await startServer();
const partnerId = pyEnv["res.partner"].create({});
for (let i = 0; i < 30; i++) {
pyEnv["mail.message"].create({
body: "not empty".repeat(50),
model: "res.partner",
res_id: partnerId,
});
}
pyEnv["ir.attachment"].create({
mimetype: "text/plain",
name: "Blah.txt",
res_id: partnerId,
res_model: "res.partner",
});
const { openView } = await start();
await openView({
res_id: partnerId,
res_model: "res.partner",
views: [[false, "form"]],
});
await afterNextRender(() => {
$(".o-mail-Chatter-scrollable").scrollTop(10 * 1000); // to bottom
});
await click("button[aria-label='Attach files']");
assert.strictEqual($(".o-mail-Chatter-scrollable").scrollTop(), 0);
});