DEV: Fix flakey upload spec (#1316)

This commit is contained in:
Isaac Janzen 2025-05-07 10:29:07 -05:00 committed by GitHub
parent c0e15501dd
commit f090065405
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 10 deletions

View File

@ -3,6 +3,7 @@ import Controller from "@ember/controller";
import { action } from "@ember/object"; import { action } from "@ember/object";
import { getOwner } from "@ember/owner"; import { getOwner } from "@ember/owner";
import { service } from "@ember/service"; import { service } from "@ember/service";
import { TrackedArray } from "@ember-compat/tracked-built-ins";
import { popupAjaxError } from "discourse/lib/ajax-error"; import { popupAjaxError } from "discourse/lib/ajax-error";
import UppyUpload from "discourse/lib/uppy/uppy-upload"; import UppyUpload from "discourse/lib/uppy/uppy-upload";
import UppyMediaOptimization from "discourse/lib/uppy-media-optimization-plugin"; import UppyMediaOptimization from "discourse/lib/uppy-media-optimization-plugin";
@ -15,7 +16,7 @@ export default class DiscourseAiBotConversations extends Controller {
@service site; @service site;
@service siteSettings; @service siteSettings;
@tracked uploads = []; @tracked uploads = new TrackedArray();
// Don't track this directly - we'll get it from uppyUpload // Don't track this directly - we'll get it from uppyUpload
textarea = null; textarea = null;
@ -46,8 +47,6 @@ export default class DiscourseAiBotConversations extends Controller {
init() { init() {
super.init(...arguments); super.init(...arguments);
this.uploads = [];
this.uppyUpload = new UppyUpload(getOwner(this), { this.uppyUpload = new UppyUpload(getOwner(this), {
id: "ai-bot-file-uploader", id: "ai-bot-file-uploader",
type: "ai-bot-conversation", type: "ai-bot-conversation",
@ -85,7 +84,7 @@ export default class DiscourseAiBotConversations extends Controller {
}, },
uploadDone: (upload) => { uploadDone: (upload) => {
this.uploads.pushObject(upload); this.uploads.push(upload);
}, },
// Fix: Don't try to set inProgressUploads directly // Fix: Don't try to set inProgressUploads directly
@ -162,7 +161,7 @@ export default class DiscourseAiBotConversations extends Controller {
@action @action
removeUpload(upload) { removeUpload(upload) {
this.uploads.removeObject(upload); this.uploads = new TrackedArray(this.uploads.filter((u) => u !== upload));
} }
@action @action
@ -178,7 +177,7 @@ export default class DiscourseAiBotConversations extends Controller {
this.aiBotConversationsHiddenSubmit.uploads = this.uploads; this.aiBotConversationsHiddenSubmit.uploads = this.uploads;
try { try {
await this.aiBotConversationsHiddenSubmit.submitToBot(); await this.aiBotConversationsHiddenSubmit.submitToBot();
this.uploads.clear(); this.uploads = new TrackedArray();
} catch (error) { } catch (error) {
popupAjaxError(error); popupAjaxError(error);
} }

View File

@ -90,7 +90,7 @@ export default RouteTemplate(
<DButton <DButton
@icon="xmark" @icon="xmark"
@action={{fn @controller.cancelUpload upload}} @action={{fn @controller.cancelUpload upload}}
class="btn-flat ai-bot-upload__remove" class="btn-flat ai-bot-upload__cancel"
/> />
</div> </div>
{{/each}} {{/each}}

View File

@ -138,8 +138,6 @@ RSpec.describe "AI Bot - Homepage", type: :system do
end end
it "allows removing an upload before submission" do it "allows removing an upload before submission" do
skip "TODO: fix this test for playwright"
ai_pm_homepage.visit ai_pm_homepage.visit
expect(ai_pm_homepage).to have_homepage expect(ai_pm_homepage).to have_homepage
@ -147,7 +145,6 @@ RSpec.describe "AI Bot - Homepage", type: :system do
attach_file([file_path]) { find(".ai-bot-upload-btn", visible: true).click } attach_file([file_path]) { find(".ai-bot-upload-btn", visible: true).click }
expect(page).to have_css(".ai-bot-upload", count: 1) expect(page).to have_css(".ai-bot-upload", count: 1)
# TODO: for some reason this line fails in playwright
find(".ai-bot-upload__remove").click find(".ai-bot-upload__remove").click
expect(page).to have_no_css(".ai-bot-upload") expect(page).to have_no_css(".ai-bot-upload")