require 'test_helper' module Workarea decorate Storefront::SearchAutocompleteSystemTest, with: :one_theme do def test_autocomplete create_product(name: 'Test One') create_product(name: 'Test Two') create_search_by_week(query_string: 'test one', searches: 5, total_results: 5) create_search_by_week(query_string: 'test two', searches: 10, total_results: 5) visit storefront.root_path find('[data-header-search-ui] button').click fill_in 'q', with: '' within '#search_autocomplete' do assert_text(t('workarea.storefront.search_autocomplete.trending_products')) assert_text(t('workarea.storefront.search_autocomplete.trending_searches')) assert_match(/Foo Product.*Baz Product.*Bar Product/m, page.body) assert_match(/foo search.*baz search.*bar search/m, page.body) end fill_in 'q', with: 'te' within '#search_autocomplete' do assert_text('Test Two') assert_match(/test two.*test one/m, page.body) end fill_in 'q', with: '' within '#search_autocomplete' do assert_text(t('workarea.storefront.search_autocomplete.trending_products')) assert_text(t('workarea.storefront.search_autocomplete.trending_searches')) assert_match(/Foo Product.*Baz Product.*Bar Product/m, page.body) assert_match(/foo search.*baz search.*bar search/m, page.body) end fill_in 'q', with: 'corge' within '#search_autocomplete' do assert_text(t('workarea.storefront.search_autocomplete.trending_products')) assert_text(t('workarea.storefront.search_autocomplete.trending_searches')) assert_match(/Foo Product.*Baz Product.*Bar Product/m, page.body) assert_match(/foo search.*baz search.*bar search/m, page.body) end end end end