2014-07-31 06:56:01 +08:00
|
|
|
var oldMobileView;
|
2013-11-28 04:58:36 +08:00
|
|
|
|
2014-07-31 06:56:01 +08:00
|
|
|
moduleFor("controller:site-map", "controller:site-map", {
|
2015-01-10 04:40:25 +08:00
|
|
|
needs: ['controller:application'],
|
|
|
|
|
2013-11-28 04:58:36 +08:00
|
|
|
setup: function() {
|
|
|
|
oldMobileView = Discourse.Mobile.mobileView;
|
|
|
|
},
|
|
|
|
|
|
|
|
teardown: function() {
|
|
|
|
Discourse.Mobile.mobileView = oldMobileView;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test("showAdminLinks", function() {
|
2015-02-27 01:25:25 +08:00
|
|
|
const currentUser = Ember.Object.create({ staff: true });
|
|
|
|
const controller = this.subject({ currentUser });
|
2013-11-28 04:58:36 +08:00
|
|
|
equal(controller.get("showAdminLinks"), true, "is true when current user is a staff member");
|
|
|
|
|
2015-02-27 01:25:25 +08:00
|
|
|
currentUser.set("staff", false);
|
2013-11-28 04:58:36 +08:00
|
|
|
equal(controller.get("showAdminLinks"), false, "is false when current user is not a staff member");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("flaggedPostsCount", function() {
|
2015-02-27 01:25:25 +08:00
|
|
|
const currentUser = Ember.Object.create({ site_flagged_posts_count: 5 });
|
|
|
|
const controller = this.subject({ currentUser });
|
2013-11-28 04:58:36 +08:00
|
|
|
|
|
|
|
equal(controller.get("flaggedPostsCount"), 5, "returns current user's flagged posts count");
|
|
|
|
|
2015-02-27 01:25:25 +08:00
|
|
|
currentUser.set("site_flagged_posts_count", 0);
|
2013-11-28 04:58:36 +08:00
|
|
|
equal(controller.get("flaggedPostsCount"), 0, "is bound (reacts to change of current user's flagged posts count)");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("faqUrl returns faq url configured in site settings if it is set", function() {
|
|
|
|
Discourse.SiteSettings.faq_url = "faq-url";
|
2014-07-31 06:56:01 +08:00
|
|
|
var controller = this.subject();
|
2013-11-28 04:58:36 +08:00
|
|
|
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;
|
2014-07-31 06:56:01 +08:00
|
|
|
var controller = this.subject();
|
2013-11-28 04:58:36 +08:00
|
|
|
equal(controller.get("faqUrl"), "/faq");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("showMoblieToggle returns true when mobile theme is enabled in site settings", function() {
|
|
|
|
Discourse.SiteSettings.enable_mobile_theme = true;
|
2014-07-28 10:05:27 +08:00
|
|
|
Discourse.Mobile.isMobileDevice = true;
|
2014-07-31 06:56:01 +08:00
|
|
|
var controller = this.subject();
|
2014-08-07 06:28:02 +08:00
|
|
|
controller.capabilities = { touch: true };
|
2013-11-28 04:58:36 +08:00
|
|
|
equal(controller.get("showMobileToggle"), true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("showMoblieToggle returns false when mobile theme is disabled in site settings", function() {
|
|
|
|
Discourse.SiteSettings.enable_mobile_theme = false;
|
2014-07-28 10:05:27 +08:00
|
|
|
Discourse.Mobile.isMobileDevice = true;
|
2014-07-31 06:56:01 +08:00
|
|
|
var controller = this.subject();
|
2013-11-28 04:58:36 +08:00
|
|
|
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;
|
2014-07-31 06:56:01 +08:00
|
|
|
var controller = this.subject();
|
2013-11-28 04:58:36 +08:00
|
|
|
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;
|
2014-07-31 06:56:01 +08:00
|
|
|
var controller = this.subject();
|
2013-11-28 04:58:36 +08:00
|
|
|
equal(controller.get("mobileViewLinkTextKey"), "mobile_view");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("categories", function() {
|
|
|
|
var categoryListStub = ["category1", "category2"];
|
2014-07-31 06:56:01 +08:00
|
|
|
sandbox.stub(Discourse.Category, "list").returns(categoryListStub);
|
2013-11-28 04:58:36 +08:00
|
|
|
|
2015-01-10 04:40:25 +08:00
|
|
|
var controller = this.subject({ siteSettings: Discourse.SiteSettings });
|
2014-07-23 04:15:56 +08:00
|
|
|
deepEqual(controller.get("categories"), categoryListStub, "returns the list of categories");
|
2013-11-28 04:58:36 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test("toggleMobleView", function() {
|
2014-07-31 06:56:01 +08:00
|
|
|
sandbox.stub(Discourse.Mobile, "toggleMobileView");
|
2013-11-28 04:58:36 +08:00
|
|
|
|
2014-07-31 06:56:01 +08:00
|
|
|
var controller = this.subject();
|
2013-11-28 04:58:36 +08:00
|
|
|
controller.send("toggleMobileView");
|
|
|
|
ok(Discourse.Mobile.toggleMobileView.calledOnce, "switches between desktop and mobile views");
|
|
|
|
});
|