Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Gem Version](https://badge.fury.io/rb/activeadmin-searchable_select.svg)](http://badge.fury.io/rb/activeadmin-searchable_select)
[![NPM Version](https://badge.fury.io/js/@codevise%2Factiveadmin-searchable_select.svg)](https://badge.fury.io/js/@codevise%2Factiveadmin-searchable_select)
![npm](https://img.shields.io/npm/dm/@codevise/activeadmin-searchable_select)
[![npm](https://img.shields.io/npm/dm/@codevise/activeadmin-searchable_select)](https://www.npmjs.com/package/@codevise/activeadmin-searchable_select)
[![Build Status](https://github.com/codevise/activeadmin-searchable_select.svg?branch=master)](https://github.com/codevise/activeadmin-searchable_select/actions)

Searchable select boxes (via [Select2](https://select2.org/)) for
Expand Down
48 changes: 0 additions & 48 deletions spec/features/ajax_params_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,52 +50,4 @@
expect(response.body).to have_selector('.searchable-select-input' \
"[data-ajax-url*='#{url_matcher}']")
end

context 'when using belongs_to' do
before(:each) do
ActiveAdminHelpers.setup do

ActiveAdmin.register(OptionType)

ActiveAdmin.register(Product) do

ActiveAdmin.register(OptionValue) do
belongs_to :option_type
searchable_select_options(scope: lambda do |params|
OptionValue.where(
option_type_id: params[:option_type_id]
)
end,
text_attribute: :value)
end

ActiveAdmin.register(Variant) do
belongs_to :product

form do |f|
f.input(:option_value,
as: :searchable_select,
ajax: {
resource: OptionValue,
path_params: {
option_type_id: f.object.product.option_type_id
}
})
end
end
end
end

it 'pre-select items in the associations' do
option_type = OptionType.create
product = Product.create(option_type: option_type)
option_value = OptionValue.create(option_type: option_type, value: 'Red')
variant = Variant.create(product: product, option_value: option_value)

get "/admin/products/#{product.id}/variants/#{variant.id}/edit"

expect(response.body).to have_selector('.searchable-select-input option[selected]',
count: 1)
end
end
end
20 changes: 20 additions & 0 deletions spec/features/end_to_end_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,22 @@
expect(select_box_items.size).to eq(15)
end
end

describe 'edit page with searchable select filter' do
it 'preselects item' do
option_type = OptionType.create(name: 'Color')
ot = OptionType.create(name: 'Size')
option_value = OptionValue.create(value: 'Black', option_type: option_type)
OptionValue.create(value: 'Orange', option_type: option_type)
OptionValue.create(value: 'M', option_type: ot)
product = Product.create(name: 'Cap', option_type: option_type)
variant = Variant.create(product: product, option_value: option_value)

visit "/admin/products/#{product.id}/variants/#{variant.id}/edit"

expect(select_box_selected_item_text).to eq('Black')
end
end
end

def expand_select_box
Expand All @@ -198,6 +214,10 @@ def select_box_items
all('.select2-dropdown li').map(&:text)
end

def select_box_selected_item_text
find('.select2-selection').text
end

def wait_for_ajax
Timeout.timeout(Capybara.default_max_wait_time) do
sleep 0.1
Expand Down