0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-14 13:58:53 +08:00
discourse/plugins/chat/test/javascripts/components/chat-header-icon-test.gjs
Martin Brennan 79d1c792eb
DEV: Update test module name conventions (#40389)
Currently, most of the JS test modules follow this
convention:

```
module("Integration | Component | topic-dismiss-buttons"
```

Which is a legacy from when ember components etc were
rendered in templates like this:

```
{{d-button title="foo"}}
```

Instead, this commit updates all of them to follow this
PascalCase convention:

```
module("Integration | Component | TopicDismissButtons", function (hooks) {
```

No linting is added to enforce this, we suspect that it's
mostly a result of cargo culting, and people will add new
tests following PascalCase convention.

Also adds an initial AI skill for writing JS tests.
2026-05-29 15:19:55 +10:00

109 lines
3.4 KiB
Text
Vendored

import { tracked } from "@glimmer/tracking";
import { render, settled } from "@ember/test-helpers";
import { module, test } from "qunit";
import sinon from "sinon";
import { forceMobile } from "discourse/lib/mobile";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { i18n } from "discourse-i18n";
import Icon from "discourse/plugins/chat/discourse/components/chat/header/icon";
import { HEADER_INDICATOR_PREFERENCE_ALL_NEW } from "discourse/plugins/chat/discourse/lib/chat-constants";
module("Component | ChatHeaderIcon", function (hooks) {
setupRenderingTest(hooks);
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(<template><Icon /></template>);
assert
.dom(".icon.btn-flat")
.hasAttribute("title", i18n("chat.title_capitalized"))
.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(<template><Icon /></template>);
assert
.dom(".icon.btn-flat")
.hasAttribute("title", i18n("chat.exit"))
.hasAttribute("href", "/latest");
assert.dom(".d-icon-shuffle").exists();
});
test("mobile", async function (assert) {
const testState = new (class {
@tracked isActive = false;
})();
forceMobile();
await render(
<template><Icon @isActive={{testState.isActive}} /></template>
);
assert
.dom(".icon.btn-flat")
.hasAttribute("title", i18n("chat.title_capitalized"))
.hasAttribute("href", "/chat");
assert
.dom(".d-icon-d-chat")
.exists("chat icon is rendered if chat is inactive");
testState.isActive = true;
await settled();
assert
.dom(".d-icon-d-chat")
.doesNotExist("chat icon is not rendered if chat is active");
});
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(<template><Icon @urgentCount={{1}} /></template>);
assert
.dom(".icon.btn-flat")
.hasAttribute("title", i18n("chat.exit"))
.hasAttribute("href", "/latest");
assert.dom(".d-icon-shuffle").exists();
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(<template><Icon @urgentCount={{1}} /></template>);
assert
.dom(".icon.btn-flat")
.hasAttribute("title", i18n("sidebar.panels.chat.label"))
.hasAttribute("href", "/chat");
assert.dom(".d-icon-d-chat").exists();
assert
.dom(".chat-channel-unread-indicator__number")
.exists()
.containsText("1");
});
});