diff --git a/common/static/coffee/spec/discussion/view/new_post_view_spec.coffee b/common/static/coffee/spec/discussion/view/new_post_view_spec.coffee new file mode 100644 index 0000000000..a7b20906e1 --- /dev/null +++ b/common/static/coffee/spec/discussion/view/new_post_view_spec.coffee @@ -0,0 +1,79 @@ +# -*- coding: utf-8 -*- +describe "NewPostView", -> + beforeEach -> + setFixtures( + """ +
+
+
+ +
+
+
+ """ + ) + window.$$course_id = "edX/999/test" + spyOn(DiscussionUtil, "makeWmdEditor") + @discussion = new Discussion([], {pages: 1}) + @view = new NewPostView( + el: $(".new-post-article"), + collection: @discussion, + ) + @parent_category_text = @view.$el.find( "ul.topic_menu li[role='menuitem'] > a" )[0].text + @selected_option_text = @view.$el.find( "ul.topic_menu li[role='menuitem'] > a" )[1].text + + describe "Drop down works correct", -> + + it "completely show parent category and sub-category", -> + complete_text = @parent_category_text + " / " + @selected_option_text + selected_text_width = @view.getNameWidth(complete_text) + @view.maxNameWidth = selected_text_width + 1 + @view.$el.find( "ul.topic_menu li[role='menuitem'] > a" )[1].click() + dropdown_text = @view.$el.find(".form-topic-drop > a").text() + expect(complete_text+' ▾').toEqual(dropdown_text) + + it "completely show just sub-category", -> + complete_text = @parent_category_text + " / " + @selected_option_text + selected_text_width = @view.getNameWidth(complete_text) + @view.maxNameWidth = selected_text_width - 10 + @view.$el.find( "ul.topic_menu li[role='menuitem'] > a" )[1].click() + dropdown_text = @view.$el.find(".form-topic-drop > a").text() + expect(dropdown_text.indexOf("…")).toEqual(0) + expect(dropdown_text).toContain(@selected_option_text) + + it "partially show sub-category", -> + parent_width = @view.getNameWidth(@parent_category_text) + complete_text = @parent_category_text + " / " + @selected_option_text + selected_text_width = @view.getNameWidth(complete_text) + @view.maxNameWidth = selected_text_width - parent_width + @view.$el.find( "ul.topic_menu li[role='menuitem'] > a" )[1].click() + dropdown_text = @view.$el.find(".form-topic-drop > a").text() + expect(dropdown_text.indexOf("…")).toEqual(0) + expect(dropdown_text.lastIndexOf("…")).toBeGreaterThan(0) + + it "broken span doesn't occur", -> + complete_text = @parent_category_text + " / " + @selected_option_text + selected_text_width = @view.getNameWidth(complete_text) + @view.maxNameWidth = @view.getNameWidth(@selected_option_text) + 100 + @view.$el.find( "ul.topic_menu li[role='menuitem'] > a" )[1].click() + dropdown_text = @view.$el.find(".form-topic-drop > a").text() + expect(dropdown_text.indexOf("/ span>")).toEqual(-1) diff --git a/common/static/coffee/src/discussion/views/new_post_view.coffee b/common/static/coffee/src/discussion/views/new_post_view.coffee index ef7d1e86e9..71d605ed1b 100644 --- a/common/static/coffee/src/discussion/views/new_post_view.coffee +++ b/common/static/coffee/src/discussion/views/new_post_view.coffee @@ -51,7 +51,7 @@ if Backbone? # Set here because 1) the window might get resized and things could # change and 2) can't set in initialize because the button is hidden - @maxNameWidth = @dropdownButton.width() * 0.9 + @maxNameWidth = @dropdownButton.width() - 40 # Need a fat arrow because hideTopicDropdown is passed as a callback to bind hideTopicDropdown: () => @@ -81,7 +81,7 @@ if Backbone? getFullTopicName: (topicElement) -> name = topicElement.html() topicElement.parents('ul').not('.topic_menu').each -> - name = $(this).siblings('a').html() + ' / ' + name + name = $(this).siblings('a').text() + ' / ' + name return name getNameWidth: (name) ->