discourse/plugins/chat/test/javascripts/components/chat-header-icon-test.gjs
Kris 98d594a7b3
FEATURE: AI header icon should remember last URL (#34108)
This change concerns these header icons

<img width="220" height="116" alt="image"
src="https://github.com/user-attachments/assets/eb7883cf-4766-4499-8d1a-116a542a2cdd"
/>


Currently the chat icon in the header switches to chat "mode" when
possible, and remembers your last forum location. The AI header icon
does not remember your last forum location, and just redirects you to
the homepage when you toggle it off.

This PR adds the last forum URL memory for the AI header icon as well. 
 
I've also updated the AI header icon to be a link when
`ai_bot_enable_dedicated_ux` is enabled, this way it can be opened in a
new tab and do all the typical link behavior (requested here:
https://meta.discourse.org/t/change-ai-bot-icon-to-link-element/377435).
It is still a button when `ai_bot_enable_dedicated_ux`, which is
appropriate for opening the composer.

This also updates the AI button title when the state changes (noted
here:
https://meta.discourse.org/t/ai-bot-header-button-title-doesnt-always-match-its-action/377402)
2025-08-08 09:12:22 +10:00

94 lines
3.1 KiB
Text

import { render } 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/controllers/preferences-chat";
module("Discourse Chat | Component | chat-header-icon", 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) {
forceMobile();
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 - 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");
});
});