Skip to content

Commit

Permalink
Follow-up for #3630
Browse files Browse the repository at this point in the history
- Add a spec
- Apply Prettier
  • Loading branch information
mshibuya committed Aug 25, 2024
1 parent b666c63 commit 13114e5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions spec/integration/fields/polymorphic_assosiation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@
expect(@comment.commentable).to eq @hardball
end

it 'clears the selected id on type change', js: true do
@players = ['Jackie Robinson', 'Rob Wooten'].map { |name| FactoryBot.create :player, name: name }
visit new_path(model_name: 'comment')
select 'Player', from: 'comment[commentable_type]'
find('input.ra-filtering-select-input').set('Rob')
page.execute_script("document.querySelector('input.ra-filtering-select-input').dispatchEvent(new KeyboardEvent('keydown'))")
expect(page).to have_selector('ul.ui-autocomplete li.ui-menu-item a')
page.execute_script %{[...document.querySelectorAll('ul.ui-autocomplete li.ui-menu-item')].find(e => e.innerText.includes("Jackie Robinson")).click()}
select 'Team', from: 'comment[commentable_type]'
expect(find('#comment_commentable_id', visible: false).value).to eq ''
end

context 'when the associated model is declared in a two-level namespace' do
it 'successfully saves the record', js: true do
polymorphic_association_tests = ['Jackie Robinson', 'Rob Wooten'].map do |name|
Expand Down
2 changes: 1 addition & 1 deletion src/rails_admin/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ import I18n from "./i18n";
"options"
);
object_select.data("options", selected_data);
object_select.val('');
object_select.val("");
object_select.filteringSelect("destroy");
object_select.filteringSelect(selected_data);
});
Expand Down

0 comments on commit 13114e5

Please sign in to comment.