Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion addons/mail/static/src/core/common/suggestion_hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,10 @@ export class UseSuggestion {
}
insert(option) {
let position = this.search.position + 1;
if ([":", "::"].includes(this.search.delimiter) || this.comp.composerService.htmlEnabled) {
if (
[":", "::"].includes(this.search.delimiter) ||
(this.comp.composerService.htmlEnabled && this.search.delimiter !== "/")
) {
position = this.search.position;
}
if (this.comp.composerService.htmlEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ const commandRegistry = registry.category("discuss.channel_commands");
const suggestionServicePatch = {
getSupportedDelimiters(thread, env) {
const res = super.getSupportedDelimiters(...arguments);
if (this.composer.htmlEnabled) {
return res;
}
return thread?.model === "discuss.channel" ? [...res, ["/", 0]] : res;
},
/**
Expand Down
110 changes: 105 additions & 5 deletions addons/mail/static/tests/discuss/core/suggestion.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { insertText as htmlInsertText } from "@html_editor/../tests/_helpers/user_actions";

import {
click,
contains,
Expand All @@ -9,7 +11,7 @@ import {
} from "@mail/../tests/mail_test_helpers";
import { beforeEach, describe, test } from "@odoo/hoot";
import { mockDate } from "@odoo/hoot-mock";
import { Command, patchWithCleanup, serverState } from "@web/../tests/web_test_helpers";
import { Command, getService, patchWithCleanup, serverState } from "@web/../tests/web_test_helpers";

import { Composer } from "@mail/core/common/composer";
import { press } from "@odoo/hoot-dom";
Expand All @@ -26,7 +28,7 @@ beforeEach(() => {
});
});

test('display command suggestions on typing "/"', async () => {
test('[text composer] display command suggestions on typing "/"', async () => {
const pyEnv = await startServer();
const channelId = pyEnv["discuss.channel"].create({
name: "General",
Expand All @@ -40,7 +42,29 @@ test('display command suggestions on typing "/"', async () => {
await contains(".o-mail-Composer-suggestionList .o-open");
});

test("use a command for a specific channel type", async () => {
test.tags("html composer");
test("display command suggestions on typing '/'", async () => {
const pyEnv = await startServer();
const channelId = pyEnv["discuss.channel"].create({
name: "General",
channel_type: "channel",
});
await start();
const composerService = getService("mail.composer");
composerService.setHtmlComposer();
await openDiscuss(channelId);
await contains(".o-mail-Composer-suggestionList");
await contains(".o-mail-Composer-suggestionList .o-open", { count: 0 });
await focus(".o-mail-Composer-html.odoo-editor-editable");
const editor = {
document,
editable: document.querySelector(".o-mail-Composer-html.odoo-editor-editable"),
};
await htmlInsertText(editor, "/");
await contains(".o-mail-Composer-suggestionList .o-open");
});

test("[text composer] use a command for a specific channel type", async () => {
const pyEnv = await startServer();
const channelId = pyEnv["discuss.channel"].create({ channel_type: "chat" });
await start();
Expand All @@ -53,7 +77,27 @@ test("use a command for a specific channel type", async () => {
await contains(".o-mail-Composer-input", { value: "/who " });
});

test("command suggestion should only open if command is the first character", async () => {
test.tags("html composer");
test("use a command for a specific channel type", async () => {
const pyEnv = await startServer();
const channelId = pyEnv["discuss.channel"].create({ channel_type: "chat" });
await start();
const composerService = getService("mail.composer");
composerService.setHtmlComposer();
await openDiscuss(channelId);
await contains(".o-mail-Composer-suggestionList");
await contains(".o-mail-Composer-suggestionList .o-open", { count: 0 });
await focus(".o-mail-Composer-html.odoo-editor-editable");
const editor = {
document,
editable: document.querySelector(".o-mail-Composer-html.odoo-editor-editable"),
};
await htmlInsertText(editor, "/");
await click(".o-mail-Composer-suggestion strong", { text: "who" });
await contains(".o-mail-Composer-html.odoo-editor-editable", { text: "/who" });
});

test("[text composer] command suggestion should only open if command is the first character", async () => {
const pyEnv = await startServer();
const channelId = pyEnv["discuss.channel"].create({
name: "General",
Expand All @@ -71,6 +115,31 @@ test("command suggestion should only open if command is the first character", as
await contains(".o-mail-Composer-suggestionList .o-open", { count: 0 });
});

test.tags("html composer");
test("command suggestion should only open if command is the first character", async () => {
const pyEnv = await startServer();
const channelId = pyEnv["discuss.channel"].create({
name: "General",
channel_type: "channel",
});
await start();
const composerService = getService("mail.composer");
composerService.setHtmlComposer();
await openDiscuss(channelId);
await contains(".o-mail-Composer-suggestionList");
await contains(".o-mail-Composer-suggestionList .o-open", { count: 0 });
await focus(".o-mail-Composer-html.odoo-editor-editable");
const editor = {
document,
editable: document.querySelector(".o-mail-Composer-html.odoo-editor-editable"),
};
await htmlInsertText(editor, "bluhbluh");
await contains(".o-mail-Composer-html.odoo-editor-editable", { text: "bluhbluh" });
await htmlInsertText(editor, "/");
// weak test, no guarantee that we waited long enough for the potential list to open
await contains(".o-mail-Composer-suggestionList .o-open", { count: 0 });
});

test("Sort partner suggestions by recent chats", async () => {
mockDate("2023-01-03 12:00:00"); // so that it's after last interest (mock server is in 2019 by default!)
const pyEnv = await startServer();
Expand Down Expand Up @@ -164,7 +233,7 @@ test("mention suggestion are shown after deleting a character", async () => {
await contains(".o-mail-Composer-suggestion strong", { text: "John Doe" });
});

test("command suggestion are shown after deleting a character", async () => {
test("[text composer] command suggestion are shown after deleting a character", async () => {
const pyEnv = await startServer();
const partnerId = pyEnv["res.partner"].create({ name: "John Doe" });
const channelId = pyEnv["discuss.channel"].create({
Expand All @@ -187,6 +256,37 @@ test("command suggestion are shown after deleting a character", async () => {
await contains(".o-mail-Composer-suggestion strong", { text: "help" });
});

test.tags("html composer");
test("command suggestion are shown after deleting a character", async () => {
const pyEnv = await startServer();
const partnerId = pyEnv["res.partner"].create({ name: "John Doe" });
const channelId = pyEnv["discuss.channel"].create({
name: "General",
channel_type: "channel",
channel_member_ids: [
Command.create({ partner_id: serverState.partnerId }),
Command.create({ partner_id: partnerId }),
],
});
await start();
const composerService = getService("mail.composer");
composerService.setHtmlComposer();
await openDiscuss(channelId);
await contains(".o-mail-Composer-suggestionList");
await contains(".o-mail-Composer-suggestionList .o-open", { count: 0 });
await focus(".o-mail-Composer-html.odoo-editor-editable");
const editor = {
document,
editable: document.querySelector(".o-mail-Composer-html.odoo-editor-editable"),
};
await htmlInsertText(editor, "/he");
await contains(".o-mail-Composer-suggestion strong", { text: "help" });
await htmlInsertText(editor, "e");
await contains(".o-mail-Composer-suggestion strong", { count: 0, text: "help" });
await press("Backspace");
await contains(".o-mail-Composer-suggestion strong", { text: "help" });
});

test("mention suggestion displays OdooBot before archived partners", async () => {
const pyEnv = await startServer();
const partnerId = pyEnv["res.partner"].create({ name: "Jane", active: false });
Expand Down