Super basic test support for listing topics

This commit is contained in:
Robin Ward 2013-06-13 15:08:42 -04:00
parent cb6774a895
commit 5193ddc72f
10 changed files with 88 additions and 24 deletions

View File

@ -225,6 +225,7 @@ Discourse = Ember.Application.createWithMixins({
ajax: function() {
var url, args;
if (arguments.length === 1) {
if (typeof arguments[0] === "string") {
url = arguments[0];
@ -246,6 +247,14 @@ Discourse = Ember.Application.createWithMixins({
console.warning("DEPRECATION: Discourse.ajax should use promises, received 'error' callback");
}
// If we have URL_FIXTURES, load from there instead (testing)
var fixture = Discourse.URL_FIXTURES && Discourse.URL_FIXTURES[url];
if (fixture) {
return Ember.Deferred.promise(function(promise) {
promise.resolve(fixture);
})
}
return Ember.Deferred.promise(function (promise) {
var oldSuccess = args.success;
args.success = function(xhr) {

View File

@ -10,7 +10,8 @@ var validNavNames = ['latest', 'hot', 'categories', 'category', 'favorited', 'un
var validAnon = ['latest', 'hot', 'categories', 'category'];
Discourse.NavItem = Discourse.Model.extend({
topicTrackingState: function(){
topicTrackingState: function() {
return Discourse.TopicTrackingState.current();
}.property(),
@ -32,7 +33,15 @@ Discourse.NavItem = Discourse.Model.extend({
if (state) {
return state.lookupCount(this.get('name'));
}
}.property('topicTrackingState.messageCount')
}.property('topicTrackingState.messageCount'),
excludeCategory: function() {
if (parseInt(this.get('filters.length'), 10) > 0) {
return this.get('filters')[0].substring(1);
}
}.property('filters.length')
});
Discourse.NavItem.reopenClass({

View File

@ -120,17 +120,7 @@ Discourse.TopicList.reopenClass({
},
list: function(menuItem) {
var filter = menuItem.name;
var topicList = Discourse.TopicList.create({
inserted: Em.A(),
filter: filter
});
var url = Discourse.getURL("/") + filter + ".json";
if (menuItem.filters && menuItem.filters.length > 0) {
url += "?exclude_category=" + menuItem.filters[0].substring(1);
}
var filter = menuItem.get('name');
var list = Discourse.get('transient.topicsList');
if (list) {
@ -144,8 +134,26 @@ Discourse.TopicList.reopenClass({
Discourse.set('transient.topicsList', null);
Discourse.set('transient.topicListScrollPos', null);
return PreloadStore.getAndRemove("topic_list", function() { return Discourse.ajax(url) }).then(function(result) {
topicList.setProperties({
return Discourse.TopicList.find(filter, menuItem.get('excludeCategory'));
}
});
Discourse.TopicList.reopenClass({
find: function(filter, excludeCategory) {
// How we find our topic list
var finder = function() {
var url = Discourse.getURL("/") + filter + ".json";
if (excludeCategory) { url += "?exclude_category=" + excludeCategory; }
return Discourse.ajax(url);
}
return PreloadStore.getAndRemove("topic_list", finder).then(function(result) {
var topicList = Discourse.TopicList.create({
inserted: Em.A(),
filter: filter,
topics: Discourse.TopicList.topicsFrom(result),
can_create_topic: result.topic_list.can_create_topic,
more_topics_url: result.topic_list.more_topics_url,
@ -162,6 +170,6 @@ Discourse.TopicList.reopenClass({
return topicList;
});
}
});

View File

@ -10,6 +10,7 @@ paths:
- app/assets/javascripts/**/*.js
- spec/javascripts/**/*.js
- spec/phantom_js/**/*.js
- test/javascripts/**/*.js
exclude_paths:
- app/assets/javascripts/external/*

View File

@ -14,7 +14,8 @@
{ "path": "lib" },
{ "path": "script" },
{ "path": "cookbooks" },
{ "path": "spec" }
{ "path": "spec" },
{ "path": "test" }
],
"settings":
{

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,2 @@
/*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,"supress_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};

View File

@ -1,11 +1,12 @@
/*global module:true test:true ok:true visit:true expect:true exists:true count:true */
module("Header", {
setup: function() {
Ember.run(Discourse, Discourse.advanceReadiness);
},
teardown: function() {
$('#discourse-modal').modal('hide')
$('#discourse-modal').remove()
Discourse.reset();
}
});

View File

@ -0,0 +1,23 @@
/*global module:true test:true ok:true visit:true expect:true exists:true count:true */
module("List Topics", {
setup: function() {
Ember.run(Discourse, Discourse.advanceReadiness);
},
teardown: function() {
Discourse.reset();
}
});
test("/", function() {
expect(2);
visit("/").then(function() {
ok(exists("#topic-list"), "The list of topics was rendered");
ok(count('#topic-list .topic-list-item') > 0, "has topics");
});
});

View File

@ -1,3 +1,4 @@
/*global count:true find:true document:true */
//= require env
@ -33,20 +34,26 @@
//= require_tree .
//= require_self
document.write('<div id="ember-testing-container"><div id="ember-testing"></div></div>');
document.write('<style>#ember-testing-container { position: absolute; background: white; bottom: 0; right: 0; width: 640px; height: 384px; overflow: auto; z-index: 9999; border: 1px solid #ccc; } #ember-testing { zoom: 50%; }</style>');
//= require_tree ./fixtures
// Trick JSHint into allow document.write
var d = document;
d.write('<div id="ember-testing-container"><div id="ember-testing"></div></div>');
d.write('<style>#ember-testing-container { position: absolute; background: white; bottom: 0; right: 0; width: 640px; height: 384px; overflow: auto; z-index: 9999; border: 1px solid #ccc; } #ember-testing { zoom: 50%; }</style>');
Discourse.rootElement = '#ember-testing';
Discourse.setupForTesting();
Discourse.injectTestHelpers();
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,"supress_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};
Discourse.Router.map(function() {
return Discourse.routeBuilder.call(this);
});
function exists(selector) {
return !!find(selector).length;
return !!count(selector);
}
function count(selector) {
return find(selector).length;
}