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

View File

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

View File

@ -138,8 +138,6 @@ RSpec.describe "AI Bot - Homepage", type: :system do
end
it "allows removing an upload before submission" do
skip "TODO: fix this test for playwright"
ai_pm_homepage.visit
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 }
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
expect(page).to have_no_css(".ai-bot-upload")