FIX: Reply broken when auto caption is enabled (#642)

This commit is contained in:
Keegan George 2024-05-27 12:17:35 -07:00 committed by GitHub
parent a1c649965f
commit 90c5e4bb0e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 37 additions and 6 deletions

View File

@ -161,6 +161,11 @@ export default apiInitializer("1.25.0", (api) => {
const imageUploads = composer.model.reply.match(IMAGE_MARKDOWN_REGEX);
const hasImageUploads = imageUploads?.length > 0;
if (!hasImageUploads) {
resolve();
}
const imagesToCaption = imageUploads.filter((image) => {
const caption = image
.substring(image.indexOf("[") + 1, image.indexOf("]"))
@ -181,12 +186,7 @@ export default apiInitializer("1.25.0", (api) => {
const autoCaptionPromptKey = "ai-auto-caption-seen";
const seenAutoCaptionPrompt = keyValueStore.getItem(autoCaptionPromptKey);
if (
autoCaptionEnabled ||
!hasImageUploads ||
!needsBetterCaptions ||
seenAutoCaptionPrompt
) {
if (autoCaptionEnabled || !needsBetterCaptions || seenAutoCaptionPrompt) {
return resolve();
}

View File

@ -4,6 +4,9 @@ RSpec.describe "AI image caption", type: :system, js: true do
fab!(:user) { Fabricate(:admin, refresh_auto_groups: true) }
fab!(:non_member_group) { Fabricate(:group) }
let(:user_preferences_ai_page) { PageObjects::Pages::UserPreferencesAi.new }
let(:topic_page) { PageObjects::Pages::Topic.new }
fab!(:topic)
fab!(:post) { Fabricate(:post, topic: topic) }
let(:composer) { PageObjects::Components::Composer.new }
let(:popup) { PageObjects::Components::AiCaptionPopup.new }
let(:dialog) { PageObjects::Components::Dialog.new }
@ -150,5 +153,33 @@ RSpec.describe "AI image caption", type: :system, js: true do
end
end
end
context "when a post has no uploads" do
before { user.user_option.update!(auto_image_caption: true) }
it "should create the topic without triggering auto caption" do
title = "I love using Discourse! It is my favorite forum software"
visit("/latest")
page.find("#create-topic").click
composer.fill_title(title)
composer.fill_content(
"Culpa labore velit cupidatat commodo magna esse et minim consequat veniam dolore eiusmod. Labore eu elit in nulla ipsum elit consectetur sunt consectetur enim. Cillum ex ex velit eiusmod labore ullamco ut ad. Dolore dolor commodo nisi fugiat esse quis anim officia quis. Pariatur cillum pariatur irure cupidatat nostrud ullamco labore id aliqua ut nostrud. Eu adipisicing ut laboris.",
)
composer.create
expect(dialog).to be_closed
expect(topic_page).to have_topic_title(title)
end
it "should create a reply to a post without triggering auto caption" do
visit("/t/-/#{topic.id}")
topic_page.click_footer_reply
composer.fill_content(
"Culpa labore velit cupidatat commodo magna esse et minim consequat veniam dolore eiusmod. Labore eu elit in nulla ipsum elit consectetur sunt consectetur enim. Cillum ex ex velit eiusmod labore ullamco ut ad. Dolore dolor commodo nisi fugiat esse quis anim officia quis. Pariatur cillum pariatur irure cupidatat nostrud ullamco labore id aliqua ut nostrud. Eu adipisicing ut laboris.",
)
composer.create
expect(dialog).to be_closed
expect(topic_page).to have_post_number(post.post_number)
end
end
end
end