2022-11-02 21:41:30 +08:00
|
|
|
import userFixtures from "discourse/tests/fixtures/user-fixtures";
|
|
|
|
import { cloneJSON } from "discourse-common/lib/object";
|
|
|
|
import {
|
|
|
|
acceptance,
|
|
|
|
exists,
|
|
|
|
loggedInUser,
|
|
|
|
} from "discourse/tests/helpers/qunit-helpers";
|
2022-11-11 13:39:15 +08:00
|
|
|
import { click, visit } from "@ember/test-helpers";
|
2022-11-02 21:41:30 +08:00
|
|
|
import {
|
|
|
|
chatChannels,
|
|
|
|
directMessageChannels,
|
|
|
|
generateChatView,
|
|
|
|
} from "discourse/plugins/chat/chat-fixtures";
|
|
|
|
import { test } from "qunit";
|
|
|
|
|
|
|
|
acceptance("Discourse Chat - User card test", function (needs) {
|
|
|
|
needs.user({
|
|
|
|
admin: false,
|
|
|
|
moderator: false,
|
|
|
|
username: "eviltrout",
|
|
|
|
id: 1,
|
|
|
|
can_chat: true,
|
|
|
|
has_chat_enabled: true,
|
|
|
|
});
|
|
|
|
needs.pretender((server, helper) => {
|
|
|
|
server.post("/uploads/lookup-urls", () => {
|
|
|
|
return helper.response([]);
|
|
|
|
});
|
|
|
|
server.get("/chat/chat_channels.json", () => helper.response(chatChannels));
|
|
|
|
server.get("/chat/chat_channels/:channelId.json", () =>
|
|
|
|
helper.response(helper.response(directMessageChannels[0]))
|
|
|
|
);
|
|
|
|
server.get("/chat/:chatChannelId/messages.json", () =>
|
|
|
|
helper.response(generateChatView(loggedInUser()))
|
|
|
|
);
|
|
|
|
server.post("/chat/direct_messages/create.json", () => {
|
|
|
|
return helper.response({
|
|
|
|
chat_channel: {
|
|
|
|
chat_channels: [],
|
|
|
|
chatable: {
|
|
|
|
users: [
|
|
|
|
{
|
|
|
|
username: "hawk",
|
|
|
|
id: 2,
|
|
|
|
name: "hawk",
|
|
|
|
avatar_template:
|
|
|
|
"/letter_avatar_proxy/v3/letter/t/41988e/{size}.png",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
chatable_id: 16,
|
2022-11-02 22:53:36 +08:00
|
|
|
chatable_type: "DirectMessage",
|
2022-11-02 21:41:30 +08:00
|
|
|
chatable_url: null,
|
|
|
|
id: 75,
|
|
|
|
title: "@hawk",
|
|
|
|
last_message_sent_at: "2021-11-08T21:26:05.710Z",
|
|
|
|
current_user_membership: {
|
|
|
|
last_read_message_id: null,
|
|
|
|
unread_count: 0,
|
|
|
|
unread_mentions: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
let cardResponse = cloneJSON(userFixtures["/u/charlie/card.json"]);
|
|
|
|
cardResponse.user.can_chat_user = true;
|
|
|
|
server.get("/u/hawk/card.json", () => helper.response(cardResponse));
|
|
|
|
});
|
|
|
|
needs.settings({
|
|
|
|
chat_enabled: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
needs.hooks.beforeEach(function () {
|
|
|
|
Object.defineProperty(this, "chatService", {
|
|
|
|
get: () => this.container.lookup("service:chat"),
|
|
|
|
});
|
|
|
|
Object.defineProperty(this, "appEvents", {
|
|
|
|
get: () => this.container.lookup("service:appEvents"),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("user card has chat button that opens the correct channel", async function (assert) {
|
2022-11-11 13:39:15 +08:00
|
|
|
await visit("/");
|
|
|
|
await click(".header-dropdown-toggle.open-chat");
|
2022-12-02 23:57:35 +08:00
|
|
|
await click('.chat-channel-row[data-chat-channel-id="9"]');
|
2022-11-02 21:41:30 +08:00
|
|
|
await click("[data-user-card='hawk']");
|
2022-11-11 13:39:15 +08:00
|
|
|
|
2022-11-02 21:41:30 +08:00
|
|
|
assert.ok(exists(".user-card-chat-btn"));
|
|
|
|
|
|
|
|
await click(".user-card-chat-btn");
|
2022-11-11 13:39:15 +08:00
|
|
|
|
2022-11-25 21:15:38 +08:00
|
|
|
assert.ok(exists(`.chat-drawer.is-expanded[data-chat-channel-id="75"]`));
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
acceptance(
|
|
|
|
"Discourse Chat - Anon user viewing user card test",
|
|
|
|
function (needs) {
|
|
|
|
needs.settings({
|
|
|
|
chat_enabled: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
test("user card has no chat button", async function (assert) {
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
await click('a[data-user-card="charlie"]');
|
|
|
|
|
|
|
|
assert.notOk(
|
|
|
|
exists(".user-card-chat-btn"),
|
|
|
|
"anon user should not be able to chat with anyone via the user card"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|