Fix checking empty array

This commit is contained in:
Syed Hassan Raza
2016-10-19 16:47:02 +05:00
parent eb6bb03604
commit c0fcb529ec
2 changed files with 10 additions and 3 deletions

View File

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

View File

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