53 lines
1.6 KiB
Ruby
Raw Permalink Normal View History

2024-12-12 09:17:25 +11:00
# frozen_string_literal: true
RSpec.describe "AI Spam Configuration", type: :system, js: true do
fab!(:admin)
before do
SiteSetting.discourse_ai_enabled = true
sign_in(admin)
end
2025-07-17 11:36:19 -07:00
context "when no LLMs are configured" do
it "shows the placeholder when no LLM is configured" do
visit "/admin/plugins/discourse-ai/ai-spam"
2024-12-12 09:17:25 +11:00
2025-07-17 11:36:19 -07:00
expect(page).to have_css(".ai-spam__llm-placeholder")
2024-12-12 09:17:25 +11:00
2025-07-17 11:36:19 -07:00
toggle = PageObjects::Components::DToggleSwitch.new(".ai-spam__toggle")
2024-12-12 09:17:25 +11:00
2025-07-17 11:36:19 -07:00
toggle.toggle
dialog = PageObjects::Components::Dialog.new
expect(dialog).to have_content(I18n.t("discourse_ai.llm.configuration.must_select_model"))
dialog.click_ok
2024-12-12 09:17:25 +11:00
2025-07-17 11:36:19 -07:00
expect(toggle.unchecked?).to eq(true)
end
end
context "when LLMs are configured" do
fab!(:llm_model)
it "can properly configure spam settings" do
visit "/admin/plugins/discourse-ai/ai-spam"
2024-12-12 09:17:25 +11:00
2025-07-17 11:36:19 -07:00
toggle = PageObjects::Components::DToggleSwitch.new(".ai-spam__toggle")
toggle.toggle
2024-12-12 09:17:25 +11:00
2025-07-17 11:36:19 -07:00
try_until_success { expect(AiModerationSetting.spam&.llm_model_id).to eq(llm_model.id) }
2024-12-12 09:17:25 +11:00
2025-07-17 11:36:19 -07:00
find(".ai-spam__instructions-input").fill_in(with: "Test spam detection instructions")
find(".ai-spam__instructions-save").click
2024-12-12 09:17:25 +11:00
2025-07-17 11:36:19 -07:00
toasts = PageObjects::Components::Toasts.new
expect(toasts).to have_content(I18n.t("js.discourse_ai.spam.settings_saved"))
2024-12-12 09:17:25 +11:00
2025-07-17 11:36:19 -07:00
expect(AiModerationSetting.spam.custom_instructions).to eq("Test spam detection instructions")
2024-12-12 09:17:25 +11:00
2025-07-17 11:36:19 -07:00
visit "/admin/plugins/discourse-ai/ai-llms"
2024-12-12 09:17:25 +11:00
2025-07-17 11:36:19 -07:00
expect(find(".ai-llm-list-editor__usages")).to have_content(
I18n.t("js.discourse_ai.llms.usage.ai_spam"),
)
end
2024-12-12 09:17:25 +11:00
end
end