mirror of
https://github.com/discourse/discourse.git
synced 2025-02-16 16:24:55 +00:00
DEV: Extract build-quote tests (#21217)
They are not related to pretty-text.
This commit is contained in:
parent
b0bc37fd96
commit
9e2a490f79
@ -0,0 +1,82 @@
|
|||||||
|
import { module, test } from "qunit";
|
||||||
|
import { setupTest } from "ember-qunit";
|
||||||
|
import { getOwner } from "discourse-common/lib/get-owner";
|
||||||
|
import { buildQuote } from "discourse/lib/quote";
|
||||||
|
import PrettyText from "pretty-text/pretty-text";
|
||||||
|
|
||||||
|
module("Unit | Utility | build-quote", function (hooks) {
|
||||||
|
setupTest(hooks);
|
||||||
|
|
||||||
|
test("quotes", function (assert) {
|
||||||
|
const store = getOwner(this).lookup("service:store");
|
||||||
|
const post = store.createRecord("post", {
|
||||||
|
cooked: "<p><b>lorem</b> ipsum</p>",
|
||||||
|
username: "eviltrout",
|
||||||
|
post_number: 1,
|
||||||
|
topic_id: 2,
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.strictEqual(
|
||||||
|
buildQuote(post, undefined),
|
||||||
|
"",
|
||||||
|
"empty string for undefined content"
|
||||||
|
);
|
||||||
|
assert.strictEqual(
|
||||||
|
buildQuote(post, null),
|
||||||
|
"",
|
||||||
|
"empty string for null content"
|
||||||
|
);
|
||||||
|
assert.strictEqual(
|
||||||
|
buildQuote(post, ""),
|
||||||
|
"",
|
||||||
|
"empty string for empty string content"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.strictEqual(
|
||||||
|
buildQuote(post, "lorem"),
|
||||||
|
'[quote="eviltrout, post:1, topic:2"]\nlorem\n[/quote]\n\n',
|
||||||
|
"correctly formats quotes"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.strictEqual(
|
||||||
|
buildQuote(post, " lorem \t "),
|
||||||
|
'[quote="eviltrout, post:1, topic:2"]\nlorem\n[/quote]\n\n',
|
||||||
|
"trims white spaces before & after the quoted contents"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.strictEqual(
|
||||||
|
buildQuote(post, "lorem ipsum", { full: true }),
|
||||||
|
'[quote="eviltrout, post:1, topic:2, full:true"]\nlorem ipsum\n[/quote]\n\n',
|
||||||
|
"marks quotes as full if the `full` option is passed"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.strictEqual(
|
||||||
|
buildQuote(post, "**lorem** ipsum"),
|
||||||
|
'[quote="eviltrout, post:1, topic:2"]\n**lorem** ipsum\n[/quote]\n\n',
|
||||||
|
"keeps BBCode formatting"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("quoting a quote", function (assert) {
|
||||||
|
const store = getOwner(this).lookup("service:store");
|
||||||
|
const post = store.createRecord("post", {
|
||||||
|
cooked: new PrettyText().cook(
|
||||||
|
'[quote="sam, post:1, topic:1, full:true"]\nhello\n[/quote]\n*Test*'
|
||||||
|
),
|
||||||
|
username: "eviltrout",
|
||||||
|
post_number: 1,
|
||||||
|
topic_id: 2,
|
||||||
|
});
|
||||||
|
|
||||||
|
const quote = buildQuote(
|
||||||
|
post,
|
||||||
|
'[quote="sam, post:1, topic:1, full:true"]\nhello\n[/quote]'
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.strictEqual(
|
||||||
|
quote,
|
||||||
|
'[quote="eviltrout, post:1, topic:2"]\n[quote="sam, post:1, topic:1, full:true"]\nhello\n[/quote]\n[/quote]\n\n',
|
||||||
|
"allows quoting a quote"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
@ -4,12 +4,10 @@ import {
|
|||||||
deleteCachedInlineOnebox,
|
deleteCachedInlineOnebox,
|
||||||
} from "pretty-text/inline-oneboxer";
|
} from "pretty-text/inline-oneboxer";
|
||||||
import QUnit, { module, test } from "qunit";
|
import QUnit, { module, test } from "qunit";
|
||||||
import { buildQuote } from "discourse/lib/quote";
|
|
||||||
import { deepMerge } from "discourse-common/lib/object";
|
import { deepMerge } from "discourse-common/lib/object";
|
||||||
import { extractDataAttribute } from "pretty-text/engines/discourse-markdown-it";
|
import { extractDataAttribute } from "pretty-text/engines/discourse-markdown-it";
|
||||||
import { registerEmoji } from "pretty-text/emoji";
|
import { registerEmoji } from "pretty-text/emoji";
|
||||||
import { IMAGE_VERSION as v } from "pretty-text/emoji/version";
|
import { IMAGE_VERSION as v } from "pretty-text/emoji/version";
|
||||||
import { getOwner } from "discourse-common/lib/get-owner";
|
|
||||||
|
|
||||||
const rawOpts = {
|
const rawOpts = {
|
||||||
siteSettings: {
|
siteSettings: {
|
||||||
@ -440,6 +438,24 @@ eviltrout</p>
|
|||||||
</aside>`,
|
</aside>`,
|
||||||
"quote has group class"
|
"quote has group class"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
assert.cooked(
|
||||||
|
"[quote]\ntest\n[/quote]",
|
||||||
|
'<aside class="quote no-group">\n<blockquote>\n<p>test</p>\n</blockquote>\n</aside>',
|
||||||
|
"it supports quotes without params"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.cooked(
|
||||||
|
"[quote]\n*test*\n[/quote]",
|
||||||
|
'<aside class="quote no-group">\n<blockquote>\n<p><em>test</em></p>\n</blockquote>\n</aside>',
|
||||||
|
"it doesn't insert a new line for italics"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.cooked(
|
||||||
|
"[quote=,script='a'><script>alert('test');//':a]\n[/quote]",
|
||||||
|
'<aside class="quote no-group">\n<blockquote></blockquote>\n</aside>',
|
||||||
|
"It will not create a script tag within an attribute"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Incomplete quotes", function (assert) {
|
test("Incomplete quotes", function (assert) {
|
||||||
@ -1273,90 +1289,6 @@ eviltrout</p>
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("quotes", function (assert) {
|
|
||||||
const store = getOwner(this).lookup("service:store");
|
|
||||||
const post = store.createRecord("post", {
|
|
||||||
cooked: "<p><b>lorem</b> ipsum</p>",
|
|
||||||
username: "eviltrout",
|
|
||||||
post_number: 1,
|
|
||||||
topic_id: 2,
|
|
||||||
});
|
|
||||||
|
|
||||||
function formatQuote(val, expected, text, opts) {
|
|
||||||
assert.strictEqual(buildQuote(post, val, opts), expected, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
formatQuote(undefined, "", "empty string for undefined content");
|
|
||||||
formatQuote(null, "", "empty string for null content");
|
|
||||||
formatQuote("", "", "empty string for empty string content");
|
|
||||||
|
|
||||||
formatQuote(
|
|
||||||
"lorem",
|
|
||||||
'[quote="eviltrout, post:1, topic:2"]\nlorem\n[/quote]\n\n',
|
|
||||||
"correctly formats quotes"
|
|
||||||
);
|
|
||||||
|
|
||||||
formatQuote(
|
|
||||||
" lorem \t ",
|
|
||||||
'[quote="eviltrout, post:1, topic:2"]\nlorem\n[/quote]\n\n',
|
|
||||||
"trims white spaces before & after the quoted contents"
|
|
||||||
);
|
|
||||||
|
|
||||||
formatQuote(
|
|
||||||
"lorem ipsum",
|
|
||||||
'[quote="eviltrout, post:1, topic:2, full:true"]\nlorem ipsum\n[/quote]\n\n',
|
|
||||||
"marks quotes as full if the `full` option is passed",
|
|
||||||
{ full: true }
|
|
||||||
);
|
|
||||||
|
|
||||||
formatQuote(
|
|
||||||
"**lorem** ipsum",
|
|
||||||
'[quote="eviltrout, post:1, topic:2"]\n**lorem** ipsum\n[/quote]\n\n',
|
|
||||||
"keeps BBCode formatting"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert.cooked(
|
|
||||||
"[quote]\ntest\n[/quote]",
|
|
||||||
'<aside class="quote no-group">\n<blockquote>\n<p>test</p>\n</blockquote>\n</aside>',
|
|
||||||
"it supports quotes without params"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert.cooked(
|
|
||||||
"[quote]\n*test*\n[/quote]",
|
|
||||||
'<aside class="quote no-group">\n<blockquote>\n<p><em>test</em></p>\n</blockquote>\n</aside>',
|
|
||||||
"it doesn't insert a new line for italics"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert.cooked(
|
|
||||||
"[quote=,script='a'><script>alert('test');//':a]\n[/quote]",
|
|
||||||
'<aside class="quote no-group">\n<blockquote></blockquote>\n</aside>',
|
|
||||||
"It will not create a script tag within an attribute"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("quoting a quote", function (assert) {
|
|
||||||
const store = getOwner(this).lookup("service:store");
|
|
||||||
const post = store.createRecord("post", {
|
|
||||||
cooked: new PrettyText(defaultOpts).cook(
|
|
||||||
'[quote="sam, post:1, topic:1, full:true"]\nhello\n[/quote]\n*Test*'
|
|
||||||
),
|
|
||||||
username: "eviltrout",
|
|
||||||
post_number: 1,
|
|
||||||
topic_id: 2,
|
|
||||||
});
|
|
||||||
|
|
||||||
const quote = buildQuote(
|
|
||||||
post,
|
|
||||||
'[quote="sam, post:1, topic:1, full:true"]\nhello\n[/quote]'
|
|
||||||
);
|
|
||||||
|
|
||||||
assert.strictEqual(
|
|
||||||
quote,
|
|
||||||
'[quote="eviltrout, post:1, topic:2"]\n[quote="sam, post:1, topic:1, full:true"]\nhello\n[/quote]\n[/quote]\n\n',
|
|
||||||
"allows quoting a quote"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("quote formatting", function (assert) {
|
test("quote formatting", function (assert) {
|
||||||
assert.cooked(
|
assert.cooked(
|
||||||
'[quote="EvilTrout, post:123, topic:456, full:true"]\n[sam]\n[/quote]',
|
'[quote="EvilTrout, post:123, topic:456, full:true"]\n[sam]\n[/quote]',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user