2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
require 'spec_helper'
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe 'Dropdown author', :js do
|
2017-08-17 22:00:37 +05:30
|
|
|
include FilteredSearchHelpers
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
let!(:project) { create(:project) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let!(:user) { create(:user, name: 'administrator', username: 'root') }
|
|
|
|
let!(:user_john) { create(:user, name: 'John', username: 'th0mas') }
|
2018-03-17 18:26:18 +05:30
|
|
|
let!(:user_jacob) { create(:user, name: 'Jacob', username: 'ooter32') }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:filtered_search) { find('.filtered-search') }
|
|
|
|
let(:js_dropdown_author) { '#js-dropdown-author' }
|
|
|
|
|
|
|
|
def send_keys_to_filtered_search(input)
|
|
|
|
input.split("").each do |i|
|
|
|
|
filtered_search.send_keys(i)
|
|
|
|
end
|
|
|
|
|
|
|
|
sleep 0.5
|
2017-09-10 17:25:29 +05:30
|
|
|
wait_for_requests
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def dropdown_author_size
|
|
|
|
page.all('#js-dropdown-author .filter-dropdown .filter-dropdown-item').size
|
|
|
|
end
|
|
|
|
|
|
|
|
def click_author(text)
|
|
|
|
find('#js-dropdown-author .filter-dropdown .filter-dropdown-item', text: text).click
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2018-11-18 11:00:15 +05:30
|
|
|
project.add_maintainer(user)
|
|
|
|
project.add_maintainer(user_john)
|
|
|
|
project.add_maintainer(user_jacob)
|
2017-09-10 17:25:29 +05:30
|
|
|
sign_in(user)
|
2017-08-17 22:00:37 +05:30
|
|
|
create(:issue, project: project)
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
visit project_issues_path(project)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'behavior' do
|
|
|
|
it 'opens when the search bar has author:' do
|
|
|
|
filtered_search.set('author:')
|
|
|
|
|
|
|
|
expect(page).to have_css(js_dropdown_author, visible: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'closes when the search bar is unfocused' do
|
2019-03-02 22:35:43 +05:30
|
|
|
find('body').click
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(page).to have_css(js_dropdown_author, visible: false)
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
it 'shows loading indicator when opened' do
|
2018-03-17 18:26:18 +05:30
|
|
|
slow_requests do
|
|
|
|
filtered_search.set('author:')
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(page).to have_css('#js-dropdown-author .filter-dropdown-loading', visible: true)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
it 'hides loading indicator when loaded' do
|
2017-08-17 22:00:37 +05:30
|
|
|
send_keys_to_filtered_search('author:')
|
|
|
|
|
|
|
|
expect(page).not_to have_css('#js-dropdown-author .filter-dropdown-loading')
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
it 'loads all the authors when opened' do
|
2017-08-17 22:00:37 +05:30
|
|
|
send_keys_to_filtered_search('author:')
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(dropdown_author_size).to eq(4)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows current user at top of dropdown' do
|
|
|
|
send_keys_to_filtered_search('author:')
|
|
|
|
|
|
|
|
expect(first('#js-dropdown-author li')).to have_content(user.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'filtering' do
|
|
|
|
before do
|
|
|
|
filtered_search.set('author')
|
|
|
|
send_keys_to_filtered_search(':')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters by name' do
|
2018-03-17 18:26:18 +05:30
|
|
|
send_keys_to_filtered_search('jac')
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(dropdown_author_size).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters by case insensitive name' do
|
2018-03-17 18:26:18 +05:30
|
|
|
send_keys_to_filtered_search('Jac')
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(dropdown_author_size).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters by username with symbol' do
|
2018-03-17 18:26:18 +05:30
|
|
|
send_keys_to_filtered_search('@oot')
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(dropdown_author_size).to eq(2)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters by username without symbol' do
|
2018-03-17 18:26:18 +05:30
|
|
|
send_keys_to_filtered_search('oot')
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(dropdown_author_size).to eq(2)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters by case insensitive username without symbol' do
|
2018-03-17 18:26:18 +05:30
|
|
|
send_keys_to_filtered_search('OOT')
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(dropdown_author_size).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'selecting from dropdown' do
|
|
|
|
before do
|
|
|
|
filtered_search.set('author')
|
|
|
|
send_keys_to_filtered_search(':')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'fills in the author username when the author has not been filtered' do
|
|
|
|
click_author(user_jacob.name)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
wait_for_requests
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(page).to have_css(js_dropdown_author, visible: false)
|
2018-03-17 18:26:18 +05:30
|
|
|
expect_tokens([author_token(user_jacob.name)])
|
2017-08-17 22:00:37 +05:30
|
|
|
expect_filtered_search_input_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'fills in the author username when the author has been filtered' do
|
|
|
|
click_author(user.name)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
wait_for_requests
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(page).to have_css(js_dropdown_author, visible: false)
|
2018-03-17 18:26:18 +05:30
|
|
|
expect_tokens([author_token(user.name)])
|
2017-08-17 22:00:37 +05:30
|
|
|
expect_filtered_search_input_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe 'selecting from dropdown without Ajax call' do
|
|
|
|
before do
|
|
|
|
Gitlab::Testing::RequestBlockerMiddleware.block_requests!
|
|
|
|
filtered_search.set('author:')
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
Gitlab::Testing::RequestBlockerMiddleware.allow_requests!
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'selects current user' do
|
|
|
|
find('#js-dropdown-author .filter-dropdown-item', text: user.username).click
|
|
|
|
|
|
|
|
expect(page).to have_css(js_dropdown_author, visible: false)
|
2018-03-17 18:26:18 +05:30
|
|
|
expect_tokens([author_token(user.username)])
|
2017-09-10 17:25:29 +05:30
|
|
|
expect_filtered_search_input_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe 'input has existing content' do
|
|
|
|
it 'opens author dropdown with existing search term' do
|
|
|
|
filtered_search.set('searchTerm author:')
|
|
|
|
|
|
|
|
expect(page).to have_css(js_dropdown_author, visible: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'opens author dropdown with existing assignee' do
|
|
|
|
filtered_search.set('assignee:@user author:')
|
|
|
|
|
|
|
|
expect(page).to have_css(js_dropdown_author, visible: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'opens author dropdown with existing label' do
|
|
|
|
filtered_search.set('label:~bug author:')
|
|
|
|
|
|
|
|
expect(page).to have_css(js_dropdown_author, visible: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'opens author dropdown with existing milestone' do
|
|
|
|
filtered_search.set('milestone:%v1.0 author:')
|
|
|
|
|
|
|
|
expect(page).to have_css(js_dropdown_author, visible: true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'caching requests' do
|
|
|
|
it 'caches requests after the first load' do
|
|
|
|
filtered_search.set('author')
|
|
|
|
send_keys_to_filtered_search(':')
|
|
|
|
initial_size = dropdown_author_size
|
|
|
|
|
|
|
|
expect(initial_size).to be > 0
|
|
|
|
|
|
|
|
new_user = create(:user)
|
2018-11-18 11:00:15 +05:30
|
|
|
project.add_maintainer(new_user)
|
2017-08-17 22:00:37 +05:30
|
|
|
find('.filtered-search-box .clear-search').click
|
|
|
|
filtered_search.set('author')
|
|
|
|
send_keys_to_filtered_search(':')
|
|
|
|
|
|
|
|
expect(dropdown_author_size).to eq(initial_size)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|