diff --git a/app/assets/javascripts/admin/addon/components/watched-word-uploader.js b/app/assets/javascripts/admin/addon/components/watched-word-uploader.js index 8c2864b69b1..efbacb9c0b3 100644 --- a/app/assets/javascripts/admin/addon/components/watched-word-uploader.js +++ b/app/assets/javascripts/admin/addon/components/watched-word-uploader.js @@ -3,7 +3,6 @@ import I18n from "I18n"; import UppyUploadMixin from "discourse/mixins/uppy-upload"; import { alias } from "@ember/object/computed"; import bootbox from "bootbox"; -import discourseComputed from "discourse-common/utils/decorators"; export default Component.extend(UppyUploadMixin, { type: "txt", @@ -16,9 +15,8 @@ export default Component.extend(UppyUploadMixin, { return { skipValidation: true }; }, - @discourseComputed("actionKey") - data(actionKey) { - return { action_key: actionKey }; + _perFileData() { + return { action_key: this.actionKey }; }, uploadDone() { diff --git a/app/assets/javascripts/discourse/tests/integration/components/watched-word-uploader-test.js b/app/assets/javascripts/discourse/tests/integration/components/watched-word-uploader-test.js new file mode 100644 index 00000000000..04f65e36ccc --- /dev/null +++ b/app/assets/javascripts/discourse/tests/integration/components/watched-word-uploader-test.js @@ -0,0 +1,57 @@ +import componentTest, { + setupRenderingTest, +} from "discourse/tests/helpers/component-test"; +import { + createFile, + discourseModule, +} from "discourse/tests/helpers/qunit-helpers"; +import hbs from "htmlbars-inline-precompile"; +import pretender, { response } from "discourse/tests/helpers/create-pretender"; +import { click, waitFor } from "@ember/test-helpers"; +import { isLegacyEmber } from "discourse-common/config/environment"; + +if (!isLegacyEmber()) { + discourseModule( + "Integration | Component | watched-word-uploader", + function (hooks) { + setupRenderingTest(hooks); + + hooks.beforeEach(function () { + pretender.post( + "/admin/customize/watched_words/upload.json", + function () { + return response(200, {}); + } + ); + }); + + componentTest("sets the proper action key on uploads", { + template: hbs`{{watched-word-uploader + id="watched-word-uploader" + actionKey=actionNameKey + done=doneUpload + }}`, + + async test(assert) { + const done = assert.async(); + this.set("actionNameKey", "flag"); + this.set("doneUpload", function () { + assert.equal( + Object.entries(this._uppyInstance.getState().files)[0][1].meta + .action_key, + "flag" + ); + done(); + }); + + const words = createFile("watched-words.txt"); + await this.container + .lookup("service:app-events") + .trigger("upload-mixin:watched-word-uploader:add-files", words); + await waitFor(".bootbox span.d-button-label"); + await click(".bootbox span.d-button-label"); + }, + }); + } + ); +}