Skip to content

Commit ceef8b5

Browse files
committed
DEV: Continue with specs
1 parent 802a336 commit ceef8b5

File tree

6 files changed

+90
-41
lines changed

6 files changed

+90
-41
lines changed

assets/javascripts/discourse/connectors/topic-above-post-stream/ai-bot-conversation.gjs

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
import bodyClass from "discourse/helpers/body-class";
21
import Component from "@glimmer/component";
2+
import { service } from "@ember/service";
3+
import bodyClass from "discourse/helpers/body-class";
4+
5+
export default class AiBotConversation extends Component {
6+
@service siteSettings;
37

4-
export default class AiBotConversaion extends Component {
58
get show() {
6-
return this.args.outletArgs.model?.ai_persona_name
9+
return (
10+
this.siteSettings.ai_enable_experimental_bot_ux &&
11+
this.args.outletArgs.model?.pm_with_non_human_user
12+
);
713
}
814

915
<template>
@@ -12,4 +18,3 @@ export default class AiBotConversaion extends Component {
1218
{{/if}}
1319
</template>
1420
}
15-

assets/javascripts/discourse/controllers/discourse-ai-bot-conversations.js

-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import Controller from "@ember/controller";
2-
import { on } from "@ember/modifier";
3-
import { computed } from "@ember/object";
42
import { action } from "@ember/object";
5-
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
63
import { service } from "@ember/service";
7-
import DButton from "discourse/components/d-button";
8-
import bodyClass from "discourse/helpers/body-class";
9-
import { i18n } from "discourse-i18n";
104
import SimpleTextareaInteractor from "../lib/simple-textarea-interactor";
115

126
export default class DiscourseAiBotConversations extends Controller {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default class AiBotConversationsHiddenSubmit extends Service {
3737
await this.composer.open({
3838
action: Composer.PRIVATE_MESSAGE,
3939
draftKey: "private_message_ai",
40-
recipients: "DiscourseHelper", // TODO: Figure out how to grab the right bot
40+
recipients: this.currentUser.ai_enabled_personas[0].username,
4141
topicTitle: i18n("discourse_ai.ai_bot.default_pm_prefix"),
4242
topicBody: this.inputValue,
4343
archetypeId: "private_message",

assets/stylesheets/modules/ai-bot-conversations/common.scss

+9-7
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ body.discourse-ai-bot-conversations-page {
88
}
99

1010
#sidebar-section-content-community,
11-
[data-section-name=tags],
11+
[data-section-name="tags"],
1212
[data-section-name="categories"],
1313
[data-section-name="messages"],
14+
[data-section-name="user-threads"],
15+
[data-section-name="user-threads"],
16+
[data-section-name="chat-dms"],
1417
.sidebar-sections:not(.admin-panel)
15-
.sidebar-section-link
16-
.sidebar-section-link-prefix,
18+
.sidebar-section-link
19+
.sidebar-section-link-prefix,
1720
.sidebar-footer-wrapper,
1821
.sidebar__panel-switch-button {
1922
display: none;
@@ -308,9 +311,9 @@ body.discourse-ai-bot-conversations-page {
308311
content: "";
309312
width: 4em;
310313
background: linear-gradient(
311-
to right,
312-
rgba(var(--secondary-rgb), 0),
313-
rgba(var(--secondary-rgb), 1)
314+
to right,
315+
rgba(var(--secondary-rgb), 0),
316+
rgba(var(--secondary-rgb), 1)
314317
);
315318
right: 0;
316319
height: 2.5em;
@@ -469,7 +472,6 @@ body.discourse-ai-bot-conversations-page {
469472
}
470473
}
471474

472-
473475
@media screen and (max-width: 600px) {
474476
.share-ai-conversation-button {
475477
.d-icon {

spec/system/ai_bot/personal_message_spec.rb

+53-23
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,23 @@
33
RSpec.describe "AI Bot - Personal Message", type: :system do
44
let(:topic_page) { PageObjects::Pages::Topic.new }
55
let(:composer) { PageObjects::Components::Composer.new }
6+
let(:ai_pm_homepage) { PageObjects::Components::AiPmHomepage.new }
7+
let(:sidebar) { PageObjects::Components::NavigationMenu::Sidebar.new }
8+
let(:header_dropdown) { PageObjects::Components::NavigationMenu::HeaderDropdown.new }
69

710
fab!(:user)
811
fab!(:group)
9-
fab!(:gpt_4) { Fabricate(:llm_model, name: "gpt-4") }
10-
let(:bot_user) { DiscourseAi::AiBot::EntryPoint.find_user_from_model("gpt-4") }
1112

12-
let(:pm) do
13+
fab!(:bot_user) do
14+
user = Fabricate(:user)
15+
AiPersona.last.update!(user_id: user.id)
16+
user
17+
end
18+
fab!(:llm_model) do
19+
Fabricate(:llm_model, provider: "anthropic", name: "claude-3-opus", enabled_chat_bot: true)
20+
end
21+
22+
fab!(:pm) do
1323
Fabricate(
1424
:private_message_topic,
1525
title: "AI Conversation Test",
@@ -20,24 +30,12 @@
2030
],
2131
)
2232
end
23-
24-
let(:pm_posts) do
25-
posts = []
26-
i = 1
27-
3.times do
28-
posts << Fabricate(:post, topic: pm, user: user, raw: "test test test user reply #{i}")
29-
posts << Fabricate(:post, topic: pm, user: bot_user, raw: "test test test bot reply #{i}")
30-
i += 1
31-
end
32-
33-
posts
34-
end
33+
fab!(:reply) { Fabricate(:post, topic: pm, user: user, raw: "test test test user reply") }
34+
fab!(:bot_reply) { Fabricate(:post, topic: pm, user: bot_user, raw: "test test test bot reply") }
3535

3636
before do
3737
SiteSetting.ai_enable_experimental_bot_ux = true
38-
3938
SiteSetting.ai_bot_enabled = true
40-
toggle_enabled_bots(bots: [gpt_4])
4139
SiteSetting.ai_bot_allowed_groups = group.id.to_s
4240
sign_in(user)
4341

@@ -53,17 +51,49 @@
5351
it "has normal bot interaction when `ai_enable_experimental_bot_ux` is disabled" do
5452
SiteSetting.ai_enable_experimental_bot_ux = false
5553
visit "/"
56-
expect(page).to have_selector(".ai-bot-button")
5754
find(".ai-bot-button").click
5855

56+
expect(ai_pm_homepage).to have_no_homepage
5957
expect(composer).to be_opened
6058
end
6159

62-
it "renders landing page when `ai_enable_experimental_bot_ux` is enabled" do
63-
visit "/"
64-
expect(page).to have_selector(".ai-bot-button")
65-
find(".ai-bot-button").click
60+
context "when `ai_enable_experimental_bot_ux` is enabled" do
61+
it "renders landing page on bot click" do
62+
visit "/"
63+
find(".ai-bot-button").click
64+
expect(ai_pm_homepage).to have_homepage
65+
expect(sidebar).to be_visible
66+
end
67+
68+
it "renders sidebar even when navigation menu is set to header" do
69+
SiteSetting.navigation_menu = "header dropdown"
70+
visit "/"
71+
find(".ai-bot-button").click
72+
expect(ai_pm_homepage).to have_homepage
73+
expect(sidebar).to be_visible
74+
epxect(header_dropdown).to be_visible
75+
end
76+
77+
it "hides default content in the sidebar" do
78+
visit "/"
79+
find(".ai-bot-button").click
6680

67-
expect(page).to have_css(".custom-homepage__content-wrapper")
81+
expect(ai_pm_homepage).to have_homepage
82+
expect(sidebar).to have_no_tags_section
83+
expect(sidebar).to have_no_section("categories")
84+
expect(sidebar).to have_no_section("messages")
85+
expect(sidebar).to have_no_section("chat-dms")
86+
expect(sidebar).to have_no_section("chat-channels")
87+
expect(sidebar).to have_no_section("user-threads")
88+
end
89+
90+
it "shows the bot conversation in the sidebar" do
91+
visit "/"
92+
find(".ai-bot-button").click
93+
94+
expect(ai_pm_homepage).to have_homepage
95+
expect(sidebar).to have_section("custom-messages")
96+
expect(sidebar).to have_section_link(pm.title, href: pm.relative_url)
97+
end
6898
end
6999
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
module PageObjects
4+
module Components
5+
class AiPmHomepage < PageObjects::Components::Base
6+
HOMEPAGE_BODY_CLASS = ".discourse-ai-bot-conversations-page"
7+
HOMEPAGE_WRAPPER_CLASS = ".custom-homepage__content-wrapper"
8+
9+
def has_homepage?
10+
page.has_css?("#{HOMEPAGE_BODY_CLASS} #{HOMEPAGE_WRAPPER_CLASS}")
11+
end
12+
13+
def has_no_homepage?
14+
page.has_no_css?("#{HOMEPAGE_BODY_CLASS} #{HOMEPAGE_WRAPPER_CLASS}")
15+
end
16+
end
17+
end
18+
end

0 commit comments

Comments
 (0)