2023-08-19 02:33:07 +08:00
|
|
|
import { render } from "@ember/test-helpers";
|
|
|
|
import { hbs } from "ember-cli-htmlbars";
|
2023-10-11 02:38:59 +08:00
|
|
|
import { module, test } from "qunit";
|
2023-08-19 02:33:07 +08:00
|
|
|
import sinon from "sinon";
|
2023-10-11 02:38:59 +08:00
|
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
2024-11-20 04:45:18 +08:00
|
|
|
import { i18n } from 'discourse-i18n';
|
2023-09-02 18:06:40 +08:00
|
|
|
import { HEADER_INDICATOR_PREFERENCE_ALL_NEW } from "discourse/plugins/chat/discourse/controllers/preferences-chat";
|
2023-08-19 02:33:07 +08:00
|
|
|
|
|
|
|
module("Discourse Chat | Component | chat-header-icon", function (hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
|
|
|
hooks.beforeEach(function () {});
|
|
|
|
|
|
|
|
test("full page - never separated sidebar mode", async function (assert) {
|
|
|
|
this.currentUser.user_option.chat_separate_sidebar_mode = "never";
|
|
|
|
sinon
|
|
|
|
.stub(this.owner.lookup("service:chat-state-manager"), "isFullPageActive")
|
|
|
|
.value(true);
|
|
|
|
|
|
|
|
await render(hbs`<Chat::Header::Icon />`);
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom(".icon.btn-flat")
|
2024-11-20 04:45:18 +08:00
|
|
|
.hasAttribute("title", i18n("chat.title_capitalized"))
|
2023-08-19 02:33:07 +08:00
|
|
|
.hasAttribute("href", "/chat");
|
|
|
|
|
|
|
|
assert.dom(".d-icon-d-chat").exists();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("full page - always separated mode", async function (assert) {
|
|
|
|
this.currentUser.user_option.chat_separate_sidebar_mode = "always";
|
|
|
|
sinon
|
|
|
|
.stub(this.owner.lookup("service:chat-state-manager"), "isFullPageActive")
|
|
|
|
.value(true);
|
|
|
|
|
|
|
|
await render(hbs`<Chat::Header::Icon />`);
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom(".icon.btn-flat")
|
2024-11-20 04:45:18 +08:00
|
|
|
.hasAttribute("title", i18n("sidebar.panels.forum.label"))
|
2023-08-19 02:33:07 +08:00
|
|
|
.hasAttribute("href", "/latest");
|
|
|
|
|
2024-09-13 23:50:52 +08:00
|
|
|
assert.dom(".d-icon-shuffle").exists();
|
2023-08-19 02:33:07 +08:00
|
|
|
});
|
2023-08-19 04:32:43 +08:00
|
|
|
|
|
|
|
test("mobile", async function (assert) {
|
|
|
|
this.site.mobileView = true;
|
|
|
|
|
|
|
|
await render(hbs`<Chat::Header::Icon />`);
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom(".icon.btn-flat")
|
2024-11-20 04:45:18 +08:00
|
|
|
.hasAttribute("title", i18n("chat.title_capitalized"))
|
2023-08-19 04:32:43 +08:00
|
|
|
.hasAttribute("href", "/chat");
|
|
|
|
|
|
|
|
assert.dom(".d-icon-d-chat").exists();
|
|
|
|
});
|
2023-09-02 18:06:40 +08:00
|
|
|
|
|
|
|
test("full page - with unread", async function (assert) {
|
|
|
|
this.currentUser.user_option.chat_separate_sidebar_mode = "always";
|
|
|
|
this.currentUser.user_option.chat_header_indicator_preference =
|
|
|
|
HEADER_INDICATOR_PREFERENCE_ALL_NEW;
|
|
|
|
|
|
|
|
sinon
|
|
|
|
.stub(this.owner.lookup("service:chat-state-manager"), "isFullPageActive")
|
|
|
|
.value(true);
|
|
|
|
|
|
|
|
await render(hbs`<Chat::Header::Icon @urgentCount={{1}} />`);
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom(".icon.btn-flat")
|
2024-11-20 04:45:18 +08:00
|
|
|
.hasAttribute("title", i18n("sidebar.panels.forum.label"))
|
2023-09-02 18:06:40 +08:00
|
|
|
.hasAttribute("href", "/latest");
|
2024-09-13 23:50:52 +08:00
|
|
|
assert.dom(".d-icon-shuffle").exists();
|
2023-09-02 18:06:40 +08:00
|
|
|
assert.dom(".chat-channel-unread-indicator__number").doesNotExist();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("drawer - with unread", async function (assert) {
|
|
|
|
this.currentUser.user_option.chat_separate_sidebar_mode = "always";
|
|
|
|
this.currentUser.user_option.chat_header_indicator_preference =
|
|
|
|
HEADER_INDICATOR_PREFERENCE_ALL_NEW;
|
|
|
|
|
|
|
|
await render(hbs`<Chat::Header::Icon @urgentCount={{1}} />`);
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom(".icon.btn-flat")
|
2024-11-20 04:45:18 +08:00
|
|
|
.hasAttribute("title", i18n("sidebar.panels.chat.label"))
|
2023-09-02 18:06:40 +08:00
|
|
|
.hasAttribute("href", "/chat");
|
|
|
|
assert.dom(".d-icon-d-chat").exists();
|
|
|
|
assert
|
|
|
|
.dom(".chat-channel-unread-indicator__number")
|
|
|
|
.exists()
|
|
|
|
.containsText("1");
|
|
|
|
});
|
2023-08-19 02:33:07 +08:00
|
|
|
});
|