mirror of
https://github.com/discourse/discourse.git
synced 2025-06-05 14:07:30 +08:00
Extra tests for composer
This commit is contained in:
@ -114,7 +114,6 @@ test("right clicks are tracked", function() {
|
||||
Discourse.SiteSettings.track_external_right_clicks = true;
|
||||
trackRightClick();
|
||||
equal($('a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42");
|
||||
Discourse.SiteSettings.track_external_right_clicks = false;
|
||||
});
|
||||
|
||||
|
||||
|
@ -1,2 +1,3 @@
|
||||
/*jshint maxlen:10000000 */
|
||||
Discourse.SiteSettings = {"title":"Discourse Meta","logo_url":"/assets/logo.png","logo_small_url":"/assets/logo-single.png","traditional_markdown_linebreaks":false,"top_menu":"latest|new|unread|read|favorited|categories","post_menu":"like|edit|flag|delete|share|bookmark|reply","share_links":"twitter|facebook|google+|email","track_external_right_clicks":false,"must_approve_users":false,"ga_tracking_code":"UA-33736483-2","ga_domain_name":"","enable_long_polling":true,"polling_interval":3000,"anon_polling_interval":30000,"min_post_length":20,"max_post_length":16000,"min_topic_title_length":15,"max_topic_title_length":255,"min_private_message_title_length":2,"allow_uncategorized_topics":true,"min_search_term_length":3,"flush_timings_secs":5,"suppress_reply_directly_below":true,"email_domains_blacklist":"mailinator.com","email_domains_whitelist":null,"version_checks":true,"min_title_similar_length":10,"min_body_similar_length":15,"category_colors":"BF1E2E|F1592A|F7941D|9EB83B|3AB54A|12A89D|25AAE2|0E76BD|652D90|92278F|ED207B|8C6238|231F20|808281|B3B5B4|283890","max_upload_size_kb":1024,"category_featured_topics":6,"favicon_url":"/assets/favicon.ico","dynamic_favicon":false,"uncategorized_name":"uncategorized","uncategorized_color":"AB9364","uncategorized_text_color":"FFFFFF","invite_only":false,"login_required":false,"enable_local_logins":true,"enable_local_account_create":true,"enable_google_logins":true,"enable_yahoo_logins":true,"enable_twitter_logins":true,"enable_facebook_logins":true,"enable_cas_logins":false,"enable_github_logins":true,"enable_persona_logins":true,"educate_until_posts":2,"topic_views_heat_low":1000,"topic_views_heat_medium":2000,"topic_views_heat_high":5000,"min_private_message_post_length":5,"faq_url":"","tos_url":"","privacy_policy_url":"","authorized_extensions":".jpg|.jpeg|.png|.gif"};
|
||||
Discourse.SiteSettingsOriginal = {"title":"Discourse Meta","logo_url":"/assets/logo.png","logo_small_url":"/assets/logo-single.png","traditional_markdown_linebreaks":false,"top_menu":"latest|new|unread|read|favorited|categories","post_menu":"like|edit|flag|delete|share|bookmark|reply","share_links":"twitter|facebook|google+|email","track_external_right_clicks":false,"must_approve_users":false,"ga_tracking_code":"UA-33736483-2","ga_domain_name":"","enable_long_polling":true,"polling_interval":3000,"anon_polling_interval":30000,"min_post_length":20,"max_post_length":16000,"min_topic_title_length":15,"max_topic_title_length":255,"min_private_message_title_length":2,"allow_uncategorized_topics":true,"min_search_term_length":3,"flush_timings_secs":5,"suppress_reply_directly_below":true,"email_domains_blacklist":"mailinator.com","email_domains_whitelist":null,"version_checks":true,"min_title_similar_length":10,"min_body_similar_length":15,"category_colors":"BF1E2E|F1592A|F7941D|9EB83B|3AB54A|12A89D|25AAE2|0E76BD|652D90|92278F|ED207B|8C6238|231F20|808281|B3B5B4|283890","max_upload_size_kb":1024,"category_featured_topics":6,"favicon_url":"/assets/favicon.ico","dynamic_favicon":false,"uncategorized_name":"uncategorized","uncategorized_color":"AB9364","uncategorized_text_color":"FFFFFF","invite_only":false,"login_required":false,"enable_local_logins":true,"enable_local_account_create":true,"enable_google_logins":true,"enable_yahoo_logins":true,"enable_twitter_logins":true,"enable_facebook_logins":true,"enable_cas_logins":false,"enable_github_logins":true,"enable_persona_logins":true,"educate_until_posts":2,"topic_views_heat_low":1000,"topic_views_heat_medium":2000,"topic_views_heat_high":5000,"min_private_message_post_length":5,"faq_url":"","tos_url":"","privacy_policy_url":"","authorized_extensions":".jpg|.jpeg|.png|.gif"};
|
||||
Discourse.SiteSettings = jQuery.extend(true, {}, Discourse.SiteSettingsOriginal);
|
@ -33,22 +33,76 @@ test('missingTitleCharacters', function() {
|
||||
missingTitleCharacters('z', true, Discourse.SiteSettings.min_private_message_title_length - 1, 'too short pm title');
|
||||
});
|
||||
|
||||
|
||||
test('wouldLoseChanges', function() {
|
||||
test('replyDirty', function() {
|
||||
var composer = Discourse.Composer.create();
|
||||
ok(!composer.get('wouldLoseChanges'), "by default it's false");
|
||||
ok(!composer.get('replyDirty'), "by default it's false");
|
||||
|
||||
composer.setProperties({
|
||||
originalText: "hello",
|
||||
reply: "hello"
|
||||
});
|
||||
|
||||
ok(!composer.get('wouldLoseChanges'), "it's false when the originalText is the same as the reply");
|
||||
ok(!composer.get('replyDirty'), "it's false when the originalText is the same as the reply");
|
||||
composer.set('reply', 'hello world');
|
||||
ok(composer.get('wouldLoseChanges'), "it's true when the reply changes");
|
||||
ok(composer.get('replyDirty'), "it's true when the reply changes");
|
||||
});
|
||||
|
||||
test("appendText", function() {
|
||||
var composer = Discourse.Composer.create();
|
||||
|
||||
blank(composer.get('reply'), "the reply is blank by default");
|
||||
|
||||
composer.appendText("hello");
|
||||
equal(composer.get('reply'), "hello", "it appends text to nothing");
|
||||
composer.appendText(" world");
|
||||
equal(composer.get('reply'), "hello world", "it appends text to existing text");
|
||||
|
||||
});
|
||||
|
||||
test("Title length for regular topics", function() {
|
||||
Discourse.SiteSettings.min_topic_title_length = 5;
|
||||
Discourse.SiteSettings.max_topic_title_length = 10;
|
||||
var composer = Discourse.Composer.create();
|
||||
|
||||
composer.set('title', 'asdf');
|
||||
ok(!composer.get('titleLengthValid'), "short titles are not valid");
|
||||
|
||||
composer.set('title', 'this is a long title');
|
||||
ok(!composer.get('titleLengthValid'), "long titles are not valid");
|
||||
|
||||
composer.set('title', 'just right');
|
||||
ok(composer.get('titleLengthValid'), "in the range is okay");
|
||||
});
|
||||
|
||||
test("Title length for private messages", function() {
|
||||
Discourse.SiteSettings.min_private_message_title_length = 5;
|
||||
Discourse.SiteSettings.max_topic_title_length = 10;
|
||||
var composer = Discourse.Composer.create({action: Discourse.Composer.PRIVATE_MESSAGE});
|
||||
|
||||
composer.set('title', 'asdf');
|
||||
ok(!composer.get('titleLengthValid'), "short titles are not valid");
|
||||
|
||||
composer.set('title', 'this is a long title');
|
||||
ok(!composer.get('titleLengthValid'), "long titles are not valid");
|
||||
|
||||
composer.set('title', 'just right');
|
||||
ok(composer.get('titleLengthValid'), "in the range is okay");
|
||||
});
|
||||
|
||||
test("Title length for private messages", function() {
|
||||
Discourse.SiteSettings.min_private_message_title_length = 5;
|
||||
Discourse.SiteSettings.max_topic_title_length = 10;
|
||||
var composer = Discourse.Composer.create({action: Discourse.Composer.PRIVATE_MESSAGE});
|
||||
|
||||
composer.set('title', 'asdf');
|
||||
ok(!composer.get('titleLengthValid'), "short titles are not valid");
|
||||
|
||||
composer.set('title', 'this is a long title');
|
||||
ok(!composer.get('titleLengthValid'), "long titles are not valid");
|
||||
|
||||
composer.set('title', 'just right');
|
||||
ok(composer.get('titleLengthValid'), "in the range is okay");
|
||||
});
|
||||
|
||||
test('importQuote with no data', function() {
|
||||
this.stub(Discourse.Post, 'load');
|
||||
@ -63,6 +117,19 @@ test('importQuote with no data', function() {
|
||||
ok(!Discourse.Post.load.calledOnce, "load is not called");
|
||||
});
|
||||
|
||||
test('editingFirstPost', function() {
|
||||
var composer = Discourse.Composer.create();
|
||||
ok(!composer.get('editingFirstPost'), "it's false by default");
|
||||
|
||||
var post = Discourse.Post.create({id: 123, post_number: 2});
|
||||
composer.setProperties({post: post, action: Discourse.Composer.EDIT });
|
||||
ok(!composer.get('editingFirstPost'), "it's false when not editing the first post");
|
||||
|
||||
post.set('post_number', 1);
|
||||
ok(composer.get('editingFirstPost'), "it's true when editing the first post");
|
||||
|
||||
});
|
||||
|
||||
asyncTest('importQuote with a post', function() {
|
||||
expect(1);
|
||||
|
||||
|
@ -29,4 +29,16 @@ test('updateFromPost', function() {
|
||||
}));
|
||||
|
||||
equal(post.get('raw'), "different raw", "raw field updated");
|
||||
});
|
||||
|
||||
test('hasHistory', function() {
|
||||
|
||||
var post = Discourse.Post.create({id: 1});
|
||||
ok(!post.get('hasHistory'), 'posts without versions have no history');
|
||||
post.set('version', 1);
|
||||
ok(!post.get('hasHistory'), 'posts with one version have no history');
|
||||
post.set('version', 2);
|
||||
ok(post.get('hasHistory'), 'posts with more than one version have a history');
|
||||
|
||||
|
||||
});
|
@ -72,8 +72,13 @@ Discourse.setupForTesting();
|
||||
Discourse.injectTestHelpers();
|
||||
Discourse.bindDOMEvents();
|
||||
|
||||
|
||||
Discourse.Router.map(function() {
|
||||
return Discourse.routeBuilder.call(this);
|
||||
});
|
||||
|
||||
|
||||
QUnit.testStart(function() {
|
||||
// Allow our tests to change site settings and have them reset before the next test
|
||||
Discourse.SiteSettings = jQuery.extend(true, {}, Discourse.SiteSettingsOriginal);
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user