Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit efaeefe

Browse files
committed
DEV: Update specs
1 parent 32e62f4 commit efaeefe

File tree

4 files changed

+77
-21
lines changed

4 files changed

+77
-21
lines changed

assets/javascripts/discourse/components/ai-bot-sidebar-new-conversation.gjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export default class AiBotSidebarNewConversation extends Component {
66
@service router;
77

88
get show() {
9+
// don't show the new question button on the conversations home page
910
return this.router.currentRouteName !== "discourse-ai-bot-conversations";
1011
}
1112

assets/javascripts/discourse/services/ai-bot-conversations-hidden-submit.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ export default class AiBotConversationsHiddenSubmit extends Service {
3333
});
3434
}
3535

36+
// borrowed from ai-bot-helper.js
37+
const draftKey = "new_private_message_ai_" + new Date().getTime();
38+
3639
// this is a total hack, the composer is hidden on the homepage with CSS
3740
await this.composer.open({
3841
action: Composer.PRIVATE_MESSAGE,
39-
draftKey: "private_message_ai",
42+
draftKey,
4043
recipients: this.currentUser.ai_enabled_personas[0].username,
4144
topicTitle: i18n("discourse_ai.ai_bot.default_pm_prefix"),
4245
topicBody: this.inputValue,

assets/javascripts/initializers/ai-bot-sidebar.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,7 @@ export default {
5656
this.isFetching = false;
5757
this.buildSidebarLinks();
5858
})
59-
.catch((e) => {
60-
debugger;
61-
this.isFetching = false;
62-
});
59+
.catch(() => (this.isFetching = false));
6360
}
6461

6562
addNewMessage(newTopic) {

spec/system/ai_bot/personal_message_spec.rb

Lines changed: 71 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,69 @@
77
let(:sidebar) { PageObjects::Components::NavigationMenu::Sidebar.new }
88
let(:header_dropdown) { PageObjects::Components::NavigationMenu::HeaderDropdown.new }
99

10-
fab!(:user)
10+
11+
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
1112
fab!(:group)
1213

14+
fab!(:claude_2) do
15+
Fabricate(
16+
:llm_model,
17+
provider: "anthropic",
18+
url: "https://api.anthropic.com/v1/messages",
19+
name: "claude-2",
20+
)
21+
end
1322
fab!(:bot_user) do
14-
user = Fabricate(:user)
15-
AiPersona.last.update!(user_id: user.id)
16-
user
23+
toggle_enabled_bots(bots: [claude_2])
24+
SiteSetting.ai_bot_enabled = true
25+
claude_2.reload.user
26+
end
27+
fab!(:bot) do
28+
persona =
29+
AiPersona
30+
.find(DiscourseAi::Personas::Persona.system_personas[DiscourseAi::Personas::General])
31+
.class_instance
32+
.new
33+
DiscourseAi::Personas::Bot.as(bot_user, persona: persona)
1734
end
18-
fab!(:llm_model) { Fabricate(:llm_model, enabled_chat_bot: true) }
1935

20-
fab!(:pm) { Fabricate(:private_message_topic, title: "AI Conversation Test", user: user) }
21-
fab!(:reply) do
22-
Fabricate(:post, topic: pm, user: user, post_number: 1, raw: "test test test user reply")
36+
fab!(:pm) do
37+
Fabricate(
38+
:private_message_topic,
39+
title: "This is my special PM",
40+
user: user,
41+
topic_allowed_users: [
42+
Fabricate.build(:topic_allowed_user, user: user),
43+
Fabricate.build(:topic_allowed_user, user: bot_user),
44+
],
45+
)
46+
end
47+
fab!(:first_post) do
48+
Fabricate(:post, topic: pm, user: user, post_number: 1, raw: "This is a reply by the user")
49+
end
50+
fab!(:second_post) do
51+
Fabricate(:post, topic: pm, user: bot_user, post_number: 2, raw: "This is a bot reply")
2352
end
24-
fab!(:bot_reply) do
25-
Fabricate(:post, topic: pm, user: bot_user, post_number: 2, raw: "test test test bot reply")
53+
fab!(:third_post) do
54+
Fabricate(
55+
:post,
56+
topic: pm,
57+
user: user,
58+
post_number: 3,
59+
raw: "This is a second reply by the user",
60+
)
2661
end
2762
fab!(:topic_user) { Fabricate(:topic_user, topic: pm, user: user) }
2863
fab!(:topic_bot_user) { Fabricate(:topic_user, topic: pm, user: bot_user) }
2964

3065
before do
3166
SiteSetting.ai_enable_experimental_bot_ux = true
3267
SiteSetting.ai_bot_enabled = true
33-
toggle_enabled_bots(bots: [llm_model])
3468
SiteSetting.ai_bot_allowed_groups = group.id.to_s
35-
sign_in(user)
3669

3770
group.add(user)
3871
group.save
3972

40-
allowed_persona = AiPersona.last
41-
allowed_persona.update!(allowed_group_ids: [group.id], enabled: true)
42-
4373
sign_in(user)
4474
end
4575

@@ -88,7 +118,32 @@
88118

89119
expect(ai_pm_homepage).to have_homepage
90120
expect(sidebar).to have_section("custom-messages")
91-
expect(sidebar).to have_section_link(pm.title, href: pm.relative_url)
121+
expect(sidebar).to have_section_link(pm.title)
122+
expect(sidebar).to have_no_css("button.ai-new-question-button")
123+
end
124+
125+
it "navigates to the bot conversation when clicked" do
126+
visit "/"
127+
find(".ai-bot-button").click
128+
129+
expect(ai_pm_homepage).to have_homepage
130+
sidebar.find(
131+
".sidebar-section[data-section-name='custom-messages'] a.sidebar-section-link",
132+
).click
133+
expect(topic_page).to have_topic_title(pm.title)
134+
end
135+
136+
it "displays sidebar and 'new question' on the topic page" do
137+
topic_page.visit_topic(pm)
138+
expect(sidebar).to be_visible
139+
expect(sidebar).to have_css("button.ai-new-question-button")
140+
end
141+
142+
it "redirect to the homepage when 'new question' is clicked" do
143+
topic_page.visit_topic(pm)
144+
expect(sidebar).to be_visible
145+
sidebar.find("button.ai-new-question-button").click
146+
expect(ai_pm_homepage).to have_homepage
92147
end
93148
end
94149
end

0 commit comments

Comments
 (0)