Skip to content
Snippets Groups Projects
Commit c0fcb529 authored by Syed Hassan Raza's avatar Syed Hassan Raza
Browse files

Fix checking empty array

parent eb6bb036
No related branches found
No related tags found
No related merge requests found
......@@ -28,13 +28,13 @@
context.topics_html = this.renderCategoryMap(this.course_settings.get('category_map'));
edx.HtmlUtils.setHtml(this.$el, edx.HtmlUtils.template($('#topic-template').html())(context));
$general = this.$('.post-topic option:contains(General)');
$general = this.$('.post-topic option:contains(General)'); // always return array.
if (this.getCurrentTopicId()) {
this.setTopic(this.$('.post-topic option').filter(
'[data-discussion-id="' + this.getCurrentTopicId() + '"]'
));
} else if ($general) {
} else if ($general.length > 0) {
this.setTopic($general);
} else {
this.setTopic(this.$('.post-topic option').first());
......
......@@ -2,6 +2,7 @@
(function() {
'use strict';
describe('DiscussionTopicMenuView', function() {
var ExpectedDiscussionId;
beforeEach(function() {
this.createTopicView = function(options) {
options = _.extend({
......@@ -87,12 +88,18 @@
expect(this.view.$el.find('option.topic-title:selected').text()).toContain('<em>');
});
it('appropriate topic is selected if `topicId` is passed', function() {
it('appropriate topic is selected if topicId is passed', function() {
this.createTopicView({
topicId: 'c49f0dfb8fc94c9c8d9999cc95190c56'
});
this.view.render();
expect(this.view.$el.find('option.topic-title:selected').text()).toEqual('Numerical Input');
});
it('if general topic is not present then topiId is set to first discussion topicId', function() {
this.createTopicView({});
this.view.render();
ExpectedDiscussionId = this.view.$('.post-topic option').first().data('discussion-id');
expect(this.view.getCurrentTopicId()).toEqual(ExpectedDiscussionId);
});
});
}).call(this);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment