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/unit/lib/text-test.js
2022-11-08 09:52:11 +10:00

38 lines
1.3 KiB
JavaScript

import { module, test } from "qunit";
import { cookAsync, excerpt, parseAsync } from "discourse/lib/text";
module("Unit | Utility | text", function () {
test("parseAsync", async function (assert) {
await parseAsync("**test**").then((tokens) => {
assert.strictEqual(
tokens[1].children[1].type,
"strong_open",
"it parses the raw markdown"
);
});
});
test("excerpt", async function (assert) {
let cooked = await cookAsync("Hello! :wave:");
assert.strictEqual(
await excerpt(cooked, 300),
'Hello! <img src="/images/emoji/twitter/wave.png?v=12" title=":wave:" class="emoji" alt=":wave:" loading="lazy" width="20" height="20">'
);
cooked = await cookAsync("[:wave:](https://example.com)");
assert.strictEqual(
await excerpt(cooked, 300),
'<a href="https://example.com"><img src="/images/emoji/twitter/wave.png?v=12" title=":wave:" class="emoji only-emoji" alt=":wave:" loading="lazy" width="20" height="20"></a>'
);
cooked = await cookAsync('<script>alert("hi")</script>');
assert.strictEqual(await excerpt(cooked, 300), "");
cooked = await cookAsync("[`<script>alert('hi')</script>`]()");
assert.strictEqual(
await excerpt(cooked, 300),
"<a><code>&lt;script&gt;alert('hi')&lt;/script&gt;</code></a>"
);
});
});