Skip to content

Commit

Permalink
Do not pick up the placeholder as selection in filtering-multiselect. F…
Browse files Browse the repository at this point in the history
…ixes #2807
  • Loading branch information
mshibuya committed Jun 26, 2019
1 parent 9e528f1 commit 1550260
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
Expand Up @@ -118,7 +118,7 @@

/* Add all to selection */
this.addAll.click(function(e){
widget._select($('option', widget.collection));
widget._select($('option:not(:disabled)', widget.collection));
e.preventDefault();
widget.selection.trigger('change');
});
Expand Down
46 changes: 46 additions & 0 deletions spec/integration/widgets/filtering_multi_select_spec.rb
@@ -0,0 +1,46 @@
require 'spec_helper'

describe 'FilteringMultiSelect widget', type: :request, js: true do
subject { page }

describe 'Choose all button' do
let(:team) { FactoryBot.create :team }
let!(:players) { FactoryBot.create_list :player, 2 }
before do
RailsAdmin.config Team do
field :players
end
end

it 'picks all available items' do
visit edit_path(model_name: 'team', id: team.id)
click_link 'Choose all'
expect(all(:css, '#team_player_ids option', visible: false).map(&:value)).to match_array players.map(&:id).map(&:to_s)
end

context 'when associated_collection_cache_all is false' do
before do
RailsAdmin.config Team do
field(:players) { associated_collection_cache_all false }
end
end

it "does not pick the placeholder for selection" do
visit edit_path(model_name: 'team', id: team.id)
click_link 'Choose all'
expect(page).not_to have_css('#team_player_ids option', visible: false)
expect(page).not_to have_css('.ra-multiselect-selection option')
end

it 'picks all available items' do
visit edit_path(model_name: 'team', id: team.id)
find('input.ra-multiselect-search').set('P')
page.execute_script("$('input.ra-multiselect-search').trigger('focus')")
page.execute_script("$('input.ra-multiselect-search').trigger('keydown')")
expect(page).to have_css('.ra-multiselect-collection option', text: /Player/)
click_link 'Choose all'
expect(all(:css, '#team_player_ids option', visible: false).map(&:value)).to match_array players.map(&:id).map(&:to_s)
end
end
end
end

0 comments on commit 1550260

Please sign in to comment.