mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
TESTS: Refactored integration tests
This commit is contained in:
parent
9926382185
commit
d29157dab9
14 changed files with 157 additions and 256 deletions
|
@ -13,6 +13,10 @@ var notificationFixture = {
|
|||
module("controller:notification", {
|
||||
setup: function() {
|
||||
controller = testController('notification', notificationFixture);
|
||||
},
|
||||
|
||||
teardown: function() {
|
||||
controller.set('model', null);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
2
test/javascripts/fixtures/notification_fixtures.js
Normal file
2
test/javascripts/fixtures/notification_fixtures.js
Normal file
|
@ -0,0 +1,2 @@
|
|||
/*jshint maxlen:10000000 */
|
||||
Discourse.URL_FIXTURES["/notifications"] = [ { notification_type: 2, read: true, post_number: 2, topic_id: 1234, slug: "a-slug", data: { topic_title: "some title", display_username: "velesin" } } ];
|
2
test/javascripts/fixtures/search_fixtures.js
Normal file
2
test/javascripts/fixtures/search_fixtures.js
Normal file
|
@ -0,0 +1,2 @@
|
|||
/*jshint maxlen:10000000 */
|
||||
Discourse.URL_FIXTURES["/search"] = [ { type: "topic", more: true, results: [ { url: "some-url" } ] } ];
|
|
@ -1,5 +1,7 @@
|
|||
/* global asyncTest, requirejs, require */
|
||||
/* exported integration, testController, controllerFor, asyncTestDiscourse, fixture */
|
||||
|
||||
|
||||
function integration(name, lifecycle) {
|
||||
module("Integration: " + name, {
|
||||
setup: function() {
|
||||
|
@ -32,7 +34,7 @@ function testController(klass, model) {
|
|||
module;
|
||||
|
||||
// maybe a bit too hacky? (all of the "admin-*" controllers are in the "admin" directory)
|
||||
if (klass.indexOf("admin") == 0) {
|
||||
if (klass.indexOf("admin") === 0) {
|
||||
base = "admin";
|
||||
}
|
||||
|
||||
|
|
77
test/javascripts/integration/header-test.js
Normal file
77
test/javascripts/integration/header-test.js
Normal file
|
@ -0,0 +1,77 @@
|
|||
integration("Header", {
|
||||
setup: function() {
|
||||
var originalUser = Discourse.User.current();
|
||||
sinon.stub(Discourse.User, "current").returns(originalUser);
|
||||
Discourse.User.current.returns(Ember.Object.create({
|
||||
username: 'test',
|
||||
staff: true,
|
||||
site_flagged_posts_count: 1
|
||||
}));
|
||||
},
|
||||
|
||||
teardown: function() {
|
||||
Discourse.User.current.restore();
|
||||
}
|
||||
});
|
||||
|
||||
test("header", function() {
|
||||
expect(20);
|
||||
|
||||
visit("/");
|
||||
andThen(function() {
|
||||
ok(exists("header"), "is rendered");
|
||||
ok(exists(".logo-big"), "it renders the large logo by default");
|
||||
not(exists("#notifications-dropdown li"), "no notifications at first");
|
||||
not(exists('#site-map-dropdown'), "no site map by default");
|
||||
not(exists("#user-dropdown:visible"), "initially user dropdown is closed");
|
||||
not(exists("#search-dropdown:visible"), "initially search box is closed");
|
||||
});
|
||||
|
||||
// Logo changing
|
||||
andThen(function() {
|
||||
controllerFor("header").set("showExtraInfo", true);
|
||||
});
|
||||
|
||||
andThen(function() {
|
||||
ok(exists(".logo-small"), "it shows the small logo when `showExtraInfo` is enabled");
|
||||
});
|
||||
|
||||
// Notifications
|
||||
click("#user-notifications");
|
||||
andThen(function() {
|
||||
var $items = $("#notifications-dropdown li");
|
||||
ok(exists($items), "is lazily populated after user opens it");
|
||||
ok($items.first().hasClass("read"), "correctly binds items' 'read' class");
|
||||
});
|
||||
|
||||
// Site Map
|
||||
click("#site-map");
|
||||
andThen(function() {
|
||||
ok(exists('#site-map-dropdown'), "is rendered after user opens it");
|
||||
ok(exists("#site-map-dropdown .admin-link"), "it has the admin link");
|
||||
ok(exists("#site-map-dropdown .flagged-posts.badge-notification"), "it displays flag notifications");
|
||||
ok(exists("#site-map-dropdown .faq-link"), "it shows the faq link");
|
||||
ok(exists("#site-map-dropdown .category-links"), "has categories correctly bound");
|
||||
});
|
||||
|
||||
// User dropdown
|
||||
click("#current-user");
|
||||
andThen(function() {
|
||||
ok(exists("#user-dropdown:visible"), "is lazily rendered after user opens it");
|
||||
ok(exists("#user-dropdown .user-dropdown-links"), "has showing / hiding user-dropdown links correctly bound");
|
||||
});
|
||||
|
||||
// Search
|
||||
click("#search-button");
|
||||
andThen(function() {
|
||||
ok(exists("#search-dropdown:visible"), "after clicking a button search box opens");
|
||||
not(exists("#search-dropdown .heading"), "initially, immediately after opening, search box is empty");
|
||||
});
|
||||
|
||||
// Perform Search
|
||||
fillIn("#search-term", "hello");
|
||||
andThen(function() {
|
||||
ok(exists("#search-dropdown .heading"), "when user completes a search, search box shows search results");
|
||||
equal(find("#search-dropdown .selected a").attr("href"), "some-url", "the first search result is selected");
|
||||
});
|
||||
});
|
|
@ -1,192 +0,0 @@
|
|||
integration("Header", {
|
||||
setup: function() {
|
||||
sinon.stub(I18n, "t", function(scope, options) {
|
||||
if (options) {
|
||||
if (options.count) {
|
||||
return [scope, options.count].join(" ");
|
||||
} else {
|
||||
return [scope, options.username, options.link].join(" ").trim();
|
||||
}
|
||||
}
|
||||
return scope;
|
||||
});
|
||||
|
||||
sinon.stub(Ember.run, "debounce").callsArg(1);
|
||||
|
||||
var originalCategories = Discourse.Category.list();
|
||||
sinon.stub(Discourse.Category, "list").returns(originalCategories);
|
||||
|
||||
var originalUser = Discourse.User.current();
|
||||
sinon.stub(Discourse.User, "current").returns(originalUser);
|
||||
},
|
||||
|
||||
teardown: function() {
|
||||
I18n.t.restore();
|
||||
Ember.run.debounce.restore();
|
||||
Discourse.Category.list.restore();
|
||||
Discourse.User.current.restore();
|
||||
}
|
||||
});
|
||||
|
||||
test("header", function() {
|
||||
expect(1);
|
||||
|
||||
visit("/").then(function() {
|
||||
ok(exists("header"), "is rendered");
|
||||
});
|
||||
});
|
||||
|
||||
test("logo", function() {
|
||||
expect(2);
|
||||
|
||||
visit("/").then(function() {
|
||||
ok(exists(".logo-big"), "is rendered");
|
||||
|
||||
Ember.run(function() {
|
||||
controllerFor("header").set("showExtraInfo", true);
|
||||
});
|
||||
ok(exists(".logo-small"), "is properly wired to showExtraInfo property (when showExtraInfo value changes, logo size also changes)");
|
||||
});
|
||||
});
|
||||
|
||||
test("notifications dropdown", function() {
|
||||
expect(4);
|
||||
|
||||
var itemSelector = "#notifications-dropdown li";
|
||||
|
||||
Ember.run(function() {
|
||||
Discourse.URL_FIXTURES["/notifications"] = [
|
||||
{
|
||||
notification_type: 2, //replied
|
||||
read: true,
|
||||
post_number: 2,
|
||||
topic_id: 1234,
|
||||
slug: "a-slug",
|
||||
data: {
|
||||
topic_title: "some title",
|
||||
display_username: "velesin"
|
||||
}
|
||||
}
|
||||
];
|
||||
});
|
||||
|
||||
visit("/")
|
||||
.then(function() {
|
||||
ok(!exists($(itemSelector)), "initially is empty");
|
||||
})
|
||||
.click("#user-notifications")
|
||||
.then(function() {
|
||||
var $items = $(itemSelector);
|
||||
|
||||
ok(exists($items), "is lazily populated after user opens it");
|
||||
ok($items.first().hasClass("read"), "correctly binds items' 'read' class");
|
||||
equal($items.first().find('span').html().trim(), 'notifications.replied velesin <a href="/t/a-slug/1234/2">some title</a>', "correctly generates items' content");
|
||||
});
|
||||
});
|
||||
|
||||
test("sitemap dropdown", function() {
|
||||
expect(7);
|
||||
|
||||
Discourse.SiteSettings.faq_url = "faq-url";
|
||||
Discourse.SiteSettings.enable_mobile_theme = true;
|
||||
|
||||
Discourse.User.current.returns(Ember.Object.create({
|
||||
username: 'test',
|
||||
staff: true,
|
||||
site_flagged_posts_count: 1
|
||||
}));
|
||||
|
||||
Discourse.Category.list.returns([
|
||||
Discourse.Category.create({
|
||||
newTopics: 20
|
||||
})
|
||||
]);
|
||||
|
||||
var siteMapDropdownSelector = "#site-map-dropdown";
|
||||
|
||||
visit("/")
|
||||
.then(function() {
|
||||
ok(!exists($(siteMapDropdownSelector)), "initially is not rendered");
|
||||
})
|
||||
.click("#site-map")
|
||||
.then(function() {
|
||||
var $siteMapDropdown = $(siteMapDropdownSelector);
|
||||
|
||||
ok(exists($siteMapDropdown), "is lazily rendered after user opens it");
|
||||
|
||||
ok(exists($siteMapDropdown.find(".admin-link")), "has showing / hiding admin links correctly bound");
|
||||
ok(exists($siteMapDropdown.find(".flagged-posts.badge-notification")), "has displaying flagged posts badge correctly bound");
|
||||
equal($siteMapDropdown.find(".faq-link").attr("href"), "faq-url", "is correctly bound to the FAQ url site config");
|
||||
|
||||
ok(exists($siteMapDropdown.find(".category-links")), "has categories correctly bound");
|
||||
ok(exists($siteMapDropdown.find(".new-posts")), "has displaying category badges correctly bound");
|
||||
});
|
||||
});
|
||||
|
||||
test("search dropdown", function() {
|
||||
Discourse.SiteSettings.min_search_term_length = 2;
|
||||
Ember.run(function() {
|
||||
Discourse.URL_FIXTURES["/search"] = [
|
||||
{
|
||||
type: "topic",
|
||||
more: true,
|
||||
results: [
|
||||
{
|
||||
url: "some-url"
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
});
|
||||
|
||||
visit("/");
|
||||
andThen(function() {
|
||||
not(exists("#search-dropdown:visible"), "initially search box is closed");
|
||||
});
|
||||
click("#search-button");
|
||||
andThen(function() {
|
||||
ok(exists("#search-dropdown:visible"), "after clicking a button search box opens");
|
||||
not(exists("#search-dropdown .heading"), "initially, immediately after opening, search box is empty");
|
||||
});
|
||||
fillIn("#search-term", "ab");
|
||||
andThen(function() {
|
||||
ok(exists("#search-dropdown .heading"), "when user completes a search, search box shows search results");
|
||||
equal(find("#search-dropdown .selected a").attr("href"), "some-url", "the first search result is selected");
|
||||
});
|
||||
andThen(function() {
|
||||
Discourse.URL_FIXTURES["/search"] = [
|
||||
{
|
||||
type: "topic",
|
||||
more: true,
|
||||
results: [
|
||||
{
|
||||
url: "another-url"
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
});
|
||||
click("#search-dropdown .filter");
|
||||
andThen(function() {
|
||||
equal(find("#search-dropdown .selected a").attr("href"), "another-url", "after clicking 'more of type' link, results are reloaded");
|
||||
});
|
||||
});
|
||||
|
||||
test("user dropdown when logged in", function() {
|
||||
expect(3);
|
||||
|
||||
var userDropdownSelector = "#user-dropdown";
|
||||
|
||||
visit("/")
|
||||
.then(function() {
|
||||
not(exists(userDropdownSelector + ":visible"), "initially user dropdown is closed");
|
||||
})
|
||||
.click("#current-user")
|
||||
.then(function() {
|
||||
var $userDropdown = $(userDropdownSelector);
|
||||
|
||||
ok(exists(userDropdownSelector + ":visible"), "is lazily rendered after user opens it");
|
||||
|
||||
ok(exists($userDropdown.find(".user-dropdown-links")), "has showing / hiding user-dropdown links correctly bound");
|
||||
});
|
||||
});
|
21
test/javascripts/integration/static-test.js
Normal file
21
test/javascripts/integration/static-test.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
integration("Static");
|
||||
|
||||
test("Static Pages", function() {
|
||||
expect(4);
|
||||
visit("/faq");
|
||||
andThen(function() {
|
||||
ok(exists(".body-page"), "The content is present");
|
||||
});
|
||||
visit("/guidelines");
|
||||
andThen(function() {
|
||||
ok(exists(".body-page"), "The content is present");
|
||||
});
|
||||
visit("/tos");
|
||||
andThen(function() {
|
||||
ok(exists(".body-page"), "The content is present");
|
||||
});
|
||||
visit("/privacy");
|
||||
andThen(function() {
|
||||
ok(exists(".body-page"), "The content is present");
|
||||
});
|
||||
});
|
|
@ -1,22 +0,0 @@
|
|||
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");
|
||||
});
|
||||
});
|
|
@ -1,30 +1,22 @@
|
|||
integration("Discover Topics");
|
||||
integration("Topic Discovery");
|
||||
|
||||
test("Default List", function() {
|
||||
expect(2);
|
||||
test("Visit Discovery Pages", function() {
|
||||
expect(5);
|
||||
|
||||
visit("/").then(function() {
|
||||
visit("/");
|
||||
andThen(function() {
|
||||
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() {
|
||||
visit("/category/bug");
|
||||
andThen(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() {
|
||||
visit("/categories");
|
||||
andThen(function() {
|
||||
ok(exists('.category'), "has a list of categories");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
|
@ -3,7 +3,8 @@ integration("View Topic");
|
|||
test("Enter a Topic", function() {
|
||||
expect(2);
|
||||
|
||||
visit("/t/internationalization-localization/280").then(function() {
|
||||
visit("/t/internationalization-localization/280");
|
||||
andThen(function() {
|
||||
ok(exists("#topic"), "The was rendered");
|
||||
ok(exists("#topic .post-cloak"), "The topic has cloaked posts");
|
||||
});
|
|
@ -2,7 +2,8 @@ integration("Unknown");
|
|||
|
||||
test("Unknown URL", function() {
|
||||
expect(1);
|
||||
visit("/url-that-doesn't-exist").then(function() {
|
||||
visit("/url-that-doesn't-exist");
|
||||
andThen(function() {
|
||||
ok(exists(".page-not-found"), "The not found content is present");
|
||||
});
|
||||
});
|
34
test/javascripts/integration/user-test.js
Normal file
34
test/javascripts/integration/user-test.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
integration("User");
|
||||
|
||||
function hasStream() {
|
||||
andThen(function() {
|
||||
ok(exists('.user-main .about'), 'it has the about section');
|
||||
ok(count('.user-stream .item') > 0, 'it has stream items');
|
||||
});
|
||||
}
|
||||
|
||||
function hasTopicList() {
|
||||
andThen(function() {
|
||||
equal(count('.user-stream .item'), 0, "has no stream displayed");
|
||||
ok(count('.topic-list tr') > 0, 'it has a topic list');
|
||||
});
|
||||
}
|
||||
|
||||
test("Filters", function() {
|
||||
expect(14);
|
||||
|
||||
visit("/users/eviltrout");
|
||||
hasStream();
|
||||
visit("/users/eviltrout/activity/topics");
|
||||
hasTopicList();
|
||||
visit("/users/eviltrout/activity/posts");
|
||||
hasStream();
|
||||
visit("/users/eviltrout/activity/replies");
|
||||
hasStream();
|
||||
visit("/users/eviltrout/activity/likes-given");
|
||||
hasStream();
|
||||
visit("/users/eviltrout/activity/likes-received");
|
||||
hasStream();
|
||||
visit("/users/eviltrout/activity/edits");
|
||||
hasStream();
|
||||
});
|
|
@ -1,21 +0,0 @@
|
|||
integration("User");
|
||||
|
||||
test("Activity Streams", function() {
|
||||
expect(14);
|
||||
|
||||
var streamTest = function(url) {
|
||||
visit(url).then(function() {
|
||||
ok(exists(".user-main"), "The main content is rendered");
|
||||
ok(exists(".user-navigation"), "The navigation is rendered");
|
||||
});
|
||||
};
|
||||
|
||||
streamTest("/users/eviltrout");
|
||||
streamTest("/users/eviltrout/activity/topics");
|
||||
streamTest("/users/eviltrout/activity/posts");
|
||||
streamTest("/users/eviltrout/activity/replies");
|
||||
streamTest("/users/eviltrout/activity/likes-given");
|
||||
streamTest("/users/eviltrout/activity/likes-received");
|
||||
streamTest("/users/eviltrout/activity/edits");
|
||||
|
||||
});
|
|
@ -1,5 +1,5 @@
|
|||
/*jshint maxlen:250 */
|
||||
/*global document, sinon, console, QUnit */
|
||||
/*global document, sinon, console, QUnit, Logster */
|
||||
|
||||
//= require env
|
||||
|
||||
|
|
Loading…
Reference in a new issue