diff --git a/app/assets/javascripts/app/router.js b/app/assets/javascripts/app/router.js index d55b6a27d..d471f9c98 100644 --- a/app/assets/javascripts/app/router.js +++ b/app/assets/javascripts/app/router.js @@ -2,7 +2,7 @@ app.Router = Backbone.Router.extend({ routes: { - "help/:topic": "help", + "help/:section": "help", "help/": "help", "help": "help", "contacts": "contacts", @@ -38,10 +38,10 @@ app.Router = Backbone.Router.extend({ this.route(/^bookmarklet(?:\?(.*))?/, "bookmarklet"); }, - help: function(topic) { + help: function(section) { app.help = new app.views.Help(); $("#help").prepend(app.help.el); - app.help.render(topic); + app.help.render(section); }, contacts: function() { diff --git a/app/assets/javascripts/app/views/help_view.js b/app/assets/javascripts/app/views/help_view.js index a6b0d4d3c..ffd773b20 100644 --- a/app/assets/javascripts/app/views/help_view.js +++ b/app/assets/javascripts/app/views/help_view.js @@ -57,17 +57,17 @@ app.views.Help = app.views.StaticContentView.extend({ return this; }, - render: function(topic){ - var section = app.views.Base.prototype.render.apply(this, arguments); + render: function(section){ + var html = app.views.Base.prototype.render.apply(this, arguments); // After render actions this.resetMenu(true); this.renderStaticSection("getting_help", "faq_getting_help", this.GETTING_HELP_SUBS); - var elTarget = this.findTopic(topic); - if(elTarget != null){ $(elTarget).click(); } + var elTarget = this.findSection(section); + if(elTarget !== null){ $(elTarget).click(); } - return section; + return html; }, showItems: function(el) { @@ -146,9 +146,9 @@ app.views.Help = app.views.StaticContentView.extend({ * @param dataValue Value for the data-section to find * @returns {jQuery} */ - findTopic: function(dataValue){ - var res = this.$('a[data-section=' + dataValue + ']'); - if(res.length == 0){ return null; } + findSection: function(data){ + var res = this.$('a[data-section=' + data + ']'); + if(res.length === 0){ return null; } return res; }, @@ -191,4 +191,4 @@ app.views.Help = app.views.StaticContentView.extend({ return "" + text + ""; } }); -// @license-end \ No newline at end of file +// @license-end diff --git a/spec/javascripts/app/views/help_view_spec.js b/spec/javascripts/app/views/help_view_spec.js index 0ab8e1a26..c19567d25 100644 --- a/spec/javascripts/app/views/help_view_spec.js +++ b/spec/javascripts/app/views/help_view_spec.js @@ -86,39 +86,52 @@ describe("app.views.Help", function(){ this.view.$el.find('a[data-section=miscellaneous]').trigger('click'); expect(this.view.$el.find('#faq').children().first().hasClass('faq_question_miscellaneous')).toBeTruthy(); }); + }); - it('should not find any topic', function(){ - expect(this.view.findTopic('you_shall_not_pass')).toBeNull(); + describe("findSection", function() { + beforeEach(function() { + this.view.render(); }); - it('should find the miscellaneous topic', function(){ - var topic = this.view.$el.find('a[data-section=miscellaneous]'); - expect(this.view.findTopic('miscellaneous').html()).toBe(topic.html()); + it('should return null for an unknown section', function() { + expect(this.view.findSection('you_shall_not_pass')).toBeNull(); }); - it('should find the keyboard_shortcuts topic', function(){ - var topic = this.view.$el.find('a[data-section=keyboard_shortcuts]'); - expect(this.view.findTopic('keyboard_shortcuts').html()).toBe(topic.html()); - }); + it('should return the correct section link for existing sections', function() { + var sections = [ + 'account_and_data_management', + 'aspects', + 'pods', + 'keyboard_shortcuts', + 'tags', + 'miscellaneous' + ]; - it('should find the miscellaneous topic', function(){ - var topic = this.view.$el.find('a[data-section=tags]'); - expect(this.view.findTopic('tags').html()).toBe(topic.html()); - }); - - it('should rewrite route to help/tags', function(){ - this.view.$el.find('a[data-section=tags]').trigger('click'); - expect(window.location.href.toString().endsWith("help/tags")).toBeTruthy(); - }); - - it('should rewrite route to help/keyboard_shortcuts', function(){ - this.view.$el.find('a[data-section=keyboard_shortcuts]').trigger('click'); - expect(window.location.href.toString().endsWith("help/keyboard_shortcuts")).toBeTruthy(); - }); - - it('should rewrite route to help/sharing', function(){ - this.view.$el.find('a[data-section=sharing]').trigger('click'); - expect(window.location.href.toString().endsWith("help/sharing")).toBeTruthy(); + var self = this; + _.each(sections, function(section) { + var el = self.view.$el.find('a[data-section=' + section + ']'); + expect(self.view.findSection(section).html()).toBe(el.html()); + }); }); }); -}); \ No newline at end of file + + describe("menuClicked", function() { + beforeEach(function() { + this.view.render(); + }); + + it('should rewrite the location', function(){ + var sections = [ + 'account_and_data_management', + 'miscellaneous' + ]; + spyOn(app.router, 'navigate'); + + var self = this; + _.each(sections, function(section) { + self.view.$el.find('a[data-section=' + section + ']').trigger('click'); + expect(app.router.navigate).toHaveBeenCalledWith('help/' + section); + }); + }); + }); +});