Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewPrigorshnev committed Aug 30, 2023
1 parent 96ff9c1 commit 2df6952
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/assets/javascripts/discourse/app/lib/plugin-api.js
Expand Up @@ -2125,15 +2125,15 @@ class PluginApi {
* Support for setting a Sidebar panel.
*/
setSidebarPanel(name) {
this._lookupContainer("service:sidebar-state").setPanel(name);
this._lookupContainer("service:sidebar-state")?.setPanel(name);
}

/**
* EXPERIMENTAL. Do not use.
* Set combined sidebar section mode. In this mode, sections from all panels are displayed together.
*/
setCombinedSidebarMode() {
this._lookupContainer("service:sidebar-state").setCombinedMode();
this._lookupContainer("service:sidebar-state")?.setCombinedMode();
}

/**
Expand All @@ -2157,7 +2157,7 @@ class PluginApi {
* Hide sidebar switch panels buttons in separated mode.
*/
hideSidebarSwitchPanelButtons() {
this._lookupContainer("service:sidebar-state").hideSwitchPanelButtons();
this._lookupContainer("service:sidebar-state")?.hideSwitchPanelButtons();
}

/**
Expand Down
91 changes: 91 additions & 0 deletions plugins/chat/test/javascripts/acceptance/mentions-test.js
@@ -0,0 +1,91 @@
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
import { fillIn, visit } from "@ember/test-helpers";
import pretender, { response } from "discourse/tests/helpers/create-pretender";

acceptance("Chat | Mentions", function (needs) {
const channelId = 1;
const actingUser = {
id: 1,
username: "acting_user",
};
const channel = {
id: channelId,
chatable_id: 1,
chatable_type: "Category",
meta: { message_bus_last_ids: {}, can_delete_self: true },
current_user_membership: { following: true },
chatable: { id: 1 },
};

needs.settings({ chat_enabled: true });

needs.user({
...actingUser,
has_chat_enabled: true,
chat_channels: {
public_channels: [channel],
direct_message_channels: [],
meta: { message_bus_last_ids: {} },
tracking: {},
},
});

needs.hooks.beforeEach(function () {
pretender.post(`/chat/drafts`, () => response({}));
pretender.get(`/chat/api/channels/${channelId}/messages`, () =>
response({
messages: [],
meta: {
can_load_more_future: false,
},
})
);
pretender.get("/chat/api/mentions/groups.json", () =>
response({
unreachable: [],
over_members_limit: [],
invalid: ["and"],
})
);
});

test("shows warning when mention limit exceeded", async function (assert) {
this.siteSettings.max_mentions_per_chat_message = 2;

await visit(`/chat/c/-/${channelId}`);
await fillIn(".chat-composer__input", `Hey @user1 @user2 @user3`);

assert.dom(".chat-mention-warnings").exists();
});

test("ignores duplicates when counting mentions", async function (assert) {
this.siteSettings.max_mentions_per_chat_message = 2;

await visit(`/chat/c/-/${channelId}`);
const mention = `@user1`;
await fillIn(
".chat-composer__input",
`Hey ${mention} ${mention} ${mention}`
);

assert.dom(".chat-mention-warnings").doesNotExist();
});

test("doesn't consider code-blocks when counting mentions", async function (assert) {
this.siteSettings.max_mentions_per_chat_message = 2;

await visit(`/chat/c/-/${channelId}`);
// since @bar is inside a code-block it shouldn't be considered a mention
const message = `Hey @user1 @user2
\`\`\`
def foo
@bar = true
end
\`\`\`
`;
await fillIn(".chat-composer__input", message);

assert.dom(".chat-mention-warnings").doesNotExist();
});
});

0 comments on commit 2df6952

Please sign in to comment.