Using arrow functions changes `this` context, which is undesired in tests, e.g. it makes it impossible to setup things like pretender (`this.server`) in `beforeEach` hooks. Ember guides always use classic functions in examples (e.g. https://guides.emberjs.com/release/testing/test-types/), and that's what it uses in its own test suite, as do various addons and ember apps. It was also already used in Discourse where `this` was required. Moving forward, it will be needed in more places as we migrate toward ember-cli. (I might later add a custom rule to eslint-discourse-ember to enforce this)
58 lines
1.8 KiB
JavaScript
58 lines
1.8 KiB
JavaScript
import { queryAll } from "discourse/tests/helpers/qunit-helpers";
|
|
import { click, fillIn, visit } from "@ember/test-helpers";
|
|
import { test } from "qunit";
|
|
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
|
|
|
function pretender(server, helper) {
|
|
server.post("/uploads/lookup-urls", () => {
|
|
return helper.response([
|
|
{
|
|
short_url: "upload://asdsad.png",
|
|
url: "/secure-media-uploads/default/3X/1/asjdiasjdiasida.png",
|
|
short_path: "/uploads/short-url/asdsad.png",
|
|
},
|
|
]);
|
|
});
|
|
}
|
|
|
|
async function writeInComposer(assert) {
|
|
await visit("/t/internationalization-localization/280");
|
|
await click("#topic-footer-buttons .btn.create");
|
|
|
|
await fillIn(".d-editor-input", "[test](upload://abcdefg.png)");
|
|
|
|
assert.equal(
|
|
queryAll(".d-editor-preview:visible").html().trim(),
|
|
'<p><a href="/404">test</a></p>'
|
|
);
|
|
|
|
await fillIn(".d-editor-input", "[test|attachment](upload://asdsad.png)");
|
|
}
|
|
|
|
acceptance("Composer Attachment", function (needs) {
|
|
needs.user();
|
|
needs.pretender(pretender);
|
|
|
|
test("attachments are cooked properly", async function (assert) {
|
|
await writeInComposer(assert);
|
|
assert.equal(
|
|
queryAll(".d-editor-preview:visible").html().trim(),
|
|
'<p><a class="attachment" href="/uploads/short-url/asdsad.png">test</a></p>'
|
|
);
|
|
});
|
|
});
|
|
|
|
acceptance("Composer Attachment - Secure Media Enabled", function (needs) {
|
|
needs.user();
|
|
needs.settings({ secure_media: true });
|
|
needs.pretender(pretender);
|
|
|
|
test("attachments are cooked properly when secure media is enabled", async function (assert) {
|
|
await writeInComposer(assert);
|
|
assert.equal(
|
|
queryAll(".d-editor-preview:visible").html().trim(),
|
|
'<p><a class="attachment" href="/secure-media-uploads/default/3X/1/asjdiasjdiasida.png">test</a></p>'
|
|
);
|
|
});
|
|
});
|