From b82b7693cf84fe1cf6b34ca0b6c0d688d56f9b7e Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Wed, 8 Dec 2021 09:44:22 +0000 Subject: [PATCH] Fixes #3873 - Search is not triggered/updated if url of search is updated new search item or new search is triggered via global search. --- .../javascripts/app/controllers/search.coffee | 7 +- spec/system/search_spec.rb | 64 ++++++++++++++++++- 2 files changed, 63 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/app/controllers/search.coffee b/app/assets/javascripts/app/controllers/search.coffee index 0cebfb26e..ac17d6930 100644 --- a/app/assets/javascripts/app/controllers/search.coffee +++ b/app/assets/javascripts/app/controllers/search.coffee @@ -56,13 +56,9 @@ class App.Search extends App.Controller @navupdate(url: '#search', type: 'menu') return if _.isEmpty(params.query) - @$('.js-search').val(params.query).trigger('change') - return if @shown - - @search(1000, true) + @$('.js-search').val(params.query).trigger('keyup') hide: -> - @shown = false if @table @table.hide() @@ -108,6 +104,7 @@ class App.Search extends App.Controller return # on other keys, show result + @navigate "#search/#{encodeURIComponent(@searchInput.val())}" @search(0) empty: => diff --git a/spec/system/search_spec.rb b/spec/system/search_spec.rb index 5d3c7d6d4..652af5fc4 100644 --- a/spec/system/search_spec.rb +++ b/spec/system/search_spec.rb @@ -9,7 +9,7 @@ RSpec.describe 'Search', type: :system, authenticated: true, searchindex: true d let(:note) { 'Test note' } before do - configure_elasticsearch(required: true, rebuild: true) + ticket_1 && ticket_2 && configure_elasticsearch(required: true, rebuild: true) end it 'shows default widgets' do @@ -24,8 +24,6 @@ RSpec.describe 'Search', type: :system, authenticated: true, searchindex: true d context 'with ticket search result' do before do - ticket_1 && ticket_2 && rebuild_searchindex - fill_in id: 'global-search', with: 'Testing' click_on 'Show Search Details' @@ -176,4 +174,64 @@ RSpec.describe 'Search', type: :system, authenticated: true, searchindex: true d expect(page).to have_css('.popover-title .is-inactive', count: 1) end end + + describe 'Search is not triggered/updated if url of search is updated new search item or new search is triggered via global search #3873' do + + context 'when search changed via input box' do + before do + visit '#search' + end + + it 'does switch search results properly' do + page.find('.js-search').fill_in(with: '"Testing Ticket 1"', fill_options: { clear: :backspace }) + expect(page.find('.js-tableBody')).to have_text('Testing Ticket 1') + expect(page.find('.js-tableBody')).to have_no_text('Testing Ticket 2') + expect(current_url).to include('Testing%20Ticket%201') + + # switch by global search + page.find('.js-search').fill_in(with: '"Testing Ticket 2"', fill_options: { clear: :backspace }) + expect(page.find('.js-tableBody')).to have_text('Testing Ticket 2') + expect(page.find('.js-tableBody')).to have_no_text('Testing Ticket 1') + expect(current_url).to include('Testing%20Ticket%202') + end + end + + context 'when search changed via global search' do + before do + fill_in id: 'global-search', with: '"Testing Ticket 1"' + click_on 'Show Search Details' + end + + it 'does switch search results properly' do + expect(page.find('.js-tableBody')).to have_text('Testing Ticket 1') + expect(page.find('.js-tableBody')).to have_no_text('Testing Ticket 2') + expect(current_url).to include('Testing%20Ticket%201') + + # switch by global search + fill_in id: 'global-search', with: '"Testing Ticket 2"' + click_on 'Show Search Details' + expect(page.find('.js-tableBody')).to have_text('Testing Ticket 2') + expect(page.find('.js-tableBody')).to have_no_text('Testing Ticket 1') + expect(current_url).to include('Testing%20Ticket%202') + end + end + + context 'when search is changed via url' do + before do + visit '#search/"Testing Ticket 1"' + end + + it 'does switch search results properly' do + expect(page.find('.js-tableBody')).to have_text('Testing Ticket 1') + expect(page.find('.js-tableBody')).to have_no_text('Testing Ticket 2') + expect(current_url).to include('Testing%20Ticket%201') + + # switch by url + visit '#search/"Testing Ticket 2"' + expect(page.find('.js-tableBody')).to have_text('Testing Ticket 2') + expect(page.find('.js-tableBody')).to have_no_text('Testing Ticket 1') + expect(current_url).to include('Testing%20Ticket%202') + end + end + end end