discourse/plugins/discourse-ai/spec/system/ai_bot/header_toggle_spec.rb
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

65 lines
1.9 KiB
Ruby
Vendored

# frozen_string_literal: true
RSpec.describe "AI Bot - Header Toggle", type: :system do
let(:topic_page) { PageObjects::Pages::Topic.new }
let(:ai_pm_homepage) { PageObjects::Components::AiPmHomepage.new }
let(:header) { PageObjects::Pages::DiscourseAi::Header.new }
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
fab!(:group)
fab!(:regular_topic) { Fabricate(:topic) }
fab!(:gpt_4) { Fabricate(:llm_model, name: "gpt-4") }
fab!(:gpt_3_5_turbo) { Fabricate(:llm_model, name: "gpt-3.5-turbo") }
before do
enable_current_plugin
SiteSetting.ai_bot_enabled = true
toggle_enabled_bots(bots: [gpt_4, gpt_3_5_turbo])
SiteSetting.ai_bot_allowed_groups = group.id.to_s
SiteSetting.ai_bot_enable_dedicated_ux = true
SiteSetting.ai_bot_add_to_header = true
SiteSetting.navigation_menu = "sidebar"
group.add(user)
group.save
allowed_persona = AiPersona.last
allowed_persona.update!(allowed_group_ids: [group.id], enabled: true)
sign_in(user)
end
it "remembers the last forum URL and returns to it when toggling" do
visit "/hot"
header.click_bot_button
expect(ai_pm_homepage).to have_homepage
expect(header).to have_icon_in_bot_button(icon: "shuffle")
header.click_bot_button
expect(header).to have_icon_in_bot_button(icon: "robot")
expect(page).to have_current_path("/hot")
end
it "updates stored forum URL when navigating between forum pages" do
visit "/hot"
header.click_bot_button
expect(ai_pm_homepage).to have_homepage
header.click_bot_button
expect(header).to have_icon_in_bot_button(icon: "robot")
expect(page).to have_current_path("/hot")
visit "/categories"
expect(page).to have_current_path("/categories")
header.click_bot_button
expect(ai_pm_homepage).to have_homepage
header.click_bot_button
expect(header).to have_icon_in_bot_button(icon: "robot")
expect(page).to have_current_path("/categories")
end
end