This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/tests/integration/components/cook-text-test.js
Jarek Radosz dbcf722ab9
DEV: Modulize component tests (#11300)
It's like the new tests, but still old underneath!
2020-11-20 15:54:09 +01:00

55 lines
1.4 KiB
JavaScript

import {
queryAll,
discourseModule,
} from "discourse/tests/helpers/qunit-helpers";
import componentTest, {
setupRenderingTest,
} from "discourse/tests/helpers/component-test";
import pretender from "discourse/tests/helpers/create-pretender";
import { resetCache } from "pretty-text/upload-short-url";
discourseModule("Integration | Component | cook-text", function (hooks) {
setupRenderingTest(hooks);
componentTest("renders markdown", {
template: '{{cook-text "_foo_" class="post-body"}}',
test(assert) {
const html = queryAll(".post-body")[0].innerHTML.trim();
assert.equal(html, "<p><em>foo</em></p>");
},
});
componentTest("resolves short URLs", {
template: `{{cook-text "![an image](upload://a.png)" class="post-body"}}`,
beforeEach() {
pretender.post("/uploads/lookup-urls", () => {
return [
200,
{ "Content-Type": "application/json" },
[
{
short_url: "upload://a.png",
url: "/images/avatar.png",
short_path: "/images/d-logo-sketch.png",
},
],
];
});
},
afterEach() {
resetCache();
},
test(assert) {
const html = queryAll(".post-body")[0].innerHTML.trim();
assert.equal(
html,
'<p><img src="/images/avatar.png" alt="an image"></p>'
);
},
});
});