A platform for community discussion. Free, open, simple.
DEV: Extract build-quote tests (#21217)
Jarek Radosz9e2a490f7982
diff --git a/app/assets/javascripts/discourse/tests/unit/lib/build-quote-test.js b/app/assets/javascripts/discourse/tests/unit/lib/build-quote-test.jsnew file mode 100644index 00000000000..fc742da9cdd--- /dev/null+++ b/app/assets/javascripts/discourse/tests/unit/lib/build-quote-test.js@@ -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"+ );+ });+});diff --git a/app/assets/javascripts/discourse/tests/unit/lib/pretty-text-test.js b/app/assets/javascripts/discourse/tests/unit/lib/pretty-text-test.jsindex 085a971f700..5886c320874 100644--- a/app/assets/javascripts/discourse/tests/unit/lib/pretty-text-test.js+++ b/app/assets/javascripts/discourse/tests/unit/lib/pretty-text-test.js@@ -4,12 +4,10 @@ import {deleteCachedInlineOnebox,} from "pretty-text/inline-oneboxer";import QUnit, { module, test } from "qunit";-import { buildQuote } from "discourse/lib/quote";import { deepMerge } from "discourse-common/lib/object";import { extractDataAttribute } from "pretty-text/engines/discourse-markdown-it";import { registerEmoji } from "pretty-text/emoji";import { IMAGE_VERSION as v } from "pretty-text/emoji/version";-import { getOwner } from "discourse-common/lib/get-owner";const rawOpts = {siteSettings: {@@ -440,6 +438,24 @@ eviltrout</p></aside>`,"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) {@@ -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) {assert.cooked('[quote="EvilTrout, post:123, topic:456, full:true"]\n[sam]\n[/quote]',