FIX: Prevent proofreading when there is no content (#779)
This commit is contained in:
parent
a08d168740
commit
943504049c
|
@ -1,10 +1,23 @@
|
|||
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||
import i18n from "discourse-common/helpers/i18n";
|
||||
import ModalDiffModal from "../discourse/components/modal/diff-modal";
|
||||
|
||||
function initializeProofread(api) {
|
||||
api.addComposerToolbarPopupMenuOption({
|
||||
action: (toolbarEvent) => {
|
||||
const modal = api.container.lookup("service:modal");
|
||||
const composer = api.container.lookup("service:composer");
|
||||
const toasts = api.container.lookup("service:toasts");
|
||||
|
||||
if (composer.model.reply?.length === 0) {
|
||||
toasts.error({
|
||||
duration: 3000,
|
||||
data: {
|
||||
message: i18n("discourse_ai.ai_helper.proofread.no_content_error"),
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
modal.show(ModalDiffModal, {
|
||||
model: {
|
||||
|
|
|
@ -241,7 +241,6 @@ en:
|
|||
one: "This model is currently used by the %{settings} setting. If misconfigured, the feature won't work as expected."
|
||||
other: "This model is currently used by the following settings: %{settings}. If misconfigured, features won't work as expected. "
|
||||
|
||||
|
||||
preconfigured_llms: "Select your LLM"
|
||||
preconfigured:
|
||||
none: "Configure manually..."
|
||||
|
@ -331,6 +330,8 @@ en:
|
|||
prompt: "This post contains non-captioned images. Would you like to enable automatic AI captions on image uploads? (This can be changed in your preferences later)"
|
||||
confirm: "Enable"
|
||||
cancel: "Don't ask again"
|
||||
proofread:
|
||||
no_content_error: "Unable to proofread text, please add some content to proofread."
|
||||
|
||||
reviewables:
|
||||
model_used: "Model used:"
|
||||
|
|
|
@ -10,6 +10,7 @@ RSpec.describe "AI Composer Proofreading Features", type: :system, js: true do
|
|||
end
|
||||
|
||||
let(:composer) { PageObjects::Components::Composer.new }
|
||||
let(:toasts) { PageObjects::Components::Toasts.new }
|
||||
|
||||
it "proofreads selected text using the composer toolbar" do
|
||||
visit "/new-topic"
|
||||
|
@ -41,4 +42,16 @@ RSpec.describe "AI Composer Proofreading Features", type: :system, js: true do
|
|||
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
|
||||
ai_toolbar = PageObjects::Components::SelectKit.new(".toolbar-popup-menu-options")
|
||||
ai_toolbar.expand
|
||||
ai_toolbar.select_row_by_name("Proofread Text")
|
||||
expect(toasts).to have_error(I18n.t("js.discourse_ai.ai_helper.proofread.no_content_error"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue