Fix jasmine tests for new help routes

This commit is contained in:
Steffen van Bergerem 2015-02-14 19:30:56 +01:00
parent aa62266376
commit 9373d5bd20
3 changed files with 53 additions and 40 deletions

View file

@ -2,7 +2,7 @@
app.Router = Backbone.Router.extend({ app.Router = Backbone.Router.extend({
routes: { routes: {
"help/:topic": "help", "help/:section": "help",
"help/": "help", "help/": "help",
"help": "help", "help": "help",
"contacts": "contacts", "contacts": "contacts",
@ -38,10 +38,10 @@ app.Router = Backbone.Router.extend({
this.route(/^bookmarklet(?:\?(.*))?/, "bookmarklet"); this.route(/^bookmarklet(?:\?(.*))?/, "bookmarklet");
}, },
help: function(topic) { help: function(section) {
app.help = new app.views.Help(); app.help = new app.views.Help();
$("#help").prepend(app.help.el); $("#help").prepend(app.help.el);
app.help.render(topic); app.help.render(section);
}, },
contacts: function() { contacts: function() {

View file

@ -57,17 +57,17 @@ app.views.Help = app.views.StaticContentView.extend({
return this; return this;
}, },
render: function(topic){ render: function(section){
var section = app.views.Base.prototype.render.apply(this, arguments); var html = app.views.Base.prototype.render.apply(this, arguments);
// After render actions // After render actions
this.resetMenu(true); this.resetMenu(true);
this.renderStaticSection("getting_help", "faq_getting_help", this.GETTING_HELP_SUBS); this.renderStaticSection("getting_help", "faq_getting_help", this.GETTING_HELP_SUBS);
var elTarget = this.findTopic(topic); var elTarget = this.findSection(section);
if(elTarget != null){ $(elTarget).click(); } if(elTarget !== null){ $(elTarget).click(); }
return section; return html;
}, },
showItems: function(el) { showItems: function(el) {
@ -146,9 +146,9 @@ app.views.Help = app.views.StaticContentView.extend({
* @param dataValue Value for the data-section to find * @param dataValue Value for the data-section to find
* @returns {jQuery} * @returns {jQuery}
*/ */
findTopic: function(dataValue){ findSection: function(data){
var res = this.$('a[data-section=' + dataValue + ']'); var res = this.$('a[data-section=' + data + ']');
if(res.length == 0){ return null; } if(res.length === 0){ return null; }
return res; return res;
}, },

View file

@ -86,39 +86,52 @@ describe("app.views.Help", function(){
this.view.$el.find('a[data-section=miscellaneous]').trigger('click'); this.view.$el.find('a[data-section=miscellaneous]').trigger('click');
expect(this.view.$el.find('#faq').children().first().hasClass('faq_question_miscellaneous')).toBeTruthy(); expect(this.view.$el.find('#faq').children().first().hasClass('faq_question_miscellaneous')).toBeTruthy();
}); });
});
it('should not find any topic', function(){ describe("findSection", function() {
expect(this.view.findTopic('you_shall_not_pass')).toBeNull(); beforeEach(function() {
this.view.render();
}); });
it('should find the miscellaneous topic', function(){ it('should return null for an unknown section', function() {
var topic = this.view.$el.find('a[data-section=miscellaneous]'); expect(this.view.findSection('you_shall_not_pass')).toBeNull();
expect(this.view.findTopic('miscellaneous').html()).toBe(topic.html());
}); });
it('should find the keyboard_shortcuts topic', function(){ it('should return the correct section link for existing sections', function() {
var topic = this.view.$el.find('a[data-section=keyboard_shortcuts]'); var sections = [
expect(this.view.findTopic('keyboard_shortcuts').html()).toBe(topic.html()); 'account_and_data_management',
'aspects',
'pods',
'keyboard_shortcuts',
'tags',
'miscellaneous'
];
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());
});
});
});
describe("menuClicked", function() {
beforeEach(function() {
this.view.render();
}); });
it('should find the miscellaneous topic', function(){ it('should rewrite the location', function(){
var topic = this.view.$el.find('a[data-section=tags]'); var sections = [
expect(this.view.findTopic('tags').html()).toBe(topic.html()); 'account_and_data_management',
}); 'miscellaneous'
];
spyOn(app.router, 'navigate');
it('should rewrite route to help/tags', function(){ var self = this;
this.view.$el.find('a[data-section=tags]').trigger('click'); _.each(sections, function(section) {
expect(window.location.href.toString().endsWith("help/tags")).toBeTruthy(); self.view.$el.find('a[data-section=' + section + ']').trigger('click');
}); expect(app.router.navigate).toHaveBeenCalledWith('help/' + section);
});
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();
}); });
}); });
}); });