| 
2 | 2 | 
 
  | 
3 | 3 | RSpec.describe "AI Spam Configuration", type: :system, js: true do  | 
4 | 4 |   fab!(:admin)  | 
5 |  | -  let(:llm_model) { Fabricate(:llm_model) }  | 
6 | 5 | 
 
  | 
7 | 6 |   before do  | 
8 | 7 |     SiteSetting.discourse_ai_enabled = true  | 
9 | 8 |     sign_in(admin)  | 
10 | 9 |   end  | 
11 | 10 | 
 
  | 
12 |  | -  it "can properly configure spam settings" do  | 
13 |  | -    visit "/admin/plugins/discourse-ai/ai-spam"  | 
 | 11 | +  context "when no LLMs are configured" do  | 
 | 12 | +    it "shows the placeholder when no LLM is configured" do  | 
 | 13 | +      visit "/admin/plugins/discourse-ai/ai-spam"  | 
14 | 14 | 
 
  | 
15 |  | -    expect(page).to have_css(".ai-spam__llm-placeholder")  | 
 | 15 | +      expect(page).to have_css(".ai-spam__llm-placeholder")  | 
16 | 16 | 
 
  | 
17 |  | -    toggle = PageObjects::Components::DToggleSwitch.new(".ai-spam__toggle")  | 
 | 17 | +      toggle = PageObjects::Components::DToggleSwitch.new(".ai-spam__toggle")  | 
18 | 18 | 
 
  | 
19 |  | -    toggle.toggle  | 
20 |  | -    dialog = PageObjects::Components::Dialog.new  | 
21 |  | -    expect(dialog).to have_content(I18n.t("discourse_ai.llm.configuration.must_select_model"))  | 
22 |  | -    dialog.click_ok  | 
 | 19 | +      toggle.toggle  | 
 | 20 | +      dialog = PageObjects::Components::Dialog.new  | 
 | 21 | +      expect(dialog).to have_content(I18n.t("discourse_ai.llm.configuration.must_select_model"))  | 
 | 22 | +      dialog.click_ok  | 
23 | 23 | 
 
  | 
24 |  | -    expect(toggle.unchecked?).to eq(true)  | 
25 |  | - | 
26 |  | -    llm_model  | 
27 |  | -    visit "/admin/plugins/discourse-ai/ai-spam"  | 
 | 24 | +      expect(toggle.unchecked?).to eq(true)  | 
 | 25 | +    end  | 
 | 26 | +  end  | 
 | 27 | +  context "when LLMs are configured" do  | 
 | 28 | +    fab!(:llm_model)  | 
 | 29 | +    it "can properly configure spam settings" do  | 
 | 30 | +      visit "/admin/plugins/discourse-ai/ai-spam"  | 
28 | 31 | 
 
  | 
29 |  | -    toggle = PageObjects::Components::DToggleSwitch.new(".ai-spam__toggle")  | 
30 |  | -    toggle.toggle  | 
 | 32 | +      toggle = PageObjects::Components::DToggleSwitch.new(".ai-spam__toggle")  | 
 | 33 | +      toggle.toggle  | 
31 | 34 | 
 
  | 
32 |  | -    try_until_success { expect(AiModerationSetting.spam&.llm_model_id).to eq(llm_model.id) }  | 
 | 35 | +      try_until_success { expect(AiModerationSetting.spam&.llm_model_id).to eq(llm_model.id) }  | 
33 | 36 | 
 
  | 
34 |  | -    find(".ai-spam__instructions-input").fill_in(with: "Test spam detection instructions")  | 
35 |  | -    find(".ai-spam__instructions-save").click  | 
 | 37 | +      find(".ai-spam__instructions-input").fill_in(with: "Test spam detection instructions")  | 
 | 38 | +      find(".ai-spam__instructions-save").click  | 
36 | 39 | 
 
  | 
37 |  | -    toasts = PageObjects::Components::Toasts.new  | 
38 |  | -    expect(toasts).to have_content(I18n.t("js.discourse_ai.spam.settings_saved"))  | 
 | 40 | +      toasts = PageObjects::Components::Toasts.new  | 
 | 41 | +      expect(toasts).to have_content(I18n.t("js.discourse_ai.spam.settings_saved"))  | 
39 | 42 | 
 
  | 
40 |  | -    expect(AiModerationSetting.spam.custom_instructions).to eq("Test spam detection instructions")  | 
 | 43 | +      expect(AiModerationSetting.spam.custom_instructions).to eq("Test spam detection instructions")  | 
41 | 44 | 
 
  | 
42 |  | -    visit "/admin/plugins/discourse-ai/ai-llms"  | 
 | 45 | +      visit "/admin/plugins/discourse-ai/ai-llms"  | 
43 | 46 | 
 
  | 
44 |  | -    expect(find(".ai-llm-list-editor__usages")).to have_content(  | 
45 |  | -      I18n.t("js.discourse_ai.llms.usage.ai_spam"),  | 
46 |  | -    )  | 
 | 47 | +      expect(find(".ai-llm-list-editor__usages")).to have_content(  | 
 | 48 | +        I18n.t("js.discourse_ai.llms.usage.ai_spam"),  | 
 | 49 | +      )  | 
 | 50 | +    end  | 
47 | 51 |   end  | 
48 | 52 | end  | 
0 commit comments