require 'test_helper' module Workarea decorate Storefront::SearchSystemTest, with: :nvy_theme do decorated do setup :capybara_settings teardown :capybara_reset end def capybara_settings Capybara.default_normalize_ws = true end def capybara_reset Capybara.default_normalize_ws = false end def test_standard_results %w(test testing tests tested).each do |term| visit storefront.search_path(q: term) assert(page.has_content?('Test Product 1')) assert(page.has_content?('Test Product 2')) assert(page.has_content?('$10.00')) assert(page.has_content?('$5.00')) assert(page.has_content?('$7.00')) # Decorated to remove parenthesis from filter link text assert(page.has_content?('Medium 2')) assert(page.has_content?('Small 1')) assert(page.has_no_content?('Red')) end end def test_filtering_results visit storefront.search_path(q: 'test') Capybara.match = :first # Decorated to remove parenthesis from filter link text click_link 'First 1' # Primary nav filtering assert(page.has_content?('Test Product 1')) assert(page.has_no_content?('Test Product 2')) click_link "First #{t('workarea.storefront.products.remove_filter')}" # Price filtering # Decorated to remove parenthesis from filter link text click_link '$10.00 - $19.99 1' assert(page.has_content?('Test Product 1')) assert(page.has_no_content?('Test Product 2')) click_link "$10.00 - $19.99 #{t('workarea.storefront.products.remove_filter')}" # Config filtering # Decorated to remove parenthesis from filter link text click_link 'Small 1' assert(page.has_content?('Test Product 2')) assert(page.has_no_content?('Test Product 1')) click_link "Small #{t('workarea.storefront.products.remove_filter')}" assert(page.has_content?('Test Product 1')) assert(page.has_content?('Test Product 2')) # Mobile Filters Nav resize_window_to('small') visit storefront.search_path(q: 'test') find('[data-mobile-filter-button]').click assert(page.has_selector?('.mobile-filters-nav', visible: true)) within '.mobile-filters-nav' do # Decorated to remove parenthesis from filter link text assert(page.has_content?('$10.00 - $19.99 1')) end page.execute_script("$('body').trigger('click');"); assert(page.has_selector?('.mobile-filters-nav', visible: false)) find('[data-mobile-filter-button]').click assert(page.has_selector?('.mobile-filters-nav', visible: true)) within '.mobile-filters-nav' do click_button t('workarea.storefront.products.filter_nav_close_button') end assert(page.has_selector?('.mobile-filters-nav', visible: false)) end def test_filter_and_sorting_results visit storefront.search_path(q: 'test') Capybara.match = :first # Decorated to remove parenthesis from filter link text click_link 'First 1' assert(page.has_content?('Test Product 1')) assert(page.has_no_content?('Test Product 2')) select(t('workarea.sorts.price_asc'), from: 'sort_top') assert(page.has_content?('Test Product 1')) assert(page.has_no_content?('Test Product 2')) end end end