2019-07-25 05:24:42 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-03-30 02:04:05 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-16 18:09:01 +00:00
|
|
|
RSpec.describe 'Recent searches', :js do
|
2017-03-30 02:04:05 +00:00
|
|
|
include FilteredSearchHelpers
|
|
|
|
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:project_1) { create(:project, :public) }
|
|
|
|
let(:project_2) { create(:project, :public) }
|
2017-05-06 02:33:21 +00:00
|
|
|
let(:project_1_local_storage_key) { "#{project_1.full_path}-issue-recent-searches" }
|
2017-03-30 02:04:05 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
Capybara.ignore_hidden_elements = false
|
2017-05-06 02:33:21 +00:00
|
|
|
create(:issue, project: project_1)
|
|
|
|
create(:issue, project: project_2)
|
2017-03-30 02:04:05 +00:00
|
|
|
|
2017-05-06 02:33:21 +00:00
|
|
|
# Visit any fast-loading page so we can clear local storage without a DOM exception
|
|
|
|
visit '/404'
|
2017-03-30 02:04:05 +00:00
|
|
|
remove_recent_searches
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
Capybara.ignore_hidden_elements = true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'searching adds to recent searches' do
|
2017-06-29 17:06:35 +00:00
|
|
|
visit project_issues_path(project_1)
|
2017-03-30 02:04:05 +00:00
|
|
|
|
|
|
|
input_filtered_search('foo', submit: true)
|
|
|
|
input_filtered_search('bar', submit: true)
|
|
|
|
|
2017-10-19 18:36:47 +00:00
|
|
|
items = all('.filtered-search-history-dropdown-item', visible: false, count: 2)
|
2017-03-30 02:04:05 +00:00
|
|
|
|
|
|
|
expect(items[0].text).to eq('bar')
|
|
|
|
expect(items[1].text).to eq('foo')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'visiting URL with search params adds to recent searches' do
|
2017-06-29 17:06:35 +00:00
|
|
|
visit project_issues_path(project_1, label_name: 'foo', search: 'bar')
|
|
|
|
visit project_issues_path(project_1, label_name: 'qux', search: 'garply')
|
2017-03-30 02:04:05 +00:00
|
|
|
|
2017-10-19 18:36:47 +00:00
|
|
|
items = all('.filtered-search-history-dropdown-item', visible: false, count: 2)
|
2017-03-30 02:04:05 +00:00
|
|
|
|
2020-01-02 13:03:23 +00:00
|
|
|
expect(items[0].text).to eq('label: = ~qux garply')
|
|
|
|
expect(items[1].text).to eq('label: = ~foo bar')
|
2017-03-30 02:04:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'saved recent searches are restored last on the list' do
|
2017-05-06 02:33:21 +00:00
|
|
|
set_recent_searches(project_1_local_storage_key, '["saved1", "saved2"]')
|
2017-03-30 02:04:05 +00:00
|
|
|
|
2017-06-29 17:06:35 +00:00
|
|
|
visit project_issues_path(project_1, search: 'foo')
|
2017-03-30 02:04:05 +00:00
|
|
|
|
2017-10-19 18:36:47 +00:00
|
|
|
items = all('.filtered-search-history-dropdown-item', visible: false, count: 3)
|
2017-03-30 02:04:05 +00:00
|
|
|
|
|
|
|
expect(items[0].text).to eq('foo')
|
|
|
|
expect(items[1].text).to eq('saved1')
|
|
|
|
expect(items[2].text).to eq('saved2')
|
|
|
|
end
|
|
|
|
|
2017-05-06 02:33:21 +00:00
|
|
|
it 'searches are scoped to projects' do
|
2017-06-29 17:06:35 +00:00
|
|
|
visit project_issues_path(project_1)
|
2017-05-06 02:33:21 +00:00
|
|
|
|
|
|
|
input_filtered_search('foo', submit: true)
|
|
|
|
input_filtered_search('bar', submit: true)
|
|
|
|
|
2017-06-29 17:06:35 +00:00
|
|
|
visit project_issues_path(project_2)
|
2017-05-06 02:33:21 +00:00
|
|
|
|
|
|
|
input_filtered_search('more', submit: true)
|
|
|
|
input_filtered_search('things', submit: true)
|
|
|
|
|
2017-10-19 18:36:47 +00:00
|
|
|
items = all('.filtered-search-history-dropdown-item', visible: false, count: 2)
|
2017-05-06 02:33:21 +00:00
|
|
|
|
|
|
|
expect(items[0].text).to eq('things')
|
|
|
|
expect(items[1].text).to eq('more')
|
|
|
|
end
|
|
|
|
|
2017-03-30 02:04:05 +00:00
|
|
|
it 'clicking item fills search input' do
|
2017-05-06 02:33:21 +00:00
|
|
|
set_recent_searches(project_1_local_storage_key, '["foo", "bar"]')
|
2017-06-29 17:06:35 +00:00
|
|
|
visit project_issues_path(project_1)
|
2017-03-30 02:04:05 +00:00
|
|
|
|
2017-11-03 16:25:28 +00:00
|
|
|
find('.filtered-search-history-dropdown-toggle-button').click
|
|
|
|
all('.filtered-search-history-dropdown-item', count: 2)[0].click
|
2017-03-30 02:04:05 +00:00
|
|
|
wait_for_filtered_search('foo')
|
|
|
|
|
|
|
|
expect(find('.filtered-search').value.strip).to eq('foo')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'clear recent searches button, clears recent searches' do
|
2017-05-06 02:33:21 +00:00
|
|
|
set_recent_searches(project_1_local_storage_key, '["foo"]')
|
2017-06-29 17:06:35 +00:00
|
|
|
visit project_issues_path(project_1)
|
2017-03-30 02:04:05 +00:00
|
|
|
|
2017-11-03 16:25:28 +00:00
|
|
|
find('.filtered-search-history-dropdown-toggle-button').click
|
|
|
|
all('.filtered-search-history-dropdown-item', count: 1)
|
2017-03-30 02:04:05 +00:00
|
|
|
|
2017-11-03 16:25:28 +00:00
|
|
|
find('.filtered-search-history-clear-button').click
|
|
|
|
items_after = all('.filtered-search-history-dropdown-item', count: 0)
|
2017-03-30 02:04:05 +00:00
|
|
|
|
|
|
|
expect(items_after.count).to eq(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows flash error when failed to parse saved history' do
|
2017-05-06 02:33:21 +00:00
|
|
|
set_recent_searches(project_1_local_storage_key, 'fail')
|
2017-06-29 17:06:35 +00:00
|
|
|
visit project_issues_path(project_1)
|
2017-03-30 02:04:05 +00:00
|
|
|
|
2017-09-25 20:02:08 +00:00
|
|
|
expect(find('.flash-alert')).to have_text('An error occurred while parsing recent searches')
|
2017-03-30 02:04:05 +00:00
|
|
|
end
|
|
|
|
end
|