From 13114e5629d49eab14d58df1319eb068dacedba7 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Shibuya Date: Sun, 25 Aug 2024 13:22:11 +0900 Subject: [PATCH] Follow-up for #3630 - Add a spec - Apply Prettier --- .../fields/polymorphic_assosiation_spec.rb | 12 ++++++++++++ src/rails_admin/widgets.js | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/spec/integration/fields/polymorphic_assosiation_spec.rb b/spec/integration/fields/polymorphic_assosiation_spec.rb index 56f4c648c5..ae2ff067fa 100644 --- a/spec/integration/fields/polymorphic_assosiation_spec.rb +++ b/spec/integration/fields/polymorphic_assosiation_spec.rb @@ -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| diff --git a/src/rails_admin/widgets.js b/src/rails_admin/widgets.js index 770d2aced8..38c2ead686 100644 --- a/src/rails_admin/widgets.js +++ b/src/rails_admin/widgets.js @@ -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); });