From 57f6a7a3b9dffb7a4b3cf7eabf72a111f4804d9c Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Wed, 19 Sep 2018 19:01:32 +0800 Subject: [PATCH] Support clicking different text for select2 helper Interaction with the variant autocomplete is not precise. The specs only search for the product name, then click the first result that matches the product name which they see. This could have been the case because searching using the full variant name does not match the variant. For example, searching "Some Product - 1kg" would not have results, while searching only "Some Product" (the product name) would list "Some Product - 1kg". Clicking the first match does not work in all scenarios. This allows using a separate text for searching and for clicking. --- spec/support/request/web_helper.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/support/request/web_helper.rb b/spec/support/request/web_helper.rb index c37014e637..912c19e445 100644 --- a/spec/support/request/web_helper.rb +++ b/spec/support/request/web_helper.rb @@ -105,6 +105,16 @@ module WebHelper targetted_select2(value, options) end + # Support having different texts to search for and to click in the select2 + # field. + # + # This overrides the method in Spree. + def targetted_select2_search(value, options) + page.execute_script %Q{$('#{options[:from]}').select2('open')} + page.execute_script "$('#{options[:dropdown_css]} input.select2-input').val('#{value}').trigger('keyup-change');" + select_select2_result(options[:select_text] || value) + end + def multi_select2_select(value, options) find("#s2id_#{options[:from]}").find('ul li.select2-search-field').click select_select2_result(value)