mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 23:07:28 +08:00
DEV: glimmerify chat-channel-row (#19287)
This commit is contained in:
@ -1,15 +1,34 @@
|
|||||||
<LinkTo @route="chat.channel" @models={{array this.channel.id (or this.channel.slug "-")}} class={{this.rowClassNames}} id={{concat "chat-channel-row-" this.channel.id}} tabindex="0" data-chat-channel-id={{this.channel.id}}>
|
<LinkTo
|
||||||
<ChatChannelTitle @channel={{this.channel}} />
|
@route="chat.channel"
|
||||||
<ChatChannelMetadata @channel={{this.channel}} @unreadIndicator={{true}} />
|
@models={{array @channel.id (or @channel.slug "-")}}
|
||||||
|
class={{concat-class
|
||||||
|
"chat-channel-row"
|
||||||
|
(if @channel.focused "focused")
|
||||||
|
(if @channel.current_user_membership.muted "muted")
|
||||||
|
(if @options.leaveButton "can-leave")
|
||||||
|
(if (eq this.chat.activeChannel.id @channel.id) "active")
|
||||||
|
(if this.channelHasUnread "has-unread")
|
||||||
|
}}
|
||||||
|
tabindex="0"
|
||||||
|
data-chat-channel-id={{@channel.id}}
|
||||||
|
{{did-insert this.startTrackingStatus}}
|
||||||
|
{{will-destroy this.stopTrackingStatus}}
|
||||||
|
>
|
||||||
|
<ChatChannelTitle @channel={{@channel}} />
|
||||||
|
<ChatChannelMetadata @channel={{@channel}} @unreadIndicator={{true}} />
|
||||||
|
|
||||||
{{#if (and this.options.leaveButton this.channel.isFollowing (not this.site.mobileView))}}
|
{{#if (and @options.leaveButton @channel.isFollowing this.site.desktopView)}}
|
||||||
<ToggleChannelMembershipButton
|
<ToggleChannelMembershipButton
|
||||||
@channel={{this.channel}}
|
@channel={{@channel}}
|
||||||
@options={{hash
|
@options={{hash
|
||||||
leaveClass="btn-flat chat-channel-leave-btn"
|
leaveClass="btn-flat chat-channel-leave-btn"
|
||||||
labelType="none"
|
labelType="none"
|
||||||
leaveIcon="times"
|
leaveIcon="times"
|
||||||
leaveTitle=this.leaveChatTitle
|
leaveTitle=(if
|
||||||
|
@channel.isDirectMessageChannel
|
||||||
|
(i18n "chat.direct_messages.leave")
|
||||||
|
(i18n "chat.channel_settings.leave_channel")
|
||||||
|
)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
@ -1,94 +1,32 @@
|
|||||||
import Component from "@ember/component";
|
|
||||||
import I18n from "I18n";
|
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
|
||||||
import { equal } from "@ember/object/computed";
|
|
||||||
import { inject as service } from "@ember/service";
|
import { inject as service } from "@ember/service";
|
||||||
import { CHATABLE_TYPES } from "discourse/plugins/chat/discourse/models/chat-channel";
|
import Component from "@glimmer/component";
|
||||||
|
import { action } from "@ember/object";
|
||||||
|
|
||||||
export default Component.extend({
|
export default class ChatChannelRow extends Component {
|
||||||
tagName: "",
|
@service router;
|
||||||
router: service(),
|
@service chat;
|
||||||
chat: service(),
|
@service currentUser;
|
||||||
channel: null,
|
@service site;
|
||||||
isDirectMessageRow: equal(
|
|
||||||
"channel.chatable_type",
|
|
||||||
CHATABLE_TYPES.directMessageChannel
|
|
||||||
),
|
|
||||||
options: null,
|
|
||||||
|
|
||||||
didInsertElement() {
|
@action
|
||||||
this._super(...arguments);
|
startTrackingStatus() {
|
||||||
|
this.#firstDirectMessageUser?.trackStatus();
|
||||||
|
}
|
||||||
|
|
||||||
if (this.isDirectMessageRow) {
|
@action
|
||||||
this.channel.chatable.users[0].trackStatus();
|
stopTrackingStatus() {
|
||||||
}
|
this.#firstDirectMessageUser?.stopTrackingStatus();
|
||||||
},
|
}
|
||||||
|
|
||||||
willDestroyElement() {
|
get channelHasUnread() {
|
||||||
this._super(...arguments);
|
|
||||||
|
|
||||||
if (this.isDirectMessageRow) {
|
|
||||||
this.channel.chatable.users[0].stopTrackingStatus();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
@discourseComputed(
|
|
||||||
"channel.id",
|
|
||||||
"chat.activeChannel.id",
|
|
||||||
"router.currentRouteName"
|
|
||||||
)
|
|
||||||
active(channelId, activeChannelId, currentRouteName) {
|
|
||||||
return (
|
return (
|
||||||
currentRouteName?.startsWith("chat.channel") &&
|
this.currentUser.get(
|
||||||
channelId === activeChannelId
|
`chat_channel_tracking_state.${this.args.channel?.id}.unread_count`
|
||||||
|
) > 0
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
|
|
||||||
@discourseComputed("active", "channel.{id,muted}", "channel.focused")
|
get #firstDirectMessageUser() {
|
||||||
rowClassNames(active, channel, focused) {
|
return this.args.channel?.chatable?.users?.firstObject;
|
||||||
const classes = ["chat-channel-row", `chat-channel-${channel.id}`];
|
}
|
||||||
|
}
|
||||||
if (active) {
|
|
||||||
classes.push("active");
|
|
||||||
}
|
|
||||||
if (focused) {
|
|
||||||
classes.push("focused");
|
|
||||||
}
|
|
||||||
if (channel.current_user_membership.muted) {
|
|
||||||
classes.push("muted");
|
|
||||||
}
|
|
||||||
if (this.options?.leaveButton) {
|
|
||||||
classes.push("can-leave");
|
|
||||||
}
|
|
||||||
|
|
||||||
const channelUnreadCount =
|
|
||||||
this.currentUser.chat_channel_tracking_state?.[channel.id]?.unread_count;
|
|
||||||
if (channelUnreadCount > 0) {
|
|
||||||
classes.push("has-unread");
|
|
||||||
}
|
|
||||||
|
|
||||||
return classes.join(" ");
|
|
||||||
},
|
|
||||||
|
|
||||||
@discourseComputed(
|
|
||||||
"isDirectMessageRow",
|
|
||||||
"channel.chatable.users.[]",
|
|
||||||
"channel.chatable.users.@each.status"
|
|
||||||
)
|
|
||||||
showUserStatus(isDirectMessageRow) {
|
|
||||||
return !!(
|
|
||||||
isDirectMessageRow &&
|
|
||||||
this.channel.chatable.users.length === 1 &&
|
|
||||||
this.channel.chatable.users[0].status
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
@discourseComputed("channel.chatable_type")
|
|
||||||
leaveChatTitle() {
|
|
||||||
if (this.channel.isDirectMessageChannel) {
|
|
||||||
return I18n.t("chat.direct_messages.leave");
|
|
||||||
} else {
|
|
||||||
return I18n.t("chat.channel_settings.leave_channel");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
@ -165,7 +165,7 @@ acceptance("Discourse Chat - Keyboard shortcuts", function (needs) {
|
|||||||
test("switching channel with alt+arrow keys in float", async function (assert) {
|
test("switching channel with alt+arrow keys in float", async function (assert) {
|
||||||
await visit("/latest");
|
await visit("/latest");
|
||||||
await click(".header-dropdown-toggle.open-chat");
|
await click(".header-dropdown-toggle.open-chat");
|
||||||
await click("#chat-channel-row-4");
|
await click('.chat-channel-row[data-chat-channel-id="4"]');
|
||||||
|
|
||||||
assert.ok(exists(`.chat-drawer.is-expanded[data-chat-channel-id="4"]`));
|
assert.ok(exists(`.chat-drawer.is-expanded[data-chat-channel-id="4"]`));
|
||||||
|
|
||||||
|
@ -71,7 +71,9 @@ acceptance(
|
|||||||
test("it clears any unread messages in the sidebar for the archived channel", async function (assert) {
|
test("it clears any unread messages in the sidebar for the archived channel", async function (assert) {
|
||||||
await visit("/chat/channel/4/public-category");
|
await visit("/chat/channel/4/public-category");
|
||||||
assert.ok(
|
assert.ok(
|
||||||
exists("#chat-channel-row-4 .chat-channel-unread-indicator"),
|
exists(
|
||||||
|
'.chat-channel-row[data-chat-channel-id="4"] .chat-channel-unread-indicator'
|
||||||
|
),
|
||||||
"unread indicator shows for channel"
|
"unread indicator shows for channel"
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -80,7 +82,9 @@ acceptance(
|
|||||||
status: "archived",
|
status: "archived",
|
||||||
});
|
});
|
||||||
assert.notOk(
|
assert.notOk(
|
||||||
exists("#chat-channel-row-4 .chat-channel-unread-indicator"),
|
exists(
|
||||||
|
'.chat-channel-row[data-chat-channel-id="4"] .chat-channel-unread-indicator'
|
||||||
|
),
|
||||||
"unread indicator should not show after archive status change"
|
"unread indicator should not show after archive status change"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -206,7 +206,7 @@ acceptance("Discourse Chat - without unread", function (needs) {
|
|||||||
test("Unfollowing a direct message channel transitions to another channel", async function (assert) {
|
test("Unfollowing a direct message channel transitions to another channel", async function (assert) {
|
||||||
await visit("/chat/channel/75/@hawk");
|
await visit("/chat/channel/75/@hawk");
|
||||||
await click(
|
await click(
|
||||||
".chat-channel-row.chat-channel-75 .toggle-channel-membership-button.-leave"
|
'.chat-channel-row[data-chat-channel-id="75"] .toggle-channel-membership-button.-leave'
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.ok(/^\/chat\/channel\/4/.test(currentURL()));
|
assert.ok(/^\/chat\/channel\/4/.test(currentURL()));
|
||||||
@ -353,13 +353,13 @@ acceptance("Discourse Chat - without unread", function (needs) {
|
|||||||
await settled();
|
await settled();
|
||||||
|
|
||||||
await click(".chat-drawer-header__return-to-channels-btn");
|
await click(".chat-drawer-header__return-to-channels-btn");
|
||||||
await click(".chat-channel-row.chat-channel-9");
|
await click('.chat-channel-row[data-chat-channel-id="9"]');
|
||||||
await triggerEvent(".chat-message-container[data-id='174']", "mouseenter");
|
await triggerEvent(".chat-message-container[data-id='174']", "mouseenter");
|
||||||
await click(".chat-message-actions-container[data-id='174'] .reply-btn");
|
await click(".chat-message-actions-container[data-id='174'] .reply-btn");
|
||||||
// Reply-to line is present
|
// Reply-to line is present
|
||||||
assert.ok(exists(".chat-composer-message-details .chat-reply"));
|
assert.ok(exists(".chat-composer-message-details .chat-reply"));
|
||||||
await click(".chat-drawer-header__return-to-channels-btn");
|
await click(".chat-drawer-header__return-to-channels-btn");
|
||||||
await click(".chat-channel-row.chat-channel-11");
|
await click('.chat-channel-row[data-chat-channel-id="11"]');
|
||||||
// Reply-to line is gone since switching channels
|
// Reply-to line is gone since switching channels
|
||||||
assert.notOk(exists(".chat-composer-message-details .chat-reply"));
|
assert.notOk(exists(".chat-composer-message-details .chat-reply"));
|
||||||
// Now click on reply btn and cancel it on channel 7
|
// Now click on reply btn and cancel it on channel 7
|
||||||
@ -370,13 +370,13 @@ acceptance("Discourse Chat - without unread", function (needs) {
|
|||||||
|
|
||||||
// Go back to channel 9 and check that reply-to is present
|
// Go back to channel 9 and check that reply-to is present
|
||||||
await click(".chat-drawer-header__return-to-channels-btn");
|
await click(".chat-drawer-header__return-to-channels-btn");
|
||||||
await click(".chat-channel-row.chat-channel-9");
|
await click('.chat-channel-row[data-chat-channel-id="9"]');
|
||||||
// Now reply-to should be back and loaded from draft
|
// Now reply-to should be back and loaded from draft
|
||||||
assert.ok(exists(".chat-composer-message-details .chat-reply"));
|
assert.ok(exists(".chat-composer-message-details .chat-reply"));
|
||||||
|
|
||||||
// Go back one for time to channel 7 and make sure reply-to is gone
|
// Go back one for time to channel 7 and make sure reply-to is gone
|
||||||
await click(".chat-drawer-header__return-to-channels-btn");
|
await click(".chat-drawer-header__return-to-channels-btn");
|
||||||
await click(".chat-channel-row.chat-channel-11");
|
await click('.chat-channel-row[data-chat-channel-id="11"]');
|
||||||
assert.notOk(exists(".chat-composer-message-details .chat-reply"));
|
assert.notOk(exists(".chat-composer-message-details .chat-reply"));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -922,7 +922,7 @@ Widget.triangulate(arg: "test")
|
|||||||
await dropdown.expand();
|
await dropdown.expand();
|
||||||
await dropdown.selectRowByValue("selectMessage");
|
await dropdown.selectRowByValue("selectMessage");
|
||||||
await click("#chat-copy-btn");
|
await click("#chat-copy-btn");
|
||||||
await click("#chat-channel-row-9");
|
await click('.chat-channel-row[data-chat-channel-id="9"]');
|
||||||
|
|
||||||
assert.notOk(exists("#chat-copy-btn"));
|
assert.notOk(exists("#chat-copy-btn"));
|
||||||
});
|
});
|
||||||
@ -1065,7 +1065,7 @@ acceptance(
|
|||||||
visible(".chat-drawer-header__top-line--expanded"),
|
visible(".chat-drawer-header__top-line--expanded"),
|
||||||
"drawer is expanded"
|
"drawer is expanded"
|
||||||
);
|
);
|
||||||
await click("#chat-channel-row-9");
|
await click('.chat-channel-row[data-chat-channel-id="9"]');
|
||||||
await click(".chat-drawer-header__title");
|
await click(".chat-drawer-header__title");
|
||||||
assert.equal(currentURL(), `/chat/channel/9/site/info/members`);
|
assert.equal(currentURL(), `/chat/channel/9/site/info/members`);
|
||||||
});
|
});
|
||||||
@ -1142,7 +1142,7 @@ acceptance(
|
|||||||
test("drawer open to DM channel with unread messages with sidebar off", async function (assert) {
|
test("drawer open to DM channel with unread messages with sidebar off", async function (assert) {
|
||||||
await visit("/t/internationalization-localization/280");
|
await visit("/t/internationalization-localization/280");
|
||||||
await click(".header-dropdown-toggle.open-chat");
|
await click(".header-dropdown-toggle.open-chat");
|
||||||
await click("#chat-channel-row-75");
|
await click('.chat-channel-row[data-chat-channel-id="75"]');
|
||||||
const chatContainer = query(".chat-drawer");
|
const chatContainer = query(".chat-drawer");
|
||||||
assert.strictEqual(chatContainer.dataset.chatChannelId, "75");
|
assert.strictEqual(chatContainer.dataset.chatChannelId, "75");
|
||||||
});
|
});
|
||||||
|
@ -39,7 +39,7 @@ acceptance("Discourse Chat - Mobile test", function (needs) {
|
|||||||
await click(".header-dropdown-toggle.open-chat");
|
await click(".header-dropdown-toggle.open-chat");
|
||||||
assert.equal(currentURL(), "/chat");
|
assert.equal(currentURL(), "/chat");
|
||||||
assert.ok(exists(".channels-list"));
|
assert.ok(exists(".channels-list"));
|
||||||
await click(".chat-channel-row.chat-channel-7");
|
await click('.chat-channel-row[data-chat-channel-id="7"]');
|
||||||
assert.notOk(exists(".open-drawer-btn"));
|
assert.notOk(exists(".open-drawer-btn"));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ acceptance("Discourse Chat - User card test", function (needs) {
|
|||||||
test("user card has chat button that opens the correct channel", async function (assert) {
|
test("user card has chat button that opens the correct channel", async function (assert) {
|
||||||
await visit("/");
|
await visit("/");
|
||||||
await click(".header-dropdown-toggle.open-chat");
|
await click(".header-dropdown-toggle.open-chat");
|
||||||
await click(".chat-channel-row.chat-channel-9");
|
await click('.chat-channel-row[data-chat-channel-id="9"]');
|
||||||
await click("[data-user-card='hawk']");
|
await click("[data-user-card='hawk']");
|
||||||
|
|
||||||
assert.ok(exists(".user-card-chat-btn"));
|
assert.ok(exists(".user-card-chat-btn"));
|
||||||
|
@ -1,117 +1,178 @@
|
|||||||
import componentTest, {
|
import { module, test } from "qunit";
|
||||||
setupRenderingTest,
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||||
} from "discourse/tests/helpers/component-test";
|
import { render } from "@ember/test-helpers";
|
||||||
import { exists } from "discourse/tests/helpers/qunit-helpers";
|
import { hbs } from "ember-cli-htmlbars";
|
||||||
import hbs from "htmlbars-inline-precompile";
|
|
||||||
import fabricators from "../helpers/fabricators";
|
import fabricators from "../helpers/fabricators";
|
||||||
import { module } from "qunit";
|
|
||||||
|
|
||||||
module("Discourse Chat | Component | chat-channel-row", function (hooks) {
|
module("Discourse Chat | Component | chat-channel-row", function (hooks) {
|
||||||
setupRenderingTest(hooks);
|
setupRenderingTest(hooks);
|
||||||
|
|
||||||
componentTest("with leaveButton", {
|
hooks.beforeEach(function () {
|
||||||
template: hbs`{{chat-channel-row channel=channel options=(hash leaveButton=true)}}`,
|
this.categoryChatChannel = fabricators.chatChannel();
|
||||||
|
this.directMessageChatChannel = fabricators.directMessageChatChannel();
|
||||||
|
});
|
||||||
|
|
||||||
beforeEach() {
|
test("links to correct channel", async function (assert) {
|
||||||
this.set(
|
await render(hbs`<ChatChannelRow @channel={{this.categoryChatChannel}} />`);
|
||||||
"channel",
|
|
||||||
fabricators.chatChannel({
|
assert
|
||||||
current_user_membership: { following: true },
|
.dom(".chat-channel-row")
|
||||||
})
|
.hasAttribute("href", `/chat/channel/${this.categoryChatChannel.id}/-`);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("allows tabbing", async function (assert) {
|
||||||
|
await render(hbs`<ChatChannelRow @channel={{this.categoryChatChannel}} />`);
|
||||||
|
|
||||||
|
assert.dom(".chat-channel-row").hasAttribute("tabindex", "0");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("channel data attrite tabbing", async function (assert) {
|
||||||
|
await render(hbs`<ChatChannelRow @channel={{this.categoryChatChannel}} />`);
|
||||||
|
|
||||||
|
assert
|
||||||
|
.dom(".chat-channel-row")
|
||||||
|
.hasAttribute(
|
||||||
|
"data-chat-channel-id",
|
||||||
|
this.categoryChatChannel.id.toString()
|
||||||
);
|
);
|
||||||
},
|
|
||||||
|
|
||||||
async test(assert) {
|
|
||||||
assert.ok(exists(".toggle-channel-membership-button.-leave"));
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
componentTest("without leaveButton", {
|
test("renders correct channel title", async function (assert) {
|
||||||
template: hbs`{{chat-channel-row channel=channel}}`,
|
await render(hbs`<ChatChannelRow @channel={{this.categoryChatChannel}} />`);
|
||||||
|
|
||||||
beforeEach() {
|
assert.dom(".chat-channel-title").hasText(this.categoryChatChannel.title);
|
||||||
this.set("channel", fabricators.chatChannel());
|
|
||||||
},
|
|
||||||
|
|
||||||
async test(assert) {
|
|
||||||
assert.notOk(exists(".chat-channel-leave-btn"));
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
componentTest(
|
test("renders correct channel metadata", async function (assert) {
|
||||||
"a row is active when the associated channel is active and visible",
|
await render(hbs`<ChatChannelRow @channel={{this.categoryChatChannel}} />`);
|
||||||
{
|
|
||||||
template: hbs`{{chat-channel-row switchChannel=switchChannel channel=channel chat=chat router=router}}`,
|
|
||||||
|
|
||||||
beforeEach() {
|
assert
|
||||||
this.set("channel", fabricators.chatChannel());
|
.dom(".chat-channel-metadata")
|
||||||
this.set("chat", { activeChannel: this.channel });
|
.hasText(
|
||||||
this.set("router", { currentRouteName: "chat.channel" });
|
moment(this.categoryChatChannel.last_message_sent_at).format("l")
|
||||||
},
|
);
|
||||||
|
|
||||||
async test(assert) {
|
|
||||||
assert.ok(exists(".chat-channel-row.active"));
|
|
||||||
|
|
||||||
this.set("router.currentRouteName", "chat.browse");
|
|
||||||
|
|
||||||
assert.notOk(exists(".chat-channel-row.active"));
|
|
||||||
|
|
||||||
this.set("router.currentRouteName", "chat.channel");
|
|
||||||
this.set("chat.activeChannel", null);
|
|
||||||
|
|
||||||
assert.notOk(exists(".chat-channel-row.active"));
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
componentTest("can receive a tab event", {
|
|
||||||
template: hbs`{{chat-channel-row channel=channel}}`,
|
|
||||||
|
|
||||||
beforeEach() {
|
|
||||||
this.set("channel", fabricators.chatChannel());
|
|
||||||
},
|
|
||||||
|
|
||||||
async test(assert) {
|
|
||||||
assert.ok(exists(".chat-channel-row[tabindex=0]"));
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
componentTest("shows user status on the direct message channel", {
|
test("renders membership toggling button when necessary", async function (assert) {
|
||||||
template: hbs`{{chat-channel-row channel=channel}}`,
|
this.site.desktopView = false;
|
||||||
|
|
||||||
beforeEach() {
|
await render(hbs`<ChatChannelRow @channel={{this.categoryChatChannel}}/>`);
|
||||||
const status = { description: "Off to dentist", emoji: "tooth" };
|
|
||||||
const channel = fabricators.directMessageChatChannel();
|
|
||||||
channel.chatable.users[0].status = status;
|
|
||||||
this.set("channel", channel);
|
|
||||||
},
|
|
||||||
|
|
||||||
async test(assert) {
|
assert.dom(".toggle-channel-membership-button").doesNotExist();
|
||||||
assert.ok(exists(".user-status-message"));
|
|
||||||
},
|
this.categoryChatChannel.current_user_membership.following = true;
|
||||||
|
|
||||||
|
await render(hbs`<ChatChannelRow @channel={{this.categoryChatChannel}} />`);
|
||||||
|
|
||||||
|
assert.dom(".toggle-channel-membership-button").doesNotExist();
|
||||||
|
|
||||||
|
this.site.desktopView = true;
|
||||||
|
|
||||||
|
await render(
|
||||||
|
hbs`<ChatChannelRow @channel={{this.categoryChatChannel}} @options={{hash leaveButton=true}}/>`
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.dom(".toggle-channel-membership-button").exists();
|
||||||
});
|
});
|
||||||
|
|
||||||
componentTest(
|
test("focused channel has correct class", async function (assert) {
|
||||||
"doesn't show user status on a direct message channel with multiple users",
|
await render(hbs`<ChatChannelRow @channel={{this.categoryChatChannel}} />`);
|
||||||
{
|
|
||||||
template: hbs`{{chat-channel-row channel=channel}}`,
|
|
||||||
|
|
||||||
beforeEach() {
|
assert.dom(".chat-channel-row").doesNotHaveClass("focused");
|
||||||
const status = { description: "Off to dentist", emoji: "tooth" };
|
|
||||||
const channel = fabricators.directMessageChatChannel();
|
|
||||||
channel.chatable.users[0].status = status;
|
|
||||||
channel.chatable.users.push({
|
|
||||||
id: 2,
|
|
||||||
username: "bill",
|
|
||||||
name: null,
|
|
||||||
avatar_template: "/letter_avatar_proxy/v3/letter/t/31188e/{size}.png",
|
|
||||||
});
|
|
||||||
this.set("channel", channel);
|
|
||||||
},
|
|
||||||
|
|
||||||
async test(assert) {
|
this.categoryChatChannel.focused = true;
|
||||||
assert.notOk(exists(".user-status-message"));
|
|
||||||
},
|
await render(hbs`<ChatChannelRow @channel={{this.categoryChatChannel}} />`);
|
||||||
}
|
|
||||||
);
|
assert.dom(".chat-channel-row").hasClass("focused");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("muted channel has correct class", async function (assert) {
|
||||||
|
await render(hbs`<ChatChannelRow @channel={{this.categoryChatChannel}} />`);
|
||||||
|
|
||||||
|
assert.dom(".chat-channel-row").doesNotHaveClass("muted");
|
||||||
|
|
||||||
|
this.categoryChatChannel.current_user_membership.muted = true;
|
||||||
|
|
||||||
|
await render(hbs`<ChatChannelRow @channel={{this.categoryChatChannel}} />`);
|
||||||
|
|
||||||
|
assert.dom(".chat-channel-row").hasClass("muted");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("leaveButton options adds correct class", async function (assert) {
|
||||||
|
await render(hbs`<ChatChannelRow @channel={{this.categoryChatChannel}} />`);
|
||||||
|
|
||||||
|
assert.dom(".chat-channel-row").doesNotHaveClass("can-leave");
|
||||||
|
|
||||||
|
await render(
|
||||||
|
hbs`<ChatChannelRow @channel={{this.categoryChatChannel}} @options={{hash leaveButton=true}} />`
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.dom(".chat-channel-row").hasClass("can-leave");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("active channel adds correct class", async function (assert) {
|
||||||
|
await render(hbs`<ChatChannelRow @channel={{this.categoryChatChannel}} />`);
|
||||||
|
|
||||||
|
assert.dom(".chat-channel-row").doesNotHaveClass("active");
|
||||||
|
|
||||||
|
this.owner
|
||||||
|
.lookup("service:chat")
|
||||||
|
.set("activeChannel", { id: this.categoryChatChannel.id });
|
||||||
|
|
||||||
|
await render(hbs`<ChatChannelRow @channel={{this.categoryChatChannel}} />`);
|
||||||
|
|
||||||
|
assert.dom(".chat-channel-row").hasClass("active");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("unreads adds correct class", async function (assert) {
|
||||||
|
await render(hbs`<ChatChannelRow @channel={{this.categoryChatChannel}} />`);
|
||||||
|
|
||||||
|
assert.dom(".chat-channel-row").doesNotHaveClass("has-unread");
|
||||||
|
|
||||||
|
this.owner
|
||||||
|
.lookup("service:current-user")
|
||||||
|
.set("chat_channel_tracking_state", {
|
||||||
|
[this.categoryChatChannel.id]: { unread_count: 1 },
|
||||||
|
});
|
||||||
|
|
||||||
|
await render(hbs`<ChatChannelRow @channel={{this.categoryChatChannel}} />`);
|
||||||
|
|
||||||
|
assert.dom(".chat-channel-row").hasClass("has-unread");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("user status with category channel", async function (assert) {
|
||||||
|
await render(hbs`<ChatChannelRow @channel={{this.categoryChatChannel}} />`);
|
||||||
|
|
||||||
|
assert.dom(".user-status-message").doesNotExist();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("user status with direct message channel", async function (assert) {
|
||||||
|
const status = { description: "Off to dentist", emoji: "tooth" };
|
||||||
|
this.directMessageChatChannel.chatable.users[0].status = status;
|
||||||
|
|
||||||
|
await render(
|
||||||
|
hbs`<ChatChannelRow @channel={{this.directMessageChatChannel}} />`
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.dom(".user-status-message").exists();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("user status with direct message channel and multiple users", async function (assert) {
|
||||||
|
const status = { description: "Off to dentist", emoji: "tooth" };
|
||||||
|
this.directMessageChatChannel.chatable.users[0].status = status;
|
||||||
|
|
||||||
|
this.directMessageChatChannel.chatable.users.push({
|
||||||
|
id: 2,
|
||||||
|
username: "bill",
|
||||||
|
name: null,
|
||||||
|
avatar_template: "/letter_avatar_proxy/v3/letter/t/31188e/{size}.png",
|
||||||
|
});
|
||||||
|
|
||||||
|
await render(
|
||||||
|
hbs`<ChatChannelRow @channel={{this.directMessageChatChannel}} />`
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.dom(".user-status-message").doesNotExist();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user