2023-03-15 16:02:20 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require_relative "../../support/openai_completions_inference_stubs"
|
|
|
|
|
|
|
|
RSpec.describe "AI Composer helper", type: :system, js: true do
|
|
|
|
fab!(:user) { Fabricate(:admin) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
Group.find_by(id: Group::AUTO_GROUPS[:admins]).add(user)
|
|
|
|
SiteSetting.composer_ai_helper_enabled = true
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:composer) { PageObjects::Components::Composer.new }
|
|
|
|
let(:ai_helper_modal) { PageObjects::Modals::AiHelper.new }
|
|
|
|
|
|
|
|
context "when using the translation mode" do
|
2023-03-22 15:00:28 -04:00
|
|
|
let(:mode) { OpenAiCompletionsInferenceStubs::TRANSLATE }
|
2023-03-15 16:02:20 -04:00
|
|
|
|
|
|
|
before { OpenAiCompletionsInferenceStubs.stub_prompt(mode) }
|
|
|
|
|
|
|
|
it "replaces the composed message with AI generated content" do
|
|
|
|
visit("/latest")
|
|
|
|
page.find("#create-topic").click
|
|
|
|
|
|
|
|
composer.fill_content(OpenAiCompletionsInferenceStubs.spanish_text)
|
|
|
|
page.find(".composer-ai-helper").click
|
|
|
|
|
|
|
|
expect(ai_helper_modal).to be_visible
|
|
|
|
|
2023-04-10 10:04:42 -04:00
|
|
|
ai_helper_modal.select_helper_model(OpenAiCompletionsInferenceStubs.text_mode_to_id(mode))
|
2023-03-15 16:02:20 -04:00
|
|
|
ai_helper_modal.save_changes
|
|
|
|
|
|
|
|
expect(composer.composer_input.value).to eq(
|
|
|
|
OpenAiCompletionsInferenceStubs.translated_response.strip,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when using the proofreading mode" do
|
2023-03-22 15:00:28 -04:00
|
|
|
let(:mode) { OpenAiCompletionsInferenceStubs::PROOFREAD }
|
2023-03-15 16:02:20 -04:00
|
|
|
|
|
|
|
before { OpenAiCompletionsInferenceStubs.stub_prompt(mode) }
|
|
|
|
|
|
|
|
it "replaces the composed message with AI generated content" do
|
|
|
|
visit("/latest")
|
|
|
|
page.find("#create-topic").click
|
|
|
|
|
|
|
|
composer.fill_content(OpenAiCompletionsInferenceStubs.translated_response)
|
|
|
|
page.find(".composer-ai-helper").click
|
|
|
|
|
|
|
|
expect(ai_helper_modal).to be_visible
|
|
|
|
|
2023-04-10 10:04:42 -04:00
|
|
|
ai_helper_modal.select_helper_model(OpenAiCompletionsInferenceStubs.text_mode_to_id(mode))
|
2023-03-15 16:02:20 -04:00
|
|
|
ai_helper_modal.save_changes
|
|
|
|
|
|
|
|
expect(composer.composer_input.value).to eq(
|
|
|
|
OpenAiCompletionsInferenceStubs.proofread_response.strip,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when selecting an AI generated title" do
|
2023-03-22 15:00:28 -04:00
|
|
|
let(:mode) { OpenAiCompletionsInferenceStubs::GENERATE_TITLES }
|
2023-03-15 16:02:20 -04:00
|
|
|
|
|
|
|
before { OpenAiCompletionsInferenceStubs.stub_prompt(mode) }
|
|
|
|
|
|
|
|
it "replaces the topic title" do
|
|
|
|
visit("/latest")
|
|
|
|
page.find("#create-topic").click
|
|
|
|
|
|
|
|
composer.fill_content(OpenAiCompletionsInferenceStubs.translated_response)
|
|
|
|
page.find(".composer-ai-helper").click
|
|
|
|
|
|
|
|
expect(ai_helper_modal).to be_visible
|
|
|
|
|
2023-04-10 10:04:42 -04:00
|
|
|
ai_helper_modal.select_helper_model(OpenAiCompletionsInferenceStubs.text_mode_to_id(mode))
|
2023-03-15 16:02:20 -04:00
|
|
|
ai_helper_modal.select_title_suggestion(2)
|
|
|
|
ai_helper_modal.save_changes
|
|
|
|
|
|
|
|
expected_title = "The Quiet Piece that Moves Literature: A Gaucho's Story"
|
|
|
|
|
|
|
|
expect(find("#reply-title").value).to eq(expected_title)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|