mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-07-12 17:13:29 +00:00
DEV: Improve AI bot conversation submit upload handling (#1497)
Try fix a flaky spec in /ai_bot/homepage_spec.rb by using ember data rather than inspecting the DOM directly to see if there are any in-progress uploads. Also add missing translation for in progress uploads warning.
This commit is contained in:
parent
d54cd1f602
commit
6b5ea38644
@ -260,10 +260,11 @@ export default class AiBotConversations extends Component {
|
||||
|
||||
@action
|
||||
async prepareAndSubmitToBot() {
|
||||
// Pass uploads to the service before submitting
|
||||
this.aiBotConversationsHiddenSubmit.uploads = this.uploads;
|
||||
try {
|
||||
await this.aiBotConversationsHiddenSubmit.submitToBot();
|
||||
await this.aiBotConversationsHiddenSubmit.submitToBot({
|
||||
uploads: this.uploads,
|
||||
inProgressUploadsCount: this.inProgressUploads.length,
|
||||
});
|
||||
this.uploads = new TrackedArray();
|
||||
} catch (error) {
|
||||
popupAjaxError(error);
|
||||
|
@ -18,7 +18,6 @@ export default class AiBotConversationsHiddenSubmit extends Service {
|
||||
|
||||
personaId;
|
||||
targetUsername;
|
||||
uploads = [];
|
||||
|
||||
inputValue = "";
|
||||
|
||||
@ -32,7 +31,7 @@ export default class AiBotConversationsHiddenSubmit extends Service {
|
||||
}
|
||||
|
||||
@action
|
||||
async submitToBot() {
|
||||
async submitToBot(uploadData) {
|
||||
if (
|
||||
this.inputValue.length <
|
||||
this.siteSettings.min_personal_message_post_length
|
||||
@ -48,7 +47,7 @@ export default class AiBotConversationsHiddenSubmit extends Service {
|
||||
}
|
||||
|
||||
// Don't submit if there are still uploads in progress
|
||||
if (document.querySelector(".ai-bot-upload--in-progress")) {
|
||||
if (uploadData.inProgressUploadsCount > 0) {
|
||||
return this.dialog.alert({
|
||||
message: i18n("discourse_ai.ai_bot.conversations.uploads_in_progress"),
|
||||
});
|
||||
@ -61,10 +60,10 @@ export default class AiBotConversationsHiddenSubmit extends Service {
|
||||
let rawContent = this.inputValue;
|
||||
|
||||
// Append upload markdown if we have uploads
|
||||
if (this.uploads && this.uploads.length > 0) {
|
||||
if (uploadData.uploads && uploadData.uploads.length > 0) {
|
||||
rawContent += "\n\n";
|
||||
|
||||
this.uploads.forEach((upload) => {
|
||||
uploadData.uploads.forEach((upload) => {
|
||||
const uploadMarkdown = getUploadMarkdown(upload);
|
||||
rawContent += uploadMarkdown + "\n";
|
||||
});
|
||||
@ -83,7 +82,6 @@ export default class AiBotConversationsHiddenSubmit extends Service {
|
||||
});
|
||||
|
||||
// Reset uploads after successful submission
|
||||
this.uploads = [];
|
||||
this.inputValue = "";
|
||||
|
||||
this.appEvents.trigger("discourse-ai:bot-pm-created", {
|
||||
|
@ -872,6 +872,7 @@ en:
|
||||
last_7_days: "Last 7 days"
|
||||
last_30_days: "Last 30 days"
|
||||
upload_files: "Upload files"
|
||||
uploads_in_progress: "Cannot submit while uploads are in progress"
|
||||
sentiments:
|
||||
dashboard:
|
||||
title: "Sentiment"
|
||||
|
@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe "AI Bot - Homepage", type: :system do
|
||||
let(:cdp) { PageObjects::CDP.new }
|
||||
let(:topic_page) { PageObjects::Pages::Topic.new }
|
||||
let(:composer) { PageObjects::Components::Composer.new }
|
||||
let(:ai_pm_homepage) { PageObjects::Components::AiPmHomepage.new }
|
||||
@ -164,6 +165,28 @@ RSpec.describe "AI Bot - Homepage", type: :system do
|
||||
expect(page).to have_no_css(".ai-bot-upload")
|
||||
end
|
||||
|
||||
it "shows an error when trying to submit while uploads are in progress" do
|
||||
ai_pm_homepage.visit
|
||||
expect(ai_pm_homepage).to have_homepage
|
||||
|
||||
file_path_1 = file_from_fixtures("logo.png", "images").path
|
||||
file_path_2 = file_from_fixtures("logo.jpg", "images").path
|
||||
|
||||
ai_pm_homepage.input.fill_in(with: "Some message to send to AI with uploads")
|
||||
|
||||
cdp.with_slow_upload do
|
||||
attach_file([file_path_1, file_path_2]) do
|
||||
find(".ai-bot-upload-btn", visible: true).click
|
||||
end
|
||||
expect(page).to have_css(".ai-bot-upload--in-progress", count: 2)
|
||||
|
||||
ai_pm_homepage.submit
|
||||
expect(page).to have_content(
|
||||
I18n.t("js.discourse_ai.ai_bot.conversations.uploads_in_progress"),
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
it "allows removing an upload before submission" do
|
||||
ai_pm_homepage.visit
|
||||
expect(ai_pm_homepage).to have_homepage
|
||||
|
Loading…
x
Reference in New Issue
Block a user