Fixed issue with dropdown toggle not updating
Added tests
This commit is contained in:
parent
f4eb55724f
commit
d3ff691d76
3 changed files with 32 additions and 2 deletions
|
@ -211,6 +211,7 @@ class GitLabDropdown
|
||||||
|
|
||||||
@dropdown.on "shown.bs.dropdown", @opened
|
@dropdown.on "shown.bs.dropdown", @opened
|
||||||
@dropdown.on "hidden.bs.dropdown", @hidden
|
@dropdown.on "hidden.bs.dropdown", @hidden
|
||||||
|
$(@el).on "update.label", @updateLabel
|
||||||
@dropdown.on "click", ".dropdown-menu, .dropdown-menu-close", @shouldPropagate
|
@dropdown.on "click", ".dropdown-menu, .dropdown-menu-close", @shouldPropagate
|
||||||
@dropdown.on 'keyup', (e) =>
|
@dropdown.on 'keyup', (e) =>
|
||||||
if e.which is 27 # Escape key
|
if e.which is 27 # Escape key
|
||||||
|
@ -453,7 +454,7 @@ class GitLabDropdown
|
||||||
|
|
||||||
# Toggle the dropdown label
|
# Toggle the dropdown label
|
||||||
if @options.toggleLabel
|
if @options.toggleLabel
|
||||||
$(@el).find(".dropdown-toggle-text").text @options.toggleLabel
|
@updateLabel()
|
||||||
else
|
else
|
||||||
selectedObject
|
selectedObject
|
||||||
else if el.hasClass(INDETERMINATE_CLASS)
|
else if el.hasClass(INDETERMINATE_CLASS)
|
||||||
|
@ -480,7 +481,7 @@ class GitLabDropdown
|
||||||
|
|
||||||
# Toggle the dropdown label
|
# Toggle the dropdown label
|
||||||
if @options.toggleLabel
|
if @options.toggleLabel
|
||||||
$(@el).find(".dropdown-toggle-text").text @options.toggleLabel(selectedObject, el)
|
@updateLabel(selectedObject, el)
|
||||||
if value?
|
if value?
|
||||||
if !field.length and fieldName
|
if !field.length and fieldName
|
||||||
@addInput(fieldName, value)
|
@addInput(fieldName, value)
|
||||||
|
@ -579,6 +580,9 @@ class GitLabDropdown
|
||||||
# Scroll the dropdown content up
|
# Scroll the dropdown content up
|
||||||
$dropdownContent.scrollTop(listItemTop - dropdownContentTop)
|
$dropdownContent.scrollTop(listItemTop - dropdownContentTop)
|
||||||
|
|
||||||
|
updateLabel: (selected = null, el = null) =>
|
||||||
|
$(@el).find(".dropdown-toggle-text").text @options.toggleLabel(selected, el)
|
||||||
|
|
||||||
$.fn.glDropdown = (opts) ->
|
$.fn.glDropdown = (opts) ->
|
||||||
return @.each ->
|
return @.each ->
|
||||||
if (!$.data @, 'glDropdown')
|
if (!$.data @, 'glDropdown')
|
||||||
|
|
|
@ -54,6 +54,7 @@ issuable_created = false
|
||||||
|
|
||||||
# Submit the form to get new data
|
# Submit the form to get new data
|
||||||
Issuable.filterResults $('.filter-form')
|
Issuable.filterResults $('.filter-form')
|
||||||
|
$('.js-label-select').trigger('update.label')
|
||||||
|
|
||||||
toggleLabelFilters: ->
|
toggleLabelFilters: ->
|
||||||
$filteredLabels = $('.filtered-labels')
|
$filteredLabels = $('.filtered-labels')
|
||||||
|
|
|
@ -174,4 +174,29 @@ feature 'Issue filtering by Labels', feature: true do
|
||||||
expect(find('.filtered-labels')).not_to have_content "feature"
|
expect(find('.filtered-labels')).not_to have_content "feature"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'remove filtered labels', js: true do
|
||||||
|
before do
|
||||||
|
page.within '.labels-filter' do
|
||||||
|
click_button 'Label'
|
||||||
|
click_link 'bug'
|
||||||
|
find('.dropdown-menu-close').click
|
||||||
|
end
|
||||||
|
|
||||||
|
page.within '.filtered-labels' do
|
||||||
|
expect(page).to have_content 'bug'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should allow user to remove filtered labels' do
|
||||||
|
page.within '.filtered-labels' do
|
||||||
|
first('.js-label-filter-remove').click
|
||||||
|
expect(page).not_to have_content 'bug'
|
||||||
|
end
|
||||||
|
|
||||||
|
page.within '.labels-filter' do
|
||||||
|
expect(page).not_to have_content 'bug'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue