0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-06 13:08:40 +08:00
discourse/plugins/discourse-ai/test/javascripts/acceptance/ai-bot-conversations-test.js
Keegan George 436041645f
FEATURE: Make the message send shortcut a core user option (#42105)
**Previously**, the enter/meta+enter send shortcut was a chat-only
preference (`chat_send_shortcut`), so chat-style composers in other
plugins — like AI bot conversations — always sent on Enter with no way
to insert a newline.

**In this update**, promoted it to a core `send_shortcut` user option on
the Interface preferences page, honored by the chat composer, the core
docked composer, and AI bot conversations.

The `chat_send_shortcut` column is backfilled into `send_shortcut`
post-deploy and kept (ignored) for now, mirroring the
`push_notification_level` promotion; the column drop, the serializer
compatibility alias removal, and the `plugin_manifest.yml` cleanup land
in a follow-up PR.

| Before | After |
| --- | --- |
|
![before](https://github.com/discourse/discourse/releases/download/_gh-attach-assets/before-jmgi09.png)
|
![after](https://github.com/discourse/discourse/releases/download/_gh-attach-assets/after-crkznx.png)
|
2026-07-28 13:58:12 -07:00

117 lines
3.3 KiB
JavaScript
Vendored

import { fillIn, triggerEvent, visit } from "@ember/test-helpers";
import { test } from "qunit";
import User from "discourse/models/user";
import {
acceptance,
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
const INPUT = "#ai-bot-conversations-input";
acceptance("AI Bot - Conversations IME handling", function (needs) {
let conversationRequests = 0;
needs.user({
ai_enabled_agents: [],
ai_enabled_chat_bots: [
{
id: 1,
model_name: "gpt-4",
username: "gpt-4",
is_agent: false,
},
],
});
needs.settings({
discourse_ai_enabled: true,
ai_bot_enabled: true,
min_personal_message_post_length: 10,
});
needs.pretender((server, helper) => {
server.get("/discourse-ai/ai-bot/conversations.json", () =>
helper.response({
conversations: [],
meta: { has_more: false },
})
);
server.post("/discourse-ai/ai-bot/conversations.json", () => {
conversationRequests += 1;
return helper.response({
id: 1,
topic_id: 1,
topic_slug: "ai-conversation",
post_url: "/t/ai-conversation/1/1",
});
});
server.get("/t/:slug/:id.json", () => helper.response({}));
});
needs.hooks.beforeEach(() => (conversationRequests = 0));
async function prepareDraft() {
await visit("/discourse-ai/ai-bot/conversations");
await fillIn(INPUT, "これはテスト入力として十分長い文章です");
}
test("Enter submits the message", async function (assert) {
await prepareDraft();
await triggerEvent(INPUT, "keydown", { key: "Enter" });
await triggerEvent(INPUT, "beforeinput", { inputType: "insertLineBreak" });
assert.strictEqual(conversationRequests, 1, "submitted once");
});
test("Shift+Enter does not submit", async function (assert) {
await prepareDraft();
await triggerEvent(INPUT, "keydown", { key: "Enter", shiftKey: true });
await triggerEvent(INPUT, "beforeinput", { inputType: "insertLineBreak" });
assert.strictEqual(conversationRequests, 0, "did not submit");
});
test("IME-confirming Enter does not submit", async function (assert) {
await prepareDraft();
await triggerEvent(INPUT, "keydown", { key: "Enter" });
await triggerEvent(INPUT, "beforeinput", {
inputType: "insertCompositionText",
});
assert.strictEqual(conversationRequests, 0, "did not submit");
});
test("Enter does not submit with the meta_enter send shortcut", async function (assert) {
updateCurrentUser({
user_option: {
...User.current().user_option,
send_shortcut: "meta_enter",
},
});
await prepareDraft();
await triggerEvent(INPUT, "keydown", { key: "Enter" });
await triggerEvent(INPUT, "beforeinput", { inputType: "insertLineBreak" });
assert.strictEqual(conversationRequests, 0, "did not submit");
});
test("Meta+Enter submits with the meta_enter send shortcut", async function (assert) {
updateCurrentUser({
user_option: {
...User.current().user_option,
send_shortcut: "meta_enter",
},
});
await prepareDraft();
await triggerEvent(INPUT, "keydown", { key: "Enter", metaKey: true });
assert.strictEqual(conversationRequests, 1, "submitted once");
});
});