Files
odoo_source/addons/mail/static/tests/web/follower_tests.js
T
Sébastien Theys 9dba4e0d77 [REF] mail, *: reorganize JS files
Remove "fake" feature sub-folders that make files harder to find.

Note: If there are too many files in the main folder now, a new split
that actually makes sense can be done at a later time: this would not
just be code move, but removing coupling between said feature and the
rest of the code.

Apply consistent structure, where the top level folder is a feature (or
core), and sub-folders are subdivision of the feature depending on
context (closely related to assets bundles).

```
- core
    - common
    - public
    - web
- feature
    - common
    - public
    - web
```

The opportunity is taken to reorganize the top of the files and imports:
- Always use absolute path in imports to be able to find all usages of a
  file with a single search.
- Reorganize imports to group them by module, and to sort them
  alphabetically by path/feature.
- Always use single asterisk (*) for `odoo-module`: less characters yay!
  And double asterisk should be used for JSDoc comments, not for custom
  instructions.

Part of task-3265211

closes odoo/odoo#124168

Related: odoo/enterprise#42121
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2023-06-08 21:52:44 +02:00

220 lines
7.9 KiB
JavaScript

/* @odoo-module */
import { click, nextAnimationFrame, start, startServer } from "@mail/../tests/helpers/test_utils";
import { editInput, makeDeferred, patchWithCleanup } from "@web/../tests/helpers/utils";
QUnit.module("follower");
QUnit.test("base rendering not editable", async (assert) => {
const pyEnv = await startServer();
const [threadId, partnerId] = pyEnv["res.partner"].create([{}, {}]);
pyEnv["mail.followers"].create({
is_active: true,
partner_id: partnerId,
res_id: threadId,
res_model: "res.partner",
});
const { openView } = await start({
async mockRPC(route, args, performRpc) {
if (route === "/mail/thread/data") {
// mimic user without write access
const res = await performRpc(...arguments);
res["hasWriteAccess"] = false;
return res;
}
},
});
await openView({
res_id: threadId,
res_model: "res.partner",
views: [[false, "form"]],
});
await click(".o-mail-Followers-button");
assert.containsOnce($, ".o-mail-Follower");
assert.containsOnce($, ".o-mail-Follower-details");
assert.containsOnce($, ".o-mail-Follower-avatar");
assert.containsNone($, ".o-mail-Follower-action");
});
QUnit.test("base rendering editable", async (assert) => {
const pyEnv = await startServer();
const [threadId, partnerId] = pyEnv["res.partner"].create([{}, {}]);
pyEnv["mail.followers"].create({
is_active: true,
partner_id: partnerId,
res_id: threadId,
res_model: "res.partner",
});
const { openView } = await start();
await openView({
res_id: threadId,
res_model: "res.partner",
views: [[false, "form"]],
});
await click(".o-mail-Followers-button");
assert.containsOnce($, ".o-mail-Follower");
assert.containsOnce($, ".o-mail-Follower-details");
assert.containsOnce($, ".o-mail-Follower-avatar");
assert.containsOnce($, ".o-mail-Follower");
assert.containsOnce($, "button[title='Edit subscription']");
assert.containsOnce($, "button[title='Remove this follower']");
});
QUnit.test("click on partner follower details", async (assert) => {
const pyEnv = await startServer();
const [threadId, partnerId] = pyEnv["res.partner"].create([{}, {}]);
pyEnv["mail.followers"].create({
is_active: true,
partner_id: partnerId,
res_id: threadId,
res_model: "res.partner",
});
const openFormDef = makeDeferred();
const { env, openView } = await start();
await openView({
res_id: threadId,
res_model: "res.partner",
views: [[false, "form"]],
});
patchWithCleanup(env.services.action, {
doAction(action) {
assert.step("do_action");
assert.strictEqual(action.res_id, partnerId);
assert.strictEqual(action.res_model, "res.partner");
assert.strictEqual(action.type, "ir.actions.act_window");
openFormDef.resolve();
},
});
await click(".o-mail-Followers-button");
assert.containsOnce($, ".o-mail-Follower");
assert.containsOnce($, ".o-mail-Follower-details");
$(".o-mail-Follower-details")[0].click();
await openFormDef;
assert.verifySteps(["do_action"], "redirect to partner profile");
});
QUnit.test("click on edit follower", async (assert) => {
const pyEnv = await startServer();
const [threadId, partnerId] = pyEnv["res.partner"].create([{}, {}]);
pyEnv["mail.followers"].create({
is_active: true,
partner_id: partnerId,
res_id: threadId,
res_model: "res.partner",
});
const { openView } = await start({
async mockRPC(route, args) {
if (route.includes("/mail/read_subscription_data")) {
assert.step("fetch_subtypes");
}
},
});
await openView({
res_id: threadId,
res_model: "res.partner",
views: [[false, "form"]],
});
await click(".o-mail-Followers-button");
assert.containsOnce($, ".o-mail-Follower");
assert.containsOnce($, "button[title='Edit subscription']");
await click("button[title='Edit subscription']");
assert.verifySteps(["fetch_subtypes"]);
assert.containsOnce($, ".o-mail-FollowerSubtypeDialog");
});
QUnit.test("edit follower and close subtype dialog", async (assert) => {
const pyEnv = await startServer();
const [threadId, partnerId] = pyEnv["res.partner"].create([{}, {}]);
pyEnv["mail.followers"].create({
is_active: true,
partner_id: partnerId,
res_id: threadId,
res_model: "res.partner",
});
const { openView } = await start({
async mockRPC(route, args) {
if (route.includes("/mail/read_subscription_data")) {
assert.step("fetch_subtypes");
}
},
});
await openView({
res_id: threadId,
res_model: "res.partner",
views: [[false, "form"]],
});
await click(".o-mail-Followers-button");
assert.containsOnce($, ".o-mail-Follower");
assert.containsOnce($, "button[title='Edit subscription']");
await click("button[title='Edit subscription']");
assert.verifySteps(["fetch_subtypes"]);
assert.containsOnce($, ".o-mail-FollowerSubtypeDialog");
await click(".o-mail-FollowerSubtypeDialog button:contains(Cancel)");
assert.containsNone($, ".o-mail-FollowerSubtypeDialog");
});
QUnit.test("remove a follower in a dirty form view", async (assert) => {
const pyEnv = await startServer();
const [threadId, partnerId] = pyEnv["res.partner"].create([{}, {}]);
pyEnv["discuss.channel"].create({ name: "General", display_name: "General" });
pyEnv["mail.followers"].create({
is_active: true,
partner_id: partnerId,
res_id: threadId,
res_model: "res.partner",
});
const views = {
"res.partner,false,form": `
<form>
<field name="name"/>
<field name="channel_ids" widget="many2many_tags" options="{'color_field': 'color'}"/>
<div class="oe_chatter">
<field name="message_ids"/>
<field name="message_follower_ids"/>
</div>
</form>`,
};
const { openFormView } = await start({ serverData: { views } });
await openFormView("res.partner", threadId);
click(".o_field_many2many_tags[name='channel_ids'] input").catch(() => {});
await nextAnimationFrame();
click(".dropdown-item:contains(General)").catch(() => {});
await nextAnimationFrame();
assert.containsOnce($, ".o_tag:contains(General)");
assert.strictEqual($(".o-mail-Followers-counter")[0].innerText, "1");
await editInput(document.body, ".o_field_char[name=name] input", "some value");
await click(".o-mail-Followers-button");
await click("button[title='Remove this follower']");
assert.strictEqual($(".o-mail-Followers-counter")[0].innerText, "0");
assert.strictEqual($(".o_field_char[name=name] input").val(), "some value");
assert.containsOnce($, ".o_tag:contains(General)");
});
QUnit.test("removing a follower should reload form view", async function (assert) {
const pyEnv = await startServer();
const [threadId, partnerId] = pyEnv["res.partner"].create([{}, {}]);
pyEnv["mail.followers"].create({
is_active: true,
partner_id: partnerId,
res_id: threadId,
res_model: "res.partner",
});
const { openFormView } = await start({
async mockRPC(route, args) {
if (args.method === "read") {
assert.step(`read ${args.args[0][0]}`);
}
},
});
await openFormView("res.partner", threadId);
assert.verifySteps([`read ${threadId}`]);
await click(".o-mail-Followers-button");
await click("button[title='Remove this follower']");
assert.verifySteps([`read ${threadId}`]);
});