Files
odoo_source/addons/test_mail/static/tests/chatter_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

106 lines
3.5 KiB
JavaScript

/** @odoo-module **/
import { start, startServer } from "@mail/../tests/helpers/test_utils";
QUnit.module("chatter");
QUnit.test("Send message button activation (access rights dependent)", async function (assert) {
const pyEnv = await startServer();
const view = `
<form string="Simple">
<sheet>
<field name="name"/>
</sheet>
<div class="oe_chatter">
<field name="message_ids"/>
</div>
</form>`;
let userAccess = {};
const { openView } = await start({
serverData: {
views: {
"mail.test.multi.company,false,form": view,
"mail.test.multi.company.read,false,form": view,
},
},
async mockRPC(route, args, performRPC) {
const res = await performRPC(route, args);
if (route === "/mail/thread/data") {
// mimic user with custom access defined in userAccess variable
const { thread_model } = args;
Object.assign(res, userAccess);
res["canPostOnReadonly"] = thread_model === "mail.test.multi.company.read";
}
return res;
},
});
const simpleId = pyEnv["mail.test.multi.company"].create({ name: "Test MC Simple" });
const simpleMcId = pyEnv["mail.test.multi.company.read"].create({
name: "Test MC Readonly",
});
async function assertSendButton(
enabled,
msg,
model = null,
resId = null,
hasReadAccess = false,
hasWriteAccess = false
) {
userAccess = { hasReadAccess, hasWriteAccess };
await openView({
res_id: resId,
res_model: model,
views: [[false, "form"]],
});
const details = `hasReadAccess: ${hasReadAccess}, hasWriteAccess: ${hasWriteAccess}, model: ${model}, resId: ${resId}`;
if (enabled) {
assert.containsNone(
document.body,
".o-mail-Chatter-topbar button:contains(Send message):disabled",
`${msg}: send message button must not be disabled (${details}`
);
} else {
assert.containsOnce(
document.body,
".o-mail-Chatter-topbar button:contains(Send message):disabled",
`${msg}: send message button must be disabled (${details})`
);
}
}
await assertSendButton(
true,
"Record, all rights",
"mail.test.multi.company",
simpleId,
true,
true
);
await assertSendButton(
true,
"Record, all rights",
"mail.test.multi.company.read",
simpleId,
true,
true
);
await assertSendButton(
false,
"Record, no write access",
"mail.test.multi.company",
simpleId,
true
);
await assertSendButton(
true,
"Record, read access but model accept post with read only access",
"mail.test.multi.company.read",
simpleMcId,
true
);
await assertSendButton(false, "Record, no rights", "mail.test.multi.company", simpleId);
await assertSendButton(false, "Record, no rights", "mail.test.multi.company.read", simpleMcId);
// Note that rights have no impact on send button for draft record (chatter.isTemporary=true)
await assertSendButton(true, "Draft record", "mail.test.multi.company");
await assertSendButton(true, "Draft record", "mail.test.multi.company.read");
});