discourse-ai/spec/system/ai_helper/ai_proofreading_spec.rb
Keegan George 9cd14b0003
DEV: Move composer AI helper to toolbar (#796)
Previously we had moved the AI helper from the options menu to a selection menu that appears when selecting text in the composer. This had the benefit of making the AI helper a more discoverable feature. Now that some time has passed and the AI helper is more recognized, we will be moving it back to the composer toolbar.

This is better because:
- It consistent with other behavior and ways of accessing tools in the composer
- It has an improved mobile experience
- It reduces unnecessary code and keeps things easier to migrate when we have composer V2.
- It allows for easily triggering AI helper for all content by clicking the button instead of having to select everything.
2024-09-13 11:59:30 -07:00

55 lines
1.8 KiB
Ruby

# frozen_string_literal: true
include SystemHelpers
RSpec.describe "AI Composer Proofreading Features", type: :system, js: true do
fab!(:admin) { Fabricate(:admin, refresh_auto_groups: true) }
before do
assign_fake_provider_to(:ai_helper_model)
SiteSetting.ai_helper_enabled = true
sign_in(admin)
end
let(:composer) { PageObjects::Components::Composer.new }
let(:toasts) { PageObjects::Components::Toasts.new }
let(:diff_modal) { PageObjects::Modals::DiffModal.new }
context "when triggering via keyboard shortcut" do
it "proofreads selected text using" do
visit "/new-topic"
composer.fill_content("hello worldd !")
composer.select_range(6, 12)
DiscourseAi::Completions::Llm.with_prepared_responses(["world"]) do
composer.composer_input.send_keys([PLATFORM_KEY_MODIFIER, :alt, "p"])
diff_modal.confirm_changes
expect(composer.composer_input.value).to eq("hello world !")
end
end
it "proofreads all text when nothing is selected" do
visit "/new-topic"
composer.fill_content("hello worrld")
# Simulate AI response
DiscourseAi::Completions::Llm.with_prepared_responses(["hello world"]) do
composer.composer_input.send_keys([PLATFORM_KEY_MODIFIER, :alt, "p"])
diff_modal.confirm_changes
expect(composer.composer_input.value).to eq("hello world")
end
end
it "does not trigger proofread modal if composer is empty" do
visit "/new-topic"
# Simulate AI response
DiscourseAi::Completions::Llm.with_prepared_responses(["hello world"]) do
composer.composer_input.send_keys([PLATFORM_KEY_MODIFIER, :alt, "p"])
expect(toasts).to have_error(I18n.t("js.discourse_ai.ai_helper.no_content_error"))
end
end
end
end