From d29157dab9f011f0247d93ac50dfe5309fb4eab0 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 30 Jul 2014 13:27:14 -0400 Subject: [PATCH] TESTS: Refactored integration tests --- .../notification_controller_test.js | 4 + .../fixtures/notification_fixtures.js | 2 + test/javascripts/fixtures/search_fixtures.js | 2 + test/javascripts/helpers/qunit_helpers.js | 4 +- test/javascripts/integration/header-test.js | 77 +++++++ test/javascripts/integration/header_test.js | 192 ------------------ test/javascripts/integration/static-test.js | 21 ++ test/javascripts/integration/static_test.js | 22 -- ...topics_test.js => topic-discovery-test.js} | 26 +-- .../{view_topic_test.js => topic-test.js} | 3 +- .../{unknown_test.js => unknown-test.js} | 3 +- test/javascripts/integration/user-test.js | 34 ++++ test/javascripts/integration/user_test.js | 21 -- test/javascripts/test_helper.js | 2 +- 14 files changed, 157 insertions(+), 256 deletions(-) create mode 100644 test/javascripts/fixtures/notification_fixtures.js create mode 100644 test/javascripts/fixtures/search_fixtures.js create mode 100644 test/javascripts/integration/header-test.js delete mode 100644 test/javascripts/integration/header_test.js create mode 100644 test/javascripts/integration/static-test.js delete mode 100644 test/javascripts/integration/static_test.js rename test/javascripts/integration/{discover_topics_test.js => topic-discovery-test.js} (52%) rename test/javascripts/integration/{view_topic_test.js => topic-test.js} (72%) rename test/javascripts/integration/{unknown_test.js => unknown-test.js} (72%) create mode 100644 test/javascripts/integration/user-test.js delete mode 100644 test/javascripts/integration/user_test.js diff --git a/test/javascripts/controllers/notification_controller_test.js b/test/javascripts/controllers/notification_controller_test.js index b0b5f22f707..a1f4757fd81 100644 --- a/test/javascripts/controllers/notification_controller_test.js +++ b/test/javascripts/controllers/notification_controller_test.js @@ -13,6 +13,10 @@ var notificationFixture = { module("controller:notification", { setup: function() { controller = testController('notification', notificationFixture); + }, + + teardown: function() { + controller.set('model', null); } }); diff --git a/test/javascripts/fixtures/notification_fixtures.js b/test/javascripts/fixtures/notification_fixtures.js new file mode 100644 index 00000000000..c1e2b64fd22 --- /dev/null +++ b/test/javascripts/fixtures/notification_fixtures.js @@ -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" } } ]; diff --git a/test/javascripts/fixtures/search_fixtures.js b/test/javascripts/fixtures/search_fixtures.js new file mode 100644 index 00000000000..4a0df4df114 --- /dev/null +++ b/test/javascripts/fixtures/search_fixtures.js @@ -0,0 +1,2 @@ +/*jshint maxlen:10000000 */ +Discourse.URL_FIXTURES["/search"] = [ { type: "topic", more: true, results: [ { url: "some-url" } ] } ]; diff --git a/test/javascripts/helpers/qunit_helpers.js b/test/javascripts/helpers/qunit_helpers.js index 3144373aea6..8b938827ec7 100644 --- a/test/javascripts/helpers/qunit_helpers.js +++ b/test/javascripts/helpers/qunit_helpers.js @@ -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"; } diff --git a/test/javascripts/integration/header-test.js b/test/javascripts/integration/header-test.js new file mode 100644 index 00000000000..e5db4d1b3af --- /dev/null +++ b/test/javascripts/integration/header-test.js @@ -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"); + }); +}); diff --git a/test/javascripts/integration/header_test.js b/test/javascripts/integration/header_test.js deleted file mode 100644 index 58f03a3f91d..00000000000 --- a/test/javascripts/integration/header_test.js +++ /dev/null @@ -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 some title', "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"); - }); -}); diff --git a/test/javascripts/integration/static-test.js b/test/javascripts/integration/static-test.js new file mode 100644 index 00000000000..a0c6884d559 --- /dev/null +++ b/test/javascripts/integration/static-test.js @@ -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"); + }); +}); diff --git a/test/javascripts/integration/static_test.js b/test/javascripts/integration/static_test.js deleted file mode 100644 index 8cee6030617..00000000000 --- a/test/javascripts/integration/static_test.js +++ /dev/null @@ -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"); - }); -}); diff --git a/test/javascripts/integration/discover_topics_test.js b/test/javascripts/integration/topic-discovery-test.js similarity index 52% rename from test/javascripts/integration/discover_topics_test.js rename to test/javascripts/integration/topic-discovery-test.js index 7153a2d4195..991eef9fc30 100644 --- a/test/javascripts/integration/discover_topics_test.js +++ b/test/javascripts/integration/topic-discovery-test.js @@ -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"); }); }); - - - diff --git a/test/javascripts/integration/view_topic_test.js b/test/javascripts/integration/topic-test.js similarity index 72% rename from test/javascripts/integration/view_topic_test.js rename to test/javascripts/integration/topic-test.js index 1bd4cca6f87..c57021bf925 100644 --- a/test/javascripts/integration/view_topic_test.js +++ b/test/javascripts/integration/topic-test.js @@ -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"); }); diff --git a/test/javascripts/integration/unknown_test.js b/test/javascripts/integration/unknown-test.js similarity index 72% rename from test/javascripts/integration/unknown_test.js rename to test/javascripts/integration/unknown-test.js index a48e38d9212..6bef185b1d6 100644 --- a/test/javascripts/integration/unknown_test.js +++ b/test/javascripts/integration/unknown-test.js @@ -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"); }); }); diff --git a/test/javascripts/integration/user-test.js b/test/javascripts/integration/user-test.js new file mode 100644 index 00000000000..b610b966f59 --- /dev/null +++ b/test/javascripts/integration/user-test.js @@ -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(); +}); diff --git a/test/javascripts/integration/user_test.js b/test/javascripts/integration/user_test.js deleted file mode 100644 index b0549550364..00000000000 --- a/test/javascripts/integration/user_test.js +++ /dev/null @@ -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"); - -}); diff --git a/test/javascripts/test_helper.js b/test/javascripts/test_helper.js index 037f2b5a068..8cf40d993b1 100644 --- a/test/javascripts/test_helper.js +++ b/test/javascripts/test_helper.js @@ -1,5 +1,5 @@ /*jshint maxlen:250 */ -/*global document, sinon, console, QUnit */ +/*global document, sinon, console, QUnit, Logster */ //= require env