From aa62266376afcfc9d1a1b8a908ef655b83f7a8a4 Mon Sep 17 00:00:00 2001 From: Augier Date: Mon, 9 Feb 2015 23:48:31 +0100 Subject: [PATCH 1/3] Added routing system to open a section in help --- app/assets/javascripts/app/router.js | 6 ++-- app/assets/javascripts/app/views/help_view.js | 35 +++++++++++++----- config/routes.rb | 1 + spec/javascripts/app/views/help_view_spec.js | 36 ++++++++++++++++++- 4 files changed, 67 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/app/router.js b/app/assets/javascripts/app/router.js index e700c9cfd..d55b6a27d 100644 --- a/app/assets/javascripts/app/router.js +++ b/app/assets/javascripts/app/router.js @@ -2,6 +2,8 @@ app.Router = Backbone.Router.extend({ routes: { + "help/:topic": "help", + "help/": "help", "help": "help", "contacts": "contacts", "conversations": "conversations", @@ -36,10 +38,10 @@ app.Router = Backbone.Router.extend({ this.route(/^bookmarklet(?:\?(.*))?/, "bookmarklet"); }, - help: function() { + help: function(topic) { app.help = new app.views.Help(); $("#help").prepend(app.help.el); - app.help.render(); + app.help.render(topic); }, contacts: function() { diff --git a/app/assets/javascripts/app/views/help_view.js b/app/assets/javascripts/app/views/help_view.js index 4df60c68f..a6b0d4d3c 100644 --- a/app/assets/javascripts/app/views/help_view.js +++ b/app/assets/javascripts/app/views/help_view.js @@ -9,7 +9,7 @@ app.views.Help = app.views.StaticContentView.extend({ "click .faq-link-sharing" : "sharing", "click .faq-link-posts-and-posting" : "postsAndPosting", "click .faq-link-tags": "tags", - "click .faq-link-keyboard-shortcuts" : "keyboardShortcuts", + "click .faq-link-keyboard-shortcuts" : "keyboardShortcuts" }, initialize : function() { @@ -19,19 +19,19 @@ app.views.Help = app.views.StaticContentView.extend({ get_support_a_tutorials: { tutorials: this.linkHtml("https://diasporafoundation.org/tutorials", Diaspora.I18n.t( 'tutorials' ))}, get_support_a_wiki: { link: this.linkHtml("https://wiki.diasporafoundation.org/Special:Search", Diaspora.I18n.t( 'wiki' ))}, get_support_a_irc: { irc: this.linkHtml("https://wiki.diasporafoundation.org/How_We_Communicate#IRC", Diaspora.I18n.t( 'irc' ))}, - get_support_a_hashtag: { question: this.linkHtml("/tags/question", "#question")}, + get_support_a_hashtag: { question: this.linkHtml("/tags/question", "#question")} }; this.POSTS_AND_POSTING_SUBS = { format_text_a: { markdown: this.linkHtml("http://diasporafoundation.org/formatting", Diaspora.I18n.t( 'markdown' )), - here: this.linkHtml("http://daringfireball.net/projects/markdown/syntax", Diaspora.I18n.t( 'here' )), + here: this.linkHtml("http://daringfireball.net/projects/markdown/syntax", Diaspora.I18n.t( 'here' )) } }; this.TAGS_SUBS = { filter_tags_a: { - third_party_tools: this.linkHtml("https://wiki.diasporafoundation.org/Tools_to_use_with_Diaspora", Diaspora.I18n.t( 'third_party_tools' )), + third_party_tools: this.linkHtml("https://wiki.diasporafoundation.org/Tools_to_use_with_Diaspora", Diaspora.I18n.t( 'third_party_tools' )) } }; @@ -51,19 +51,22 @@ app.views.Help = app.views.StaticContentView.extend({ title_sharing: Diaspora.I18n.t( 'sharing.title' ), title_tags: Diaspora.I18n.t( 'tags.title' ), title_keyboard_shortcuts: Diaspora.I18n.t( 'keyboard_shortcuts.title' ), - title_miscellaneous: Diaspora.I18n.t( 'miscellaneous.title' ), + title_miscellaneous: Diaspora.I18n.t( 'miscellaneous.title' ) }; return this; }, - render: function(){ + render: function(topic){ var section = 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(); } + return section; }, @@ -107,8 +110,12 @@ app.views.Help = app.views.StaticContentView.extend({ menuClicked: function(e) { this.resetMenu(); + $(e.target).hide(); $(e.target).next().show(); + + var data = $(e.target).data('section'); + app.router.navigate('help/' + data); }, clearItems: function() { @@ -133,6 +140,18 @@ app.views.Help = app.views.StaticContentView.extend({ this.$('#faq').append(help_section.render().el); }, + /** + * Returns The section title whose data-section property equals the given query + * Returns null if nothing found + * @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; } + return res; + }, + gettingHelp: function(e) { this.renderStaticSection("getting_help", "faq_getting_help", this.GETTING_HELP_SUBS); this.menuClicked(e); @@ -170,6 +189,6 @@ app.views.Help = app.views.StaticContentView.extend({ linkHtml: function(url, text) { return "" + text + ""; - }, + } }); -// @license-end +// @license-end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 1c245599b..8aa59a909 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -223,6 +223,7 @@ Diaspora::Application.routes.draw do # Help get 'help' => 'help#faq', :as => 'help' + get 'help/:topic' => 'help#faq' #Protocol Url get 'protocol' => redirect("http://wiki.diasporafoundation.org/Federation_Protocol_Overview") diff --git a/spec/javascripts/app/views/help_view_spec.js b/spec/javascripts/app/views/help_view_spec.js index 9561f998f..0ab8e1a26 100644 --- a/spec/javascripts/app/views/help_view_spec.js +++ b/spec/javascripts/app/views/help_view_spec.js @@ -86,5 +86,39 @@ 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(); + }); + + 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 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 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(); + }); }); -}); +}); \ No newline at end of file From 9373d5bd20b145d477e2287118df0d7ffa40f2c6 Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Sat, 14 Feb 2015 19:30:56 +0100 Subject: [PATCH 2/3] Fix jasmine tests for new help routes --- app/assets/javascripts/app/router.js | 6 +- app/assets/javascripts/app/views/help_view.js | 18 ++--- spec/javascripts/app/views/help_view_spec.js | 69 +++++++++++-------- 3 files changed, 53 insertions(+), 40 deletions(-) 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); + }); + }); + }); +}); From c5468f072fb24e4185a8800d11af3206ee8b1d05 Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Sat, 14 Feb 2015 19:44:00 +0100 Subject: [PATCH 3/3] JSHint: Add spyOn as a global variable --- config/.jshint.json | 1 + 1 file changed, 1 insertion(+) diff --git a/config/.jshint.json b/config/.jshint.json index f4a747e9f..7303e3641 100644 --- a/config/.jshint.json +++ b/config/.jshint.json @@ -58,6 +58,7 @@ "factory", "stubView", "exports", + "spyOn", "app", "Diaspora",