19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:30:27 +01:00
parent d1963a3c3a
commit 2d3ee4855a
7430 changed files with 2687981 additions and 2965473 deletions

View file

@ -1,58 +0,0 @@
/** @odoo-module **/
import '@mail/../tests/helpers/mock_server'; // ensure mail overrides are applied first
import { patch } from "@web/core/utils/patch";
import { MockServer } from "@web/../tests/helpers/mock_server";
patch(MockServer.prototype, 'snailmail', {
//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
/**
* @override
*/
async performRPC(route, args) {
if (args.model === 'mail.message' && args.method === 'cancel_letter') {
const ids = args.args[0];
return this._mockMailMessageCancelLetter(ids);
}
if (args.model === 'mail.message' && args.method === 'send_letter') {
const ids = args.args[0];
return this._mockMailMessageSendLetter(ids);
}
if (args.method === 'get_credits_url') {
// random value returned in order for the mock server to know that this route is implemented.
return true;
}
return this._super(...arguments);
},
//--------------------------------------------------------------------------
// Private Mocked Methods
//--------------------------------------------------------------------------
/**
* Simulates `cancel_letter` on `mail.message`.
*
* @private
* @param {integer[]} ids
*/
_mockMailMessageCancelLetter(ids) {
// TODO implement this mock and improve related tests (task-2300496)
// random value returned in order for the mock server to know that this route is implemented.
return true;
},
/**
* Simulates `send_letter` on `mail.message`.
*
* @private
* @param {integer[]} ids
*/
_mockMailMessageSendLetter(ids) {
// TODO implement this mock and improve related tests (task-2300496)
// random value returned in order for the mock server to know that this route is implemented.
return true;
},
});

View file

@ -1,5 +0,0 @@
/** @odoo-module **/
import { addModelNamesToFetch } from '@bus/../tests/helpers/model_definitions_helpers';
addModelNamesToFetch(['snailmail.letter']);

View file

@ -0,0 +1,218 @@
import {
click,
contains,
openFormView,
start,
startServer,
} from "@mail/../tests/mail_test_helpers";
import { describe, test } from "@odoo/hoot";
import { defineSnailmailModels } from "../snailmail_test_helpers";
describe.current.tags("desktop");
defineSnailmailModels();
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,
});
await start();
await 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" });
});
test("Cancelled", 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,
});
await start();
await 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: "Cancelled" });
});
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,
});
await start();
await 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" });
});
test("No Price Available", 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({
failure_type: "sn_price",
mail_message_id: messageId,
notification_status: "exception",
notification_type: "snail",
res_partner_id: partnerId,
});
await start();
await openFormView("res.partner", partnerId);
await click(".o-mail-Message-notification i.fa-paper-plane");
await contains(".o-snailmail-SnailmailNotificationPopover", {
text: "(Country Not Supported)",
});
});
test("Credit Error", 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({
failure_type: "sn_credit",
mail_message_id: messageId,
notification_status: "exception",
notification_type: "snail",
res_partner_id: partnerId,
});
await start();
await openFormView("res.partner", partnerId);
await click(".o-mail-Message-notification i.fa-paper-plane");
await contains(".o-snailmail-SnailmailNotificationPopover", {
text: "(Insufficient Credits)",
});
});
test("Trial Error", 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({
failure_type: "sn_trial",
mail_message_id: messageId,
notification_status: "exception",
notification_type: "snail",
res_partner_id: partnerId,
});
await start();
await openFormView("res.partner", partnerId);
await click(".o-mail-Message-notification i.fa-paper-plane");
await contains(".o-snailmail-SnailmailNotificationPopover", {
text: "(No IAP Credits)",
});
});
test("Format Error", 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({
failure_type: "sn_format",
mail_message_id: messageId,
notification_status: "exception",
notification_type: "snail",
res_partner_id: partnerId,
});
await start();
await openFormView("res.partner", partnerId);
await click(".o-mail-Message-notification i.fa-paper-plane");
await contains(".o-snailmail-SnailmailNotificationPopover", {
text: "(Format Error)",
});
});
test("Missing Required Fields", async () => {
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",
});
await start();
await openFormView("res.partner", partnerId);
await click(".o-mail-Message-notification i.fa-paper-plane");
await contains(".o-snailmail-SnailmailNotificationPopover", {
text: "(Missing Required Fields)",
});
});

View file

@ -0,0 +1,150 @@
import {
click,
contains,
start,
startServer,
triggerEvents,
} from "@mail/../tests/mail_test_helpers";
import { describe, expect, test } from "@odoo/hoot";
import { defineSnailmailModels } from "@snailmail/../tests/snailmail_test_helpers";
import { asyncStep, mockService, serverState, waitForSteps } from "@web/../tests/web_test_helpers";
describe.current.tags("desktop");
defineSnailmailModels();
test("mark as read", async () => {
const pyEnv = await startServer();
const messageId = pyEnv["mail.message"].create({
message_type: "snailmail",
model: "res.partner",
res_id: serverState.partnerId,
});
pyEnv["mail.notification"].create({
mail_message_id: messageId,
notification_status: "exception",
notification_type: "snail",
});
await start();
await click(".o_menu_systray i[aria-label='Messages']");
await contains(".o-mail-NotificationItem");
await triggerEvents(".o-mail-NotificationItem", ["mouseenter"]);
await contains(".o-mail-NotificationItem-text", {
text: "An error occurred when sending a letter with Snailmail on “Mitchell Admin”",
});
await click(".o-mail-NotificationItem [title='Mark As Read']");
await contains(".o-mail-NotificationItem", { count: 0 });
});
test("notifications grouped by notification_type", async () => {
const pyEnv = await startServer();
const partnerId = pyEnv["res.partner"].create({});
const [messageId_1, messageId_2] = pyEnv["mail.message"].create([
{
message_type: "snailmail",
model: "res.partner",
res_id: partnerId,
},
{
message_type: "email",
model: "res.partner",
res_id: partnerId,
},
]);
pyEnv["mail.notification"].create([
{
mail_message_id: messageId_1,
notification_status: "exception",
notification_type: "snail",
},
{
mail_message_id: messageId_1,
notification_status: "exception",
notification_type: "snail",
},
{
mail_message_id: messageId_2,
notification_status: "exception",
notification_type: "email",
},
{
mail_message_id: messageId_2,
notification_status: "exception",
notification_type: "email",
},
]);
await start();
await click(".o_menu_systray i[aria-label='Messages']");
await contains(".o-mail-NotificationItem", { count: 2 });
await contains(":nth-child(1 of .o-mail-NotificationItem)", {
contains: [
[".o-mail-NotificationItem-name", { text: "Email Failure: Contact" }],
[".o-mail-NotificationItem-counter", { text: "2" }],
[".o-mail-NotificationItem-text", { text: "An error occurred when sending an email" }],
],
});
await contains(":nth-child(2 of .o-mail-NotificationItem)", {
contains: [
[".o-mail-NotificationItem-name", { text: "Snailmail Failure: Contact" }],
[".o-mail-NotificationItem-counter", { text: "2" }],
[
".o-mail-NotificationItem-text",
{ text: "An error occurred when sending a letter with Snailmail." },
],
],
});
});
test("grouped notifications by document model", async (assert) => {
const pyEnv = await startServer();
const [partnerId_1, partnerId_2] = pyEnv["res.partner"].create([{}, {}]);
const [messageId_1, messageId_2] = pyEnv["mail.message"].create([
{
message_type: "snailmail",
model: "res.partner",
res_id: partnerId_1,
},
{
message_type: "snailmail",
model: "res.partner",
res_id: partnerId_2,
},
]);
pyEnv["mail.notification"].create([
{
mail_message_id: messageId_1,
notification_status: "exception",
notification_type: "snail",
},
{
mail_message_id: messageId_2,
notification_status: "exception",
notification_type: "snail",
},
]);
mockService("action", {
doAction(action) {
asyncStep("do_action");
expect(action.name).toBe("Snailmail Failures");
expect(action.type).toBe("ir.actions.act_window");
expect(action.view_mode).toBe("kanban,list,form");
expect(JSON.stringify(action.views)).toBe(
JSON.stringify([
[false, "kanban"],
[false, "list"],
[false, "form"],
])
);
expect(action.target).toBe("current");
expect(action.res_model).toBe("res.partner");
expect(JSON.stringify(action.domain)).toBe(
JSON.stringify([["message_ids.snailmail_error", "=", true]])
);
},
});
await start();
await click(".o_menu_systray i[aria-label='Messages']");
await contains(".o-mail-NotificationItem", { text: "Snailmail Failure: Contact" });
await contains(".o-mail-NotificationItem-counter", { text: "2" });
await click(".o-mail-NotificationItem");
await waitForSteps(["do_action"]);
});

View file

@ -0,0 +1,9 @@
import { models } from "@web/../tests/web_test_helpers";
export class IapAccount extends models.ServerModel {
_name = "iap.account";
get_credits_url() {
return true;
}
}

View file

@ -0,0 +1,5 @@
import { models } from "@web/../tests/web_test_helpers";
export class SnailmailLetter extends models.ServerModel {
_name = "snailmail.letter";
}

View file

@ -1,349 +0,0 @@
/* @odoo-module */
import { startServer } from "@bus/../tests/helpers/mock_python_environment";
import { start } from "@mail/../tests/helpers/test_utils";
import { makeDeferred } from "@mail/utils/deferred";
import { patchWithCleanup } from "@web/../tests/helpers/utils";
import { click, contains } from "@web/../tests/utils";
QUnit.module("snailmail", {}, function () {
QUnit.module("components", {}, async function () {
QUnit.module("message_tests.js");
QUnit.test("Sent", async function () {
const pyEnv = await startServer();
const resPartnerId1 = pyEnv["res.partner"].create({
name: "Someone",
partner_share: true,
});
const mailMessageId1 = pyEnv["mail.message"].create({
body: "not empty",
message_type: "snailmail",
model: "res.partner",
res_id: resPartnerId1,
});
pyEnv["mail.notification"].create({
mail_message_id: mailMessageId1,
notification_status: "sent",
notification_type: "snail",
res_partner_id: resPartnerId1,
});
const { openFormView } = await start();
await openFormView({
res_id: resPartnerId1,
res_model: "res.partner",
});
await contains(".o_Message");
await contains(".o_Message_notificationIcon.fa-paper-plane");
await click(".o_Message_notificationIconClickable");
await contains(".o_SnailmailNotificationPopoverContentView", { text: "Sent" });
await contains(".o_SnailmailNotificationPopoverContentView_icon.fa-check");
});
QUnit.test("Canceled", async function () {
const pyEnv = await startServer();
const resPartnerId1 = pyEnv["res.partner"].create({
name: "Someone",
partner_share: true,
});
const mailMessageId1 = pyEnv["mail.message"].create({
body: "not empty",
message_type: "snailmail",
model: "res.partner",
res_id: resPartnerId1,
});
pyEnv["mail.notification"].create({
mail_message_id: mailMessageId1,
notification_status: "canceled",
notification_type: "snail",
res_partner_id: resPartnerId1,
});
const { openFormView } = await start();
await openFormView({
res_id: resPartnerId1,
res_model: "res.partner",
});
await contains(".o_Message");
await contains(".o_Message_notificationIcon.fa-paper-plane");
await click(".o_Message_notificationIconClickable");
await contains(".o_SnailmailNotificationPopoverContentView", { text: "Canceled" });
await contains(".o_SnailmailNotificationPopoverContentView_icon.fa-trash-o");
});
QUnit.test("Pending", async function () {
const pyEnv = await startServer();
const resPartnerId1 = pyEnv["res.partner"].create({
name: "Someone",
partner_share: true,
});
const mailMessageId1 = pyEnv["mail.message"].create({
body: "not empty",
message_type: "snailmail",
model: "res.partner",
res_id: resPartnerId1,
});
pyEnv["mail.notification"].create({
mail_message_id: mailMessageId1,
notification_status: "ready",
notification_type: "snail",
res_partner_id: resPartnerId1,
});
const { openFormView } = await start();
await openFormView({
res_id: resPartnerId1,
res_model: "res.partner",
});
await contains(".o_Message");
await contains(".o_Message_notificationIcon.fa-paper-plane");
await click(".o_Message_notificationIconClickable");
await contains(".o_SnailmailNotificationPopoverContentView", {
text: "Awaiting Dispatch",
});
await contains(".o_SnailmailNotificationPopoverContentView_icon.fa-clock-o");
});
QUnit.test("No Price Available", async function (assert) {
const pyEnv = await startServer();
const resPartnerId1 = pyEnv["res.partner"].create({
name: "Someone",
partner_share: true,
});
const mailMessageId1 = pyEnv["mail.message"].create({
body: "not empty",
message_type: "snailmail",
model: "res.partner",
res_id: resPartnerId1,
});
pyEnv["mail.notification"].create({
failure_type: "sn_price",
mail_message_id: mailMessageId1,
notification_status: "exception",
notification_type: "snail",
res_partner_id: resPartnerId1,
});
const def = makeDeferred();
const { openFormView } = await start({
async mockRPC(route, args) {
if (
args.method === "cancel_letter" &&
args.model === "mail.message" &&
args.args[0][0] === mailMessageId1
) {
assert.step(args.method);
def.resolve();
}
},
});
await openFormView({
res_id: resPartnerId1,
res_model: "res.partner",
});
await contains(".o_Message");
await contains(".o_Message_notificationIcon.fa-paper-plane");
await click(".o_Message_notificationIconClickable");
await contains(".o_SnailmailError");
await contains(".o_SnailmailError_contentPrice");
await click(".o_SnailmailError_cancelLetterButton");
await contains(".o_SnailmailError", { count: 0 });
await def;
assert.verifySteps(["cancel_letter"], "should have made a RPC call to 'cancel_letter'");
});
QUnit.test("Credit Error", async function (assert) {
const pyEnv = await startServer();
const resPartnerId1 = pyEnv["res.partner"].create({
name: "Someone",
partner_share: true,
});
const mailMessageId1 = pyEnv["mail.message"].create({
body: "not empty",
message_type: "snailmail",
model: "res.partner",
res_id: resPartnerId1,
});
pyEnv["mail.notification"].create({
failure_type: "sn_credit",
mail_message_id: mailMessageId1,
notification_status: "exception",
notification_type: "snail",
res_partner_id: resPartnerId1,
});
const def = makeDeferred();
const { openFormView } = await start({
async mockRPC(route, args) {
if (
args.method === "send_letter" &&
args.model === "mail.message" &&
args.args[0][0] === mailMessageId1
) {
assert.step(args.method);
def.resolve();
}
},
});
await openFormView({
res_id: resPartnerId1,
res_model: "res.partner",
});
await contains(".o_Message");
await contains(".o_Message_notificationIcon.fa-paper-plane");
await click(".o_Message_notificationIconClickable");
await contains(".o_SnailmailError");
await contains(".o_SnailmailError_contentCredit");
await contains(".o_SnailmailError_cancelLetterButton");
await click(".o_SnailmailError_resendLetterButton");
await contains(".o_SnailmailError", { count: 0 });
await def;
assert.verifySteps(["send_letter"], "should have made a RPC call to 'send_letter'");
});
QUnit.test("Trial Error", async function (assert) {
const pyEnv = await startServer();
const resPartnerId1 = pyEnv["res.partner"].create({
name: "Someone",
partner_share: true,
});
const mailMessageId1 = pyEnv["mail.message"].create({
body: "not empty",
message_type: "snailmail",
model: "res.partner",
res_id: resPartnerId1,
});
pyEnv["mail.notification"].create({
failure_type: "sn_trial",
mail_message_id: mailMessageId1,
notification_status: "exception",
notification_type: "snail",
res_partner_id: resPartnerId1,
});
const def = makeDeferred();
const { openFormView } = await start({
async mockRPC(route, args) {
if (
args.method === "send_letter" &&
args.model === "mail.message" &&
args.args[0][0] === mailMessageId1
) {
assert.step(args.method);
def.resolve();
}
},
});
await openFormView({
res_id: resPartnerId1,
res_model: "res.partner",
});
await contains(".o_Message");
await contains(".o_Message_notificationIcon.fa-paper-plane");
await click(".o_Message_notificationIconClickable");
await contains(".o_SnailmailError");
await contains(".o_SnailmailError_contentTrial");
await contains(".o_SnailmailError_cancelLetterButton");
await click(".o_SnailmailError_resendLetterButton");
await contains(".o_SnailmailError", { count: 0 });
await def;
assert.verifySteps(["send_letter"], "should have made a RPC call to 'send_letter'");
});
QUnit.test("Format Error", async function (assert) {
const pyEnv = await startServer();
const resPartnerId1 = pyEnv["res.partner"].create({
name: "Someone",
partner_share: true,
});
const mailMessageId1 = pyEnv["mail.message"].create({
body: "not empty",
message_type: "snailmail",
model: "res.partner",
res_id: resPartnerId1,
});
pyEnv["mail.notification"].create({
failure_type: "sn_format",
mail_message_id: mailMessageId1,
notification_status: "exception",
notification_type: "snail",
res_partner_id: resPartnerId1,
});
const { env, openFormView } = await start();
await openFormView({
res_id: resPartnerId1,
res_model: "res.partner",
});
const def = makeDeferred();
patchWithCleanup(env.services.action, {
doAction(action, options) {
assert.step("do_action");
assert.strictEqual(
action,
"snailmail.snailmail_letter_format_error_action",
"action should be the one for format error"
);
assert.strictEqual(
options.additionalContext.message_id,
mailMessageId1,
"action should have correct message id"
);
def.resolve();
},
});
await contains(".o_Message");
await contains(".o_Message_notificationIcon.fa-paper-plane");
await click(".o_Message_notificationIconClickable");
await def;
assert.verifySteps(["do_action"], "should do an action to display the format error dialog");
});
QUnit.test("Missing Required Fields", async function (assert) {
const pyEnv = await startServer();
const resPartnerId1 = pyEnv["res.partner"].create({});
const mailMessageId1 = pyEnv["mail.message"].create({
body: "not empty",
message_type: "snailmail",
res_id: resPartnerId1, // non 0 id, necessary to fetch failure at init
model: "res.partner", // not mail.compose.message, necessary to fetch failure at init
});
pyEnv["mail.notification"].create({
failure_type: "sn_fields",
mail_message_id: mailMessageId1,
notification_status: "exception",
notification_type: "snail",
});
const snailMailLetterId1 = pyEnv["snailmail.letter"].create({
message_id: mailMessageId1,
});
const { env, openFormView } = await start();
await openFormView({
res_id: resPartnerId1,
res_model: "res.partner",
});
const def = makeDeferred();
patchWithCleanup(env.services.action, {
doAction(action, options) {
assert.step("do_action");
assert.strictEqual(
action,
"snailmail.snailmail_letter_missing_required_fields_action",
"action should be the one for missing fields"
);
assert.strictEqual(
options.additionalContext.default_letter_id,
snailMailLetterId1,
"action should have correct letter id"
);
def.resolve();
},
});
await contains(".o_Message");
await contains(".o_Message_notificationIcon.fa-paper-plane");
await click(".o_Message_notificationIconClickable");
await def;
assert.verifySteps(
["do_action"],
"an action should be done to display the missing fields dialog"
);
});
});
});

View file

@ -1,259 +0,0 @@
/** @odoo-module **/
import { start, startServer } from '@mail/../tests/helpers/test_utils';
import { patchWithCleanup } from '@web/../tests/helpers/utils';
QUnit.module('snailmail', {}, function () {
QUnit.module('components', {}, function () {
QUnit.module('notification_list_notification_group_tests.js');
QUnit.test('mark as read', async function (assert) {
assert.expect(2);
// Note: The server code is too complex to be rewritten in javascript.
// Actually, the server rely on the model "snailmail.letter" to identify the notification to cancel
// The following code simulates the cancel of the notification without using "snailmail.letter" model
const pyEnv = await startServer();
const mailChannelId1 = pyEnv['mail.channel'].create({});
// message that is expected to have a failure
const mailMessageId1 = pyEnv['mail.message'].create({
author_id: pyEnv.currentPartnerId,
message_type: 'snailmail',
model: 'mail.channel',
res_id: mailChannelId1,
});
// failure that is expected to be used in the test
pyEnv['mail.notification'].create({
mail_message_id: mailMessageId1, // id of the related message
notification_status: 'exception', // necessary value to have a failure
notification_type: 'snail',
});
const { afterNextRender, click } = await start();
await click('.o_MessagingMenu_toggler');
assert.containsOnce(
document.body,
'.o_NotificationGroup_markAsRead',
"should have 1 mark as read button"
);
await afterNextRender(() => {
document.querySelector('.o_NotificationGroup_markAsRead').click();
});
assert.containsNone(
document.body,
'.o_NotificationGroup',
"should have no notification group"
);
});
QUnit.test('notifications grouped by notification_type', async function (assert) {
assert.expect(11);
const pyEnv = await startServer();
const resPartnerId1 = await pyEnv['res.partner'].create({});
const [mailMessageId1, mailMessageId2] = pyEnv['mail.message'].create([
// first message that is expected to have a failure
{
message_type: 'snailmail', // different type from second message
model: 'res.partner', // same model as second message (and not `mail.channel`)
res_id: resPartnerId1, // same res_id as second message
res_model_name: "Partner", // random related model name
},
// second message that is expected to have a failure
{
message_type: 'email', // different type from first message
model: 'res.partner', // same model as first message (and not `mail.channel`)
res_id: resPartnerId1, // same res_id as first message
res_model_name: "Partner", // same related model name for consistency
},
]);
pyEnv['mail.notification'].create([
{
mail_message_id: mailMessageId1, // id of the related first message
notification_status: 'exception', // necessary value to have a failure
notification_type: 'snail', // different type from second failure
},
{
mail_message_id: mailMessageId1,
notification_status: 'exception',
notification_type: 'snail',
},
{
mail_message_id: mailMessageId2, // id of the related second message
notification_status: 'exception', // necessary value to have a failure
notification_type: 'email', // different type from first failure
},
{
mail_message_id: mailMessageId2,
notification_status: 'exception',
notification_type: 'email',
},
]);
const { click } = await start();
await click('.o_MessagingMenu_toggler');
assert.containsN(
document.body,
'.o_NotificationGroup',
2,
"should have 2 notifications group"
);
const groups = document.querySelectorAll('.o_NotificationGroup');
assert.containsOnce(
groups[0],
'.o_NotificationGroup_name',
"should have 1 group name in first group"
);
assert.strictEqual(
groups[0].querySelector('.o_NotificationGroup_name').textContent,
"Partner",
"should have model name as group name"
);
assert.containsOnce(
groups[0],
'.o_NotificationGroup_counter',
"should have 1 group counter in first group"
);
assert.strictEqual(
groups[0].querySelector('.o_NotificationGroup_counter').textContent.trim(),
"(2)",
"should have 2 notifications in first group"
);
assert.strictEqual(
groups[0].querySelector('.o_NotificationGroup_inlineText').textContent.trim(),
"An error occurred when sending an email.",
"should have the group text corresponding to email"
);
assert.containsOnce(
groups[1],
'.o_NotificationGroup_name',
"should have 1 group name in second group"
);
assert.strictEqual(
groups[1].querySelector('.o_NotificationGroup_name').textContent,
"Partner",
"should have second model name as group name"
);
assert.containsOnce(
groups[1],
'.o_NotificationGroup_counter',
"should have 1 group counter in second group"
);
assert.strictEqual(
groups[1].querySelector('.o_NotificationGroup_counter').textContent.trim(),
"(2)",
"should have 2 notifications in second group"
);
assert.strictEqual(
groups[1].querySelector('.o_NotificationGroup_inlineText').textContent.trim(),
"An error occurred when sending a letter with Snailmail.",
"should have the group text corresponding to snailmail"
);
});
QUnit.test('grouped notifications by document model', async function (assert) {
// If all failures linked to a document model refers to different documents,
// a single notification should group all failures that are linked to this
// document model.
assert.expect(12);
const pyEnv = await startServer();
const [resPartnerId1, resPartnerId2] = await pyEnv['res.partner'].create([{}, {}]);
const [mailMessageId1, mailMessageId2] = pyEnv['mail.message'].create([
{
message_type: 'snailmail', // message must be snailmail (goal of the test)
model: 'res.partner', // same model as second message (and not `mail.channel`)
res_id: resPartnerId1, // same res_id as second message
res_model_name: "Partner", // random related model name
},
{
message_type: 'snailmail', // message must be snailmail (goal of the test)
model: 'res.partner', // same model as first message (and not `mail.channel`)
res_id: resPartnerId2, // different res_id from first message
res_model_name: "Partner", // same related model name for consistency
},
]);
pyEnv['mail.notification'].create([
// first failure that is expected to be used in the test
{
mail_message_id: mailMessageId1, // id of the related first message
notification_status: 'exception', // necessary value to have a failure
notification_type: 'snail', // expected failure type for snailmail message
},
// second failure that is expected to be used in the test
{
mail_message_id: mailMessageId2, // id of the related second message
notification_status: 'exception', // necessary value to have a failure
notification_type: 'snail', // expected failure type for snailmail message
},
]);
const { click, env } = await start();
patchWithCleanup(env.services.action, {
doAction(action) {
assert.step('do_action');
assert.strictEqual(
action.name,
"Snailmail Failures",
"action should have 'Snailmail Failures' as name",
);
assert.strictEqual(
action.type,
'ir.actions.act_window',
"action should have the type act_window"
);
assert.strictEqual(
action.view_mode,
'kanban,list,form',
"action should have 'kanban,list,form' as view_mode"
);
assert.strictEqual(
JSON.stringify(action.views),
JSON.stringify([[false, 'kanban'], [false, 'list'], [false, 'form']]),
"action should have correct views"
);
assert.strictEqual(
action.target,
'current',
"action should have 'current' as target"
);
assert.strictEqual(
action.res_model,
'res.partner',
"action should have the group model as res_model"
);
assert.strictEqual(
JSON.stringify(action.domain),
JSON.stringify([['message_ids.snailmail_error', '=', true]]),
"action should have 'message_has_sms_error' as domain"
);
},
});
await click('.o_MessagingMenu_toggler');
assert.containsOnce(
document.body,
'.o_NotificationGroup',
"should have 1 notification group"
);
assert.containsOnce(
document.body,
'.o_NotificationGroup_counter',
"should have 1 group counter"
);
assert.strictEqual(
document.querySelector('.o_NotificationGroup_counter').textContent.trim(),
"(2)",
"should have 2 notifications in the group"
);
document.querySelector('.o_NotificationGroup').click();
assert.verifySteps(
['do_action'],
"should do an action to display the related records"
);
});
});
});

View file

@ -0,0 +1,10 @@
import { defineModels } from "@web/../tests/web_test_helpers";
import { mailModels } from "@mail/../tests/mail_test_helpers";
import { IapAccount } from "@snailmail/../tests/mock_server/mock_model/iap_account";
import { SnailmailLetter } from "@snailmail/../tests/mock_server/mock_model/snailmail_letter";
export function defineSnailmailModels() {
return defineModels(snailmailModels);
}
export const snailmailModels = { ...mailModels, IapAccount, SnailmailLetter };