mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
More Qunit tests including a CLI runner
This commit is contained in:
parent
8e96299653
commit
60fce196c7
11 changed files with 289 additions and 97 deletions
|
@ -1,9 +1,9 @@
|
|||
/*global module:true test:true ok:true visit:true expect:true exists:true count:true equal:true */
|
||||
/*global module:true test:true ok:true visit:true expect:true exists:true count:true equal:true present:true md5:true */
|
||||
|
||||
module("Discourse.BBCode");
|
||||
|
||||
var format = function(input, expected, text) {
|
||||
equal(Discourse.BBCode.format(input), expected, text);
|
||||
equal(Discourse.BBCode.format(input, {lookupAvatar: false}), expected, text);
|
||||
}
|
||||
|
||||
test('basic bbcode', function() {
|
||||
|
@ -36,4 +36,74 @@ test('tags with arguments', function() {
|
|||
format("[email=eviltrout@mailinator.com]evil trout[/email]", "<a href=\"mailto:eviltrout@mailinator.com\">evil trout</a>", "supports [email] with a title");
|
||||
format("[u][i]abc[/i][/u]", "<span class='bbcode-u'><span class='bbcode-i'>abc</span></span>", "can nest tags");
|
||||
format("[b]first[/b] [b]second[/b]", "<span class='bbcode-b'>first</span> <span class='bbcode-b'>second</span>", "can bold two things on the same line");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test("quotes", function() {
|
||||
|
||||
var post = Discourse.Post.create({
|
||||
cooked: "<p><b>lorem</b> ipsum</p>",
|
||||
username: "eviltrout",
|
||||
post_number: 1,
|
||||
topic_id: 2
|
||||
});
|
||||
|
||||
var formatQuote = function(val, expected, text) {
|
||||
equal(Discourse.BBCode.buildQuoteBBCode(post, val), 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 when the quote is the full message");
|
||||
|
||||
formatQuote("**lorem** ipsum",
|
||||
"[quote=\"eviltrout, post:1, topic:2, full:true\"]\n**lorem** ipsum\n[/quote]\n\n",
|
||||
"keeps BBCode formatting");
|
||||
|
||||
});
|
||||
|
||||
test("quote formatting", function() {
|
||||
|
||||
// TODO: This HTML matching is quite ugly.
|
||||
format("[quote=\"eviltrout, post:1, topic:1\"]abc[/quote]",
|
||||
"</p><aside class='quote' data-post=\"1\" data-topic=\"1\" >\n <div class='title'>\n " +
|
||||
"<div class='quote-controls'></div>\n \n eviltrout\n said:\n </div>\n <blockquote>abc</blockquote>\n</aside>\n<p>",
|
||||
"renders quotes properly");
|
||||
|
||||
format("[quote=\"eviltrout, post:1, topic:1\"]abc[quote=\"eviltrout, post:2, topic:2\"]nested[/quote][/quote]",
|
||||
"</p><aside class='quote' data-post=\"1\" data-topic=\"1\" >\n <div class='title'>\n <div " +
|
||||
"class='quote-controls'></div>\n \n eviltrout\n said:\n </div>\n <blockquote>abc</p><aside " +
|
||||
"class='quote' data-post=\"2\" data-topic=\"2\" >\n <div class='title'>\n <div class='quote-" +
|
||||
"controls'></div>\n \n eviltrout\n said:\n </div>\n <blockquote>nested</blockquote>\n</aside>\n<p></blockquote>\n</aside>\n<p>",
|
||||
"can nest quotes");
|
||||
|
||||
format("before[quote=\"eviltrout, post:1, topic:1\"]first[/quote]middle[quote=\"eviltrout, post:2, topic:2\"]second[/quote]after",
|
||||
"before</p><aside class='quote' data-post=\"1\" data-topic=\"1\" >\n <div class='title'>\n <div class='quote-cont" +
|
||||
"rols'></div>\n \n eviltrout\n said:\n </div>\n <blockquote>first</blockquote>\n</aside>\n<p>middle</p><aside cla" +
|
||||
"ss='quote' data-post=\"2\" data-topic=\"2\" >\n <div class='title'>\n <div class='quote-controls'></div>\n \n " +
|
||||
"eviltrout\n said:\n </div>\n <blockquote>second</blockquote>\n</aside>\n<p>after",
|
||||
"can handle more than one quote");
|
||||
|
||||
});
|
||||
|
||||
|
||||
test("extract quotes", function() {
|
||||
|
||||
var q = "[quote=\"eviltrout, post:1, topic:2\"]hello[/quote]";
|
||||
var result = Discourse.BBCode.extractQuotes(q + " world");
|
||||
|
||||
equal(result.text, md5(q) + "\n world");
|
||||
present(result.template);
|
||||
|
||||
});
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ var testObj = Em.Object.createWithMixins(Discourse.Presence, {
|
|||
nonEmptyString: "Evil Trout",
|
||||
emptyArray: [],
|
||||
nonEmptyArray: [1, 2, 3],
|
||||
age: 34,
|
||||
age: 34
|
||||
});
|
||||
|
||||
test("present", function() {
|
||||
|
@ -18,7 +18,6 @@ test("present", function() {
|
|||
ok(testObj.present('age'), "integers are present");
|
||||
});
|
||||
|
||||
|
||||
test("blank", function() {
|
||||
ok(testObj.blank('emptyString'), "Empty strings are blank");
|
||||
ok(!testObj.blank('nonEmptyString'), "Non empty strings are not blank");
|
||||
|
|
34
test/javascripts/mixins/selected_posts_count_test.js
Normal file
34
test/javascripts/mixins/selected_posts_count_test.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*global module:true test:true ok:true visit:true expect:true exists:true count:true equal:true */
|
||||
module("Discourse.SelectedPostsCount");
|
||||
|
||||
var buildTestObj = function(params, topicParams) {
|
||||
return Ember.Object.createWithMixins(Discourse.SelectedPostsCount, params || {});
|
||||
};
|
||||
|
||||
test("without selectedPosts", function () {
|
||||
var testObj = buildTestObj();
|
||||
|
||||
equal(testObj.get('selectedPostsCount'), 0, "No posts are selected without a selectedPosts property");
|
||||
|
||||
testObj.set('selectedPosts', []);
|
||||
equal(testObj.get('selectedPostsCount'), 0, "No posts are selected when selectedPosts is an empty array");
|
||||
});
|
||||
|
||||
test("with some selectedPosts", function() {
|
||||
var testObj = buildTestObj({ selectedPosts: [Discourse.Post.create()] });
|
||||
equal(testObj.get('selectedPostsCount'), 1, "It returns the amount of posts");
|
||||
});
|
||||
|
||||
test("when all posts are selected and there is a posts_count", function() {
|
||||
var testObj = buildTestObj({ allPostsSelected: true, posts_count: 1024 });
|
||||
equal(testObj.get('selectedPostsCount'), 1024, "It returns the posts_count");
|
||||
});
|
||||
|
||||
test("when all posts are selected and there is topic with a posts_count", function() {
|
||||
var testObj = buildTestObj({
|
||||
allPostsSelected: true,
|
||||
topic: Discourse.Topic.create({ posts_count: 3456 })
|
||||
});
|
||||
|
||||
equal(testObj.get('selectedPostsCount'), 3456, "It returns the topic's posts_count");
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue