diff --git a/spec/support/request/web_helper.rb b/spec/support/request/web_helper.rb index 42d7cb65b6..71799e4030 100644 --- a/spec/support/request/web_helper.rb +++ b/spec/support/request/web_helper.rb @@ -112,6 +112,20 @@ module WebHelper tomselect_wrapper.find(:css, '.ts-dropdown .ts-dropdown-content .option', text: value).click end + def open_tomselect_to_validate!(page, field_name) + tomselect_wrapper = page.find_field(field_name).sibling(".ts-wrapper") + tomselect_wrapper.find(".ts-control").click # open the dropdown + + raise 'Please pass the block for expectations' unless block_given? + + # execute block containing expectations + yield + + tomselect_wrapper.find( + '.ts-dropdown .ts-dropdown-content .option.active', + ).click # close the dropdown by selecting the already selected value + end + def request_monitor_finished(controller = nil) page.evaluate_script("#{angular_scope(controller)}.scope().RequestMonitor.loading == false") end diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index 2f4dde4718..0eff69cde8 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -699,22 +699,23 @@ describe 'As an enterprise user, I can manage my products', feature: :admin_styl within row_containing_name(product_a.name) do validate_tomselect_without_search!( page, "Producer", - producer_to_select, producer_search_selector ) + tomselect_select(producer_to_select, from: "Producer") end within row_containing_name(variant_a1.display_name) do validate_tomselect_without_search!( page, "Category", - category_to_select, categories_search_selector ) + tomselect_select(category_to_select, from: "Category") + validate_tomselect_without_search!( page, "Tax Category", - tax_category_to_select, tax_categories_search_selector ) + tomselect_select(tax_category_to_select, from: "Tax Category") end click_button "Save changes" @@ -746,24 +747,25 @@ describe 'As an enterprise user, I can manage my products', feature: :admin_styl within row_containing_name(product_a.name) do validate_tomselect_with_search!( page, "Producer", - producer_to_select, producer_search_selector ) + tomselect_search_and_select(producer_to_select, from: "Producer") end within row_containing_name(variant_a1.display_name) do sleep(0.1) validate_tomselect_with_search!( page, "Category", - category_to_select, categories_search_selector ) + tomselect_search_and_select(category_to_select, from: "Category") + sleep(0.1) validate_tomselect_with_search!( page, "Tax Category", - tax_category_to_select, tax_categories_search_selector ) + tomselect_search_and_select(tax_category_to_select, from: "Tax Category") end click_button "Save changes" @@ -1146,24 +1148,16 @@ describe 'As an enterprise user, I can manage my products', feature: :admin_styl @tax_category_column ||= '[data-controller="variant"] > td:nth-child(10)' end - def validate_tomselect_without_search!(page, field_name, value, search_selector) - tomselect_wrapper = page.find_field(field_name).sibling(".ts-wrapper") - tomselect_wrapper.find(".ts-control").click - - expect(page).not_to have_selector(search_selector) - - tomselect_wrapper.find(:css, '.ts-dropdown .ts-dropdown-content .option', - text: value).click + def validate_tomselect_without_search!(page, field_name, search_selector) + open_tomselect_to_validate!(page, field_name) do + expect(page).not_to have_selector(search_selector) + end end - def validate_tomselect_with_search!(page, field_name, value, search_selector) - tomselect_wrapper = page.find_field(field_name).sibling(".ts-wrapper") - tomselect_wrapper.find(".ts-control").click - - expect(page).to have_selector(search_selector) - - tomselect_wrapper.find(:css, '.ts-dropdown input.dropdown-input').send_keys(value) - tomselect_wrapper.find(:css, '.ts-dropdown .ts-dropdown-content .option', text: value).click + def validate_tomselect_with_search!(page, field_name, search_selector) + open_tomselect_to_validate!(page, field_name) do + expect(page).to have_selector(search_selector) + end end def random_producer(product)