Skip to content

Commit f090065

Browse files
authored
DEV: Fix flakey upload spec (#1316)
1 parent c0e1550 commit f090065

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

assets/javascripts/discourse/controllers/discourse-ai-bot-conversations.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Controller from "@ember/controller";
33
import { action } from "@ember/object";
44
import { getOwner } from "@ember/owner";
55
import { service } from "@ember/service";
6+
import { TrackedArray } from "@ember-compat/tracked-built-ins";
67
import { popupAjaxError } from "discourse/lib/ajax-error";
78
import UppyUpload from "discourse/lib/uppy/uppy-upload";
89
import UppyMediaOptimization from "discourse/lib/uppy-media-optimization-plugin";
@@ -15,7 +16,7 @@ export default class DiscourseAiBotConversations extends Controller {
1516
@service site;
1617
@service siteSettings;
1718

18-
@tracked uploads = [];
19+
@tracked uploads = new TrackedArray();
1920
// Don't track this directly - we'll get it from uppyUpload
2021

2122
textarea = null;
@@ -46,8 +47,6 @@ export default class DiscourseAiBotConversations extends Controller {
4647
init() {
4748
super.init(...arguments);
4849

49-
this.uploads = [];
50-
5150
this.uppyUpload = new UppyUpload(getOwner(this), {
5251
id: "ai-bot-file-uploader",
5352
type: "ai-bot-conversation",
@@ -85,7 +84,7 @@ export default class DiscourseAiBotConversations extends Controller {
8584
},
8685

8786
uploadDone: (upload) => {
88-
this.uploads.pushObject(upload);
87+
this.uploads.push(upload);
8988
},
9089

9190
// Fix: Don't try to set inProgressUploads directly
@@ -162,7 +161,7 @@ export default class DiscourseAiBotConversations extends Controller {
162161

163162
@action
164163
removeUpload(upload) {
165-
this.uploads.removeObject(upload);
164+
this.uploads = new TrackedArray(this.uploads.filter((u) => u !== upload));
166165
}
167166

168167
@action
@@ -178,7 +177,7 @@ export default class DiscourseAiBotConversations extends Controller {
178177
this.aiBotConversationsHiddenSubmit.uploads = this.uploads;
179178
try {
180179
await this.aiBotConversationsHiddenSubmit.submitToBot();
181-
this.uploads.clear();
180+
this.uploads = new TrackedArray();
182181
} catch (error) {
183182
popupAjaxError(error);
184183
}

assets/javascripts/discourse/templates/discourse-ai-bot-conversations.gjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export default RouteTemplate(
9090
<DButton
9191
@icon="xmark"
9292
@action={{fn @controller.cancelUpload upload}}
93-
class="btn-flat ai-bot-upload__remove"
93+
class="btn-flat ai-bot-upload__cancel"
9494
/>
9595
</div>
9696
{{/each}}

spec/system/ai_bot/homepage_spec.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,13 @@
138138
end
139139

140140
it "allows removing an upload before submission" do
141-
skip "TODO: fix this test for playwright"
142-
143141
ai_pm_homepage.visit
144142
expect(ai_pm_homepage).to have_homepage
145143

146144
file_path = file_from_fixtures("logo.png", "images").path
147145
attach_file([file_path]) { find(".ai-bot-upload-btn", visible: true).click }
148146
expect(page).to have_css(".ai-bot-upload", count: 1)
149147

150-
# TODO: for some reason this line fails in playwright
151148
find(".ai-bot-upload__remove").click
152149

153150
expect(page).to have_no_css(".ai-bot-upload")

0 commit comments

Comments
 (0)