More Javascript Tests + Fixtures. Also a rake task to crawl them.

This commit is contained in:
Robin Ward 2013-07-04 16:19:59 -04:00
parent 594cb50f18
commit 4a3bc1fb43
12 changed files with 110 additions and 12 deletions

@ -20,7 +20,7 @@ Discourse.StaticController = Discourse.Controller.extend({
text = text[1];
this.set('content', text);
} else {
return Discourse.ajax(path + ".json", {dataType: 'html'}).then(function (result) {
return Discourse.ajax(path).then(function (result) {
staticController.set('content', result);
});
}

@ -17,7 +17,7 @@ Discourse.UserStream = Discourse.Model.extend({
}.observes('filter'),
findItems: function() {
var url = Discourse.getURL("/user_actions?offset=") + this.get('itemsLoaded') + "&username=" + (this.get('user.username_lower'));
var url = Discourse.getURL("/user_actions.json?offset=") + this.get('itemsLoaded') + "&username=" + (this.get('user.username_lower'));
if (this.get('filter')) {
url += "&filter=" + (this.get('filter'));
}

@ -0,0 +1,51 @@
require 'open-uri'
desc 'Creates the integration fixtures. Requires a development instance running.'
task 'integration:create_fixtures' => :environment do
fixtures = {
list: ["/latest.json", "/categories.json", "/category/bug.json"],
topic: ["/t/280.json"],
user: ["/users/eviltrout.json", "/user_actions.json?offset=0&username=eviltrout"],
static: ["/faq", '/tos', '/privacy']
}
fixtures.each do |type, urls|
filename = "#{Rails.root}/test/javascripts/fixtures/#{type}_fixtures.js"
content = "/*jshint maxlen:10000000 */\n"
urls.each do |url|
http_result = fake_xhr("http://localhost:3000#{url}")
# If the result is not JSON, convert it to JSON
begin
parsed = ::JSON.parse(http_result)
rescue
http_result = http_result.to_json
end
content << "Discourse.URL_FIXTURES[\"#{url}\"] = #{http_result};\n"
end
File.write(filename, content)
end
end
def fake_xhr(url)
uri = URI(url)
result = nil
Net::HTTP.start(uri.host, uri.port) do |http|
request = Net::HTTP::Get.new uri
request.add_field "X-Requested-With", "XMLHttpRequest"
response = http.request(request)
result = response.body.force_encoding("UTF-8")
end
result
end

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -1,5 +1,5 @@
function integration(name) {
module(name, {
module("Integration: " + name, {
setup: function() {
sinon.stub(Discourse.ScrollingDOMMethods, "bindOnScroll");
sinon.stub(Discourse.ScrollingDOMMethods, "unbindOnScroll");

@ -1,24 +1,29 @@
integration("List Topics");
test("Default List", function() {
expect(2);
visit("/").then(function() {
expect(2);
ok(exists("#topic-list"), "The list of topics was rendered");
ok(exists('#topic-list .topic-list-item'), "has topics");
});
});
test("List one Category", function() {
expect(2);
visit("/category/bug").then(function() {
ok(exists("#topic-list"), "The list of topics was rendered");
ok(exists('#topic-list .topic-list-item'), "has topics");
});
});
test("Categories List", function() {
expect(1);
visit("/categories").then(function() {
expect(1);
ok(exists('.category-list-item'), "has a list of categories");
});
});

@ -0,0 +1,22 @@
integration("Static");
test("Faq", function() {
expect(1);
visit("/faq").then(function() {
ok(exists(".body-page"), "The content is present");
});
});
test("Terms of Service", function() {
expect(1);
visit("/tos").then(function() {
ok(exists(".body-page"), "The content is present");
});
});
test("Privacy", function() {
expect(1);
visit("/privacy").then(function() {
ok(exists(".body-page"), "The content is present");
});
});

@ -0,0 +1,12 @@
integration("User");
test("Profile", function() {
visit("/users/eviltrout").then(function() {
expect(2);
ok(exists(".user-heading"), "The heading is rendered");
ok(exists("#user-stream"), "The stream is rendered");
});
});

@ -1,6 +1,6 @@
integration("View Topic");
test("View a Topic", function() {
test("Enter a Topic", function() {
visit("/t/internationalization-localization/280").then(function() {
expect(2);