* = 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>
277 lines
9.6 KiB
JavaScript
277 lines
9.6 KiB
JavaScript
/* @odoo-module */
|
|
|
|
import { startServer } from "@bus/../tests/helpers/mock_python_environment";
|
|
|
|
import { start } from "@mail/../tests/helpers/test_utils";
|
|
|
|
import { makeDeferred, patchWithCleanup } from "@web/../tests/helpers/utils";
|
|
import { click, contains } from "@web/../tests/utils";
|
|
|
|
QUnit.module("message (patch)");
|
|
|
|
QUnit.test("Sent", async () => {
|
|
const pyEnv = await startServer();
|
|
const partnerId = pyEnv["res.partner"].create({
|
|
name: "Someone",
|
|
partner_share: true,
|
|
});
|
|
const messageId = pyEnv["mail.message"].create({
|
|
body: "not empty",
|
|
message_type: "snailmail",
|
|
model: "res.partner",
|
|
res_id: partnerId,
|
|
});
|
|
pyEnv["mail.notification"].create({
|
|
mail_message_id: messageId,
|
|
notification_status: "sent",
|
|
notification_type: "snail",
|
|
res_partner_id: partnerId,
|
|
});
|
|
const { openFormView } = await start();
|
|
openFormView("res.partner", partnerId);
|
|
await click(".o-mail-Message-notification i.fa-paper-plane");
|
|
await contains(".o-snailmail-SnailmailNotificationPopover i.fa-check");
|
|
await contains(".o-snailmail-SnailmailNotificationPopover", { text: "Sent" });
|
|
});
|
|
|
|
QUnit.test("Canceled", async () => {
|
|
const pyEnv = await startServer();
|
|
const partnerId = pyEnv["res.partner"].create({
|
|
name: "Someone",
|
|
partner_share: true,
|
|
});
|
|
const messageId = pyEnv["mail.message"].create({
|
|
body: "not empty",
|
|
message_type: "snailmail",
|
|
model: "res.partner",
|
|
res_id: partnerId,
|
|
});
|
|
pyEnv["mail.notification"].create({
|
|
mail_message_id: messageId,
|
|
notification_status: "canceled",
|
|
notification_type: "snail",
|
|
res_partner_id: partnerId,
|
|
});
|
|
const { openFormView } = await start();
|
|
openFormView("res.partner", partnerId);
|
|
await click(".o-mail-Message-notification i.fa-paper-plane");
|
|
await contains(".o-snailmail-SnailmailNotificationPopover i.fa-trash-o");
|
|
await contains(".o-snailmail-SnailmailNotificationPopover", { text: "Canceled" });
|
|
});
|
|
|
|
QUnit.test("Pending", async () => {
|
|
const pyEnv = await startServer();
|
|
const partnerId = pyEnv["res.partner"].create({
|
|
name: "Someone",
|
|
partner_share: true,
|
|
});
|
|
const messageId = pyEnv["mail.message"].create({
|
|
body: "not empty",
|
|
message_type: "snailmail",
|
|
model: "res.partner",
|
|
res_id: partnerId,
|
|
});
|
|
pyEnv["mail.notification"].create({
|
|
mail_message_id: messageId,
|
|
notification_status: "ready",
|
|
notification_type: "snail",
|
|
res_partner_id: partnerId,
|
|
});
|
|
const { openFormView } = await start();
|
|
openFormView("res.partner", partnerId);
|
|
await click(".o-mail-Message-notification i.fa-paper-plane");
|
|
await contains(".o-snailmail-SnailmailNotificationPopover i.fa-clock-o");
|
|
await contains(".o-snailmail-SnailmailNotificationPopover", { text: "Awaiting Dispatch" });
|
|
});
|
|
|
|
QUnit.test("No Price Available", async (assert) => {
|
|
const pyEnv = await startServer();
|
|
const partnerId = pyEnv["res.partner"].create({
|
|
name: "Someone",
|
|
partner_share: true,
|
|
});
|
|
const messageId = pyEnv["mail.message"].create({
|
|
body: "not empty",
|
|
message_type: "snailmail",
|
|
model: "res.partner",
|
|
res_id: partnerId,
|
|
});
|
|
pyEnv["mail.notification"].create({
|
|
failure_type: "sn_price",
|
|
mail_message_id: messageId,
|
|
notification_status: "exception",
|
|
notification_type: "snail",
|
|
res_partner_id: partnerId,
|
|
});
|
|
const { openFormView } = await start({
|
|
async mockRPC(route, args) {
|
|
if (
|
|
args.method === "cancel_letter" &&
|
|
args.model === "mail.message" &&
|
|
args.args[0][0] === messageId
|
|
) {
|
|
assert.step(args.method);
|
|
}
|
|
},
|
|
});
|
|
openFormView("res.partner", partnerId);
|
|
await click(".o-mail-Message-notification i.fa-paper-plane");
|
|
await contains(".o-snailmail-SnailmailError .modal-body", {
|
|
text: "The country to which you want to send the letter is not supported by our service.",
|
|
});
|
|
await click("button", { text: "Cancel letter" });
|
|
await contains(".o-snailmail-SnailmailError", { count: 0 });
|
|
assert.verifySteps(["cancel_letter"]);
|
|
});
|
|
|
|
QUnit.test("Credit Error", async (assert) => {
|
|
const pyEnv = await startServer();
|
|
const partnerId = pyEnv["res.partner"].create({
|
|
name: "Someone",
|
|
partner_share: true,
|
|
});
|
|
const messageId = pyEnv["mail.message"].create({
|
|
body: "not empty",
|
|
message_type: "snailmail",
|
|
model: "res.partner",
|
|
res_id: partnerId,
|
|
});
|
|
pyEnv["mail.notification"].create({
|
|
failure_type: "sn_credit",
|
|
mail_message_id: messageId,
|
|
notification_status: "exception",
|
|
notification_type: "snail",
|
|
res_partner_id: partnerId,
|
|
});
|
|
const { openFormView } = await start({
|
|
async mockRPC(route, args) {
|
|
if (
|
|
args.method === "send_letter" &&
|
|
args.model === "mail.message" &&
|
|
args.args[0][0] === messageId
|
|
) {
|
|
assert.step(args.method);
|
|
}
|
|
},
|
|
});
|
|
openFormView("res.partner", partnerId);
|
|
await click(".o-mail-Message-notification i.fa-paper-plane");
|
|
await contains(".o-snailmail-SnailmailError p", {
|
|
text: "The letter could not be sent due to insufficient credits on your IAP account.",
|
|
});
|
|
await contains("button", { text: "Cancel letter" });
|
|
await click("button", { text: "Re-send letter" });
|
|
await contains(".o-snailmail-SnailmailError", { count: 0 });
|
|
assert.verifySteps(["send_letter"]);
|
|
});
|
|
|
|
QUnit.test("Trial Error", async (assert) => {
|
|
const pyEnv = await startServer();
|
|
const partnerId = pyEnv["res.partner"].create({
|
|
name: "Someone",
|
|
partner_share: true,
|
|
});
|
|
const messageId = pyEnv["mail.message"].create({
|
|
body: "not empty",
|
|
message_type: "snailmail",
|
|
model: "res.partner",
|
|
res_id: partnerId,
|
|
});
|
|
pyEnv["mail.notification"].create({
|
|
failure_type: "sn_trial",
|
|
mail_message_id: messageId,
|
|
notification_status: "exception",
|
|
notification_type: "snail",
|
|
res_partner_id: partnerId,
|
|
});
|
|
const { openFormView } = await start({
|
|
async mockRPC(route, args) {
|
|
if (
|
|
args.method === "send_letter" &&
|
|
args.model === "mail.message" &&
|
|
args.args[0][0] === messageId
|
|
) {
|
|
assert.step(args.method);
|
|
}
|
|
},
|
|
});
|
|
openFormView("res.partner", partnerId);
|
|
await click(".o-mail-Message-notification i.fa-paper-plane");
|
|
await contains(".o-snailmail-SnailmailError p", {
|
|
text: "You need credits on your IAP account to send a letter.",
|
|
});
|
|
await contains("button", { text: "Cancel letter" });
|
|
await click("button", { text: "Re-send letter" });
|
|
await contains(".o-snailmail-SnailmailError", { count: 0 });
|
|
assert.verifySteps(["send_letter"]);
|
|
});
|
|
|
|
QUnit.test("Format Error", async (assert) => {
|
|
const openFormatErrorActionDef = makeDeferred();
|
|
const pyEnv = await startServer();
|
|
const partnerId = pyEnv["res.partner"].create({
|
|
name: "Someone",
|
|
partner_share: true,
|
|
});
|
|
const messageId = pyEnv["mail.message"].create({
|
|
body: "not empty",
|
|
message_type: "snailmail",
|
|
model: "res.partner",
|
|
res_id: partnerId,
|
|
});
|
|
pyEnv["mail.notification"].create({
|
|
failure_type: "sn_format",
|
|
mail_message_id: messageId,
|
|
notification_status: "exception",
|
|
notification_type: "snail",
|
|
res_partner_id: partnerId,
|
|
});
|
|
const { env, openFormView } = await start();
|
|
openFormView("res.partner", partnerId);
|
|
patchWithCleanup(env.services.action, {
|
|
doAction(action, options) {
|
|
assert.step("do_action");
|
|
assert.strictEqual(action, "snailmail.snailmail_letter_format_error_action");
|
|
assert.strictEqual(options.additionalContext.message_id, messageId);
|
|
openFormatErrorActionDef.resolve();
|
|
},
|
|
});
|
|
await click(".o-mail-Message-notification i.fa-paper-plane");
|
|
await openFormatErrorActionDef;
|
|
assert.verifySteps(["do_action"]);
|
|
});
|
|
|
|
QUnit.test("Missing Required Fields", async (assert) => {
|
|
const openRequiredFieldsActionDef = makeDeferred();
|
|
const pyEnv = await startServer();
|
|
const partnerId = pyEnv["res.partner"].create({});
|
|
const messageId = pyEnv["mail.message"].create({
|
|
body: "not empty",
|
|
message_type: "snailmail",
|
|
res_id: partnerId,
|
|
model: "res.partner",
|
|
});
|
|
pyEnv["mail.notification"].create({
|
|
failure_type: "sn_fields",
|
|
mail_message_id: messageId,
|
|
notification_status: "exception",
|
|
notification_type: "snail",
|
|
});
|
|
const snailMailLetterId1 = pyEnv["snailmail.letter"].create({
|
|
message_id: messageId,
|
|
});
|
|
const { env, openFormView } = await start();
|
|
openFormView("res.partner", partnerId);
|
|
patchWithCleanup(env.services.action, {
|
|
doAction(action, options) {
|
|
assert.step("do_action");
|
|
assert.strictEqual(action, "snailmail.snailmail_letter_missing_required_fields_action");
|
|
assert.strictEqual(options.additionalContext.default_letter_id, snailMailLetterId1);
|
|
openRequiredFieldsActionDef.resolve();
|
|
},
|
|
});
|
|
await click(".o-mail-Message-notification i.fa-paper-plane");
|
|
await openRequiredFieldsActionDef;
|
|
assert.verifySteps(["do_action"]);
|
|
});
|