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({
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() {

View file

@ -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 "<a href=\"" + url + "\" target=\"_blank\">" + text + "</a>";
}
});
// @license-end
// @license-end

View file

@ -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());
});
});
});
});
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);
});
});
});
});