|
7 | 7 | let(:sidebar) { PageObjects::Components::NavigationMenu::Sidebar.new } |
8 | 8 | let(:header_dropdown) { PageObjects::Components::NavigationMenu::HeaderDropdown.new } |
9 | 9 |
|
10 | | - fab!(:user) |
| 10 | + |
| 11 | + fab!(:user) { Fabricate(:user, refresh_auto_groups: true) } |
11 | 12 | fab!(:group) |
12 | 13 |
|
| 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 |
13 | 22 | 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) |
17 | 34 | end |
18 | | - fab!(:llm_model) { Fabricate(:llm_model, enabled_chat_bot: true) } |
19 | 35 |
|
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") |
23 | 52 | 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 | + ) |
26 | 61 | end |
27 | 62 | fab!(:topic_user) { Fabricate(:topic_user, topic: pm, user: user) } |
28 | 63 | fab!(:topic_bot_user) { Fabricate(:topic_user, topic: pm, user: bot_user) } |
29 | 64 |
|
30 | 65 | before do |
31 | 66 | SiteSetting.ai_enable_experimental_bot_ux = true |
32 | 67 | SiteSetting.ai_bot_enabled = true |
33 | | - toggle_enabled_bots(bots: [llm_model]) |
34 | 68 | SiteSetting.ai_bot_allowed_groups = group.id.to_s |
35 | | - sign_in(user) |
36 | 69 |
|
37 | 70 | group.add(user) |
38 | 71 | group.save |
39 | 72 |
|
40 | | - allowed_persona = AiPersona.last |
41 | | - allowed_persona.update!(allowed_group_ids: [group.id], enabled: true) |
42 | | - |
43 | 73 | sign_in(user) |
44 | 74 | end |
45 | 75 |
|
|
88 | 118 |
|
89 | 119 | expect(ai_pm_homepage).to have_homepage |
90 | 120 | 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 |
92 | 147 | end |
93 | 148 | end |
94 | 149 | end |
0 commit comments