File tree Expand file tree Collapse file tree 3 files changed +21
-49
lines changed
Expand file tree Collapse file tree 3 files changed +21
-49
lines changed Original file line number Diff line number Diff line change 22
33[ ![ Gem Version] ( https://badge.fury.io/rb/activeadmin-searchable_select.svg )] ( http://badge.fury.io/rb/activeadmin-searchable_select )
44[ ![ NPM Version] ( https://badge.fury.io/js/@codevise%2Factiveadmin-searchable_select.svg )] ( https://badge.fury.io/js/@codevise%2Factiveadmin-searchable_select )
5- ![ npm] ( https://img.shields.io/npm/dm/@codevise/activeadmin-searchable_select )
5+ [ ![ npm] ( https://img.shields.io/npm/dm/@codevise/activeadmin-searchable_select )] ( https://www.npmjs.com/package /@codevise/activeadmin-searchable_select)
66[ ![ Build Status] ( https://github.com/codevise/activeadmin-searchable_select.svg?branch=master )] ( https://github.com/codevise/activeadmin-searchable_select/actions )
77
88Searchable select boxes (via [ Select2] ( https://select2.org/ ) ) for
Original file line number Diff line number Diff line change 5050 expect ( response . body ) . to have_selector ( '.searchable-select-input' \
5151 "[data-ajax-url*='#{ url_matcher } ']" )
5252 end
53-
54- context 'when using belongs_to' do
55- before ( :each ) do
56- ActiveAdminHelpers . setup do
57-
58- ActiveAdmin . register ( OptionType )
59-
60- ActiveAdmin . register ( Product ) do
61-
62- ActiveAdmin . register ( OptionValue ) do
63- belongs_to :option_type
64- searchable_select_options ( scope : lambda do |params |
65- OptionValue . where (
66- option_type_id : params [ :option_type_id ]
67- )
68- end ,
69- text_attribute : :value )
70- end
71-
72- ActiveAdmin . register ( Variant ) do
73- belongs_to :product
74-
75- form do |f |
76- f . input ( :option_value ,
77- as : :searchable_select ,
78- ajax : {
79- resource : OptionValue ,
80- path_params : {
81- option_type_id : f . object . product . option_type_id
82- }
83- } )
84- end
85- end
86- end
87- end
88-
89- it 'pre-select items in the associations' do
90- option_type = OptionType . create
91- product = Product . create ( option_type : option_type )
92- option_value = OptionValue . create ( option_type : option_type , value : 'Red' )
93- variant = Variant . create ( product : product , option_value : option_value )
94-
95- get "/admin/products/#{ product . id } /variants/#{ variant . id } /edit"
96-
97- expect ( response . body ) . to have_selector ( '.searchable-select-input option[selected]' ,
98- count : 1 )
99- end
100- end
10153end
Original file line number Diff line number Diff line change 180180 expect ( select_box_items . size ) . to eq ( 15 )
181181 end
182182 end
183+
184+ describe 'edit page with searchable select filter' do
185+ it 'preselects item' do
186+ option_type = OptionType . create ( name : 'Color' )
187+ ot = OptionType . create ( name : 'Size' )
188+ option_value = OptionValue . create ( value : 'Black' , option_type : option_type )
189+ OptionValue . create ( value : 'Orange' , option_type : option_type )
190+ OptionValue . create ( value : 'M' , option_type : ot )
191+ product = Product . create ( name : 'Cap' , option_type : option_type )
192+ variant = Variant . create ( product : product , option_value : option_value )
193+
194+ visit "/admin/products/#{ product . id } /variants/#{ variant . id } /edit"
195+
196+ expect ( select_box_selected_item_text ) . to eq ( 'Black' )
197+ end
198+ end
183199 end
184200
185201 def expand_select_box
@@ -198,6 +214,10 @@ def select_box_items
198214 all ( '.select2-dropdown li' ) . map ( &:text )
199215 end
200216
217+ def select_box_selected_item_text
218+ find ( '.select2-selection' ) . text
219+ end
220+
201221 def wait_for_ajax
202222 Timeout . timeout ( Capybara . default_max_wait_time ) do
203223 sleep 0.1
You can’t perform that action at this time.
0 commit comments