|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe 'FilteringMultiSelect widget', type: :request, js: true do |
| 4 | + subject { page } |
| 5 | + |
| 6 | + describe 'Choose all button' do |
| 7 | + let(:team) { FactoryBot.create :team } |
| 8 | + let!(:players) { FactoryBot.create_list :player, 2 } |
| 9 | + before do |
| 10 | + RailsAdmin.config Team do |
| 11 | + field :players |
| 12 | + end |
| 13 | + end |
| 14 | + |
| 15 | + it 'picks all available items' do |
| 16 | + visit edit_path(model_name: 'team', id: team.id) |
| 17 | + click_link 'Choose all' |
| 18 | + expect(all(:css, '#team_player_ids option', visible: false).map(&:value)).to match_array players.map(&:id).map(&:to_s) |
| 19 | + end |
| 20 | + |
| 21 | + context 'when associated_collection_cache_all is false' do |
| 22 | + before do |
| 23 | + RailsAdmin.config Team do |
| 24 | + field(:players) { associated_collection_cache_all false } |
| 25 | + end |
| 26 | + end |
| 27 | + |
| 28 | + it "does not pick the placeholder for selection" do |
| 29 | + visit edit_path(model_name: 'team', id: team.id) |
| 30 | + click_link 'Choose all' |
| 31 | + expect(page).not_to have_css('#team_player_ids option', visible: false) |
| 32 | + expect(page).not_to have_css('.ra-multiselect-selection option') |
| 33 | + end |
| 34 | + |
| 35 | + it 'picks all available items' do |
| 36 | + visit edit_path(model_name: 'team', id: team.id) |
| 37 | + find('input.ra-multiselect-search').set('P') |
| 38 | + page.execute_script("$('input.ra-multiselect-search').trigger('focus')") |
| 39 | + page.execute_script("$('input.ra-multiselect-search').trigger('keydown')") |
| 40 | + expect(page).to have_css('.ra-multiselect-collection option', text: /Player/) |
| 41 | + click_link 'Choose all' |
| 42 | + expect(all(:css, '#team_player_ids option', visible: false).map(&:value)).to match_array players.map(&:id).map(&:to_s) |
| 43 | + end |
| 44 | + end |
| 45 | + end |
| 46 | +end |
0 commit comments