Lots of work on tests

This commit is contained in:
Robin Ward
2014-07-30 18:56:01 -04:00
parent b6684e7168
commit 6f36d5996d
43 changed files with 248 additions and 311 deletions

View File

@ -1,10 +1,8 @@
var controller, oldMobileView;
var oldMobileView;
module("controller:site-map", {
moduleFor("controller:site-map", "controller:site-map", {
setup: function() {
oldMobileView = Discourse.Mobile.mobileView;
controller = testController('site-map');
},
teardown: function() {
@ -13,14 +11,15 @@ module("controller:site-map", {
});
test("itemController", function() {
equal(controller.get("itemController"), "site-map-category", "defaults to site-map-category");
equal(this.subject().get("itemController"), "site-map-category", "defaults to site-map-category");
});
test("showAdminLinks", function() {
var currentUserStub = Ember.Object.create();
this.stub(Discourse.User, "current").returns(currentUserStub);
sandbox.stub(Discourse.User, "current").returns(currentUserStub);
currentUserStub.set("staff", true);
var controller = this.subject();
equal(controller.get("showAdminLinks"), true, "is true when current user is a staff member");
currentUserStub.set("staff", false);
@ -29,9 +28,10 @@ test("showAdminLinks", function() {
test("flaggedPostsCount", function() {
var currentUserStub = Ember.Object.create();
this.stub(Discourse.User, "current").returns(currentUserStub);
sandbox.stub(Discourse.User, "current").returns(currentUserStub);
currentUserStub.set("site_flagged_posts_count", 5);
var controller = this.subject();
equal(controller.get("flaggedPostsCount"), 5, "returns current user's flagged posts count");
currentUserStub.set("site_flagged_posts_count", 0);
@ -40,46 +40,54 @@ test("flaggedPostsCount", function() {
test("faqUrl returns faq url configured in site settings if it is set", function() {
Discourse.SiteSettings.faq_url = "faq-url";
var controller = this.subject();
equal(controller.get("faqUrl"), "faq-url");
});
test("faqUrl returns default '/faq' url when there is no corresponding site setting set", function() {
Discourse.SiteSettings.faq_url = null;
var controller = this.subject();
equal(controller.get("faqUrl"), "/faq");
});
test("showMoblieToggle returns true when mobile theme is enabled in site settings", function() {
Discourse.SiteSettings.enable_mobile_theme = true;
Discourse.Mobile.isMobileDevice = true;
var controller = this.subject();
equal(controller.get("showMobileToggle"), true);
});
test("showMoblieToggle returns false when mobile theme is disabled in site settings", function() {
Discourse.SiteSettings.enable_mobile_theme = false;
Discourse.Mobile.isMobileDevice = true;
var controller = this.subject();
equal(controller.get("showMobileToggle"), false);
});
test("mobileViewLinkTextKey returns translation key for a desktop view if the current view is mobile view", function() {
Discourse.Mobile.mobileView = true;
var controller = this.subject();
equal(controller.get("mobileViewLinkTextKey"), "desktop_view");
});
test("mobileViewLinkTextKey returns translation key for a mobile view if the current view is desktop view", function() {
Discourse.Mobile.mobileView = false;
var controller = this.subject();
equal(controller.get("mobileViewLinkTextKey"), "mobile_view");
});
test("categories", function() {
var categoryListStub = ["category1", "category2"];
this.stub(Discourse.Category, "list").returns(categoryListStub);
sandbox.stub(Discourse.Category, "list").returns(categoryListStub);
var controller = this.subject();
deepEqual(controller.get("categories"), categoryListStub, "returns the list of categories");
});
test("toggleMobleView", function() {
this.stub(Discourse.Mobile, "toggleMobileView");
sandbox.stub(Discourse.Mobile, "toggleMobileView");
var controller = this.subject();
controller.send("toggleMobileView");
ok(Discourse.Mobile.toggleMobileView.calledOnce, "switches between desktop and mobile views");
});