Files
odoo_source/addons/mail/static/tests/web/follow_button_tests.js
T
Sébastien Theys 7ea370fce7 [REF] mail, *: tests: refactor contains to further remove jQuery
* = account, base_iban, bus, calendar, crm_livechat, hr, hr_holidays,
    im_livechat, mrp, project, sms, snailmail, test_mail,
    test_mail_full, web, website_livechat, website_slides

Add support in `contains` for most operations that we use in tests.
Remove return value from `contains`.
Move into `web` module.
Remove import/export chains, directly import from correct module.

closes odoo/odoo#134652

Related: odoo/enterprise#47064
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2023-09-14 11:22:47 +00:00

94 lines
3.0 KiB
JavaScript

/* @odoo-module */
import { startServer } from "@bus/../tests/helpers/mock_python_environment";
import { start } from "@mail/../tests/helpers/test_utils";
import { click, contains } from "@web/../tests/utils";
QUnit.module("follow button");
QUnit.test("base rendering not editable", async () => {
const { openView, pyEnv } = await start();
openView({
res_id: pyEnv.currentPartnerId,
res_model: "res.partner",
views: [[false, "form"]],
});
await contains(".o-mail-Chatter-follow");
});
QUnit.test("hover following button", async () => {
const pyEnv = await startServer();
const threadId = pyEnv["res.partner"].create({});
pyEnv["mail.followers"].create({
is_active: true,
partner_id: pyEnv.currentPartnerId,
res_id: threadId,
res_model: "res.partner",
});
const { openView } = await start();
openView({
res_id: threadId,
res_model: "res.partner",
views: [[false, "form"]],
});
await contains(".fa-check + span", { text: "Following" });
await contains(".fa-times + span", { count: 0, text: "Following" });
$("button:contains(Following)")[0].dispatchEvent(new window.MouseEvent("mouseenter"));
await contains(".fa-times + span", { text: "Unfollow" });
await contains(".fa-check + span", { count: 0, text: "Unfollow" });
});
QUnit.test('click on "follow" button', async () => {
const { openView, pyEnv } = await start();
openView({
res_id: pyEnv.currentPartnerId,
res_model: "res.partner",
views: [[false, "form"]],
});
await contains("button span", { text: "Follow" });
await click("button span", { text: "Follow" });
await contains("button span", { text: "Following" });
});
QUnit.test('Click on "follow" button should save draft record', async () => {
const views = {
"res.partner,false,form": `
<form string="Partners">
<sheet>
<field name="name" required="1"/>
</sheet>
<div class="oe_chatter">
<field name="message_follower_ids"/>
</div>
</form>`,
};
const { openFormView } = await start({ serverData: { views } });
openFormView("res.partner");
await contains("button span", { text: "Follow" });
await contains("div.o_field_char");
await click("button span", { text: "Follow" });
await contains("div.o_field_invalid");
});
QUnit.test('click on "unfollow" button', async () => {
const pyEnv = await startServer();
const threadId = pyEnv["res.partner"].create({});
pyEnv["mail.followers"].create({
is_active: true,
partner_id: pyEnv.currentPartnerId,
res_id: threadId,
res_model: "res.partner",
});
const { openView } = await start();
openView({
res_id: threadId,
res_model: "res.partner",
views: [[false, "form"]],
});
await click(".fa-check + span", { text: "Following" });
await contains("button span", { text: "Follow" });
});