Commit 51cddc96 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '27568-refactor-very-slow-dropdown-asignee-spec' into 'master'

Refactor dropdown_assignee_spec

Closes #27568

See merge request !9711
parents 668844f5 15a4cac9
---
title: Refactor dropdown_assignee_spec
merge_request: 9711
author: George Andrinopoulos
require 'rails_helper'
describe 'Dropdown assignee', js: true, feature: true do
include WaitForAjax
describe 'Dropdown assignee', :feature, :js do
let!(:project) { create(:empty_project) }
let!(:user) { create(:user, name: 'administrator', username: 'root') }
let!(:user_john) { create(:user, name: 'John', username: 'th0mas') }
let!(:user_jacob) { create(:user, name: 'Jacob', username: 'otter32') }
let(:filtered_search) { find('.filtered-search') }
let(:js_dropdown_assignee) { '#js-dropdown-assignee' }
def send_keys_to_filtered_search(input)
input.split("").each do |i|
filtered_search.send_keys(i)
sleep 5
wait_for_ajax
end
end
let(:filter_dropdown) { find("#{js_dropdown_assignee} .filter-dropdown") }
def dropdown_assignee_size
page.all('#js-dropdown-assignee .filter-dropdown .filter-dropdown-item').size
filter_dropdown.all('.filter-dropdown-item').size
end
def click_assignee(text)
......@@ -56,63 +47,80 @@ describe 'Dropdown assignee', js: true, feature: true do
end
it 'should hide loading indicator when loaded' do
send_keys_to_filtered_search('assignee:')
filtered_search.set('assignee:')
expect(page).not_to have_css('#js-dropdown-assignee .filter-dropdown-loading')
expect(find(js_dropdown_assignee)).to have_css('.filter-dropdown-loading')
expect(find(js_dropdown_assignee)).not_to have_css('.filter-dropdown-loading')
end
it 'should load all the assignees when opened' do
send_keys_to_filtered_search('assignee:')
filtered_search.set('assignee:')
expect(dropdown_assignee_size).to eq(3)
end
it 'shows current user at top of dropdown' do
send_keys_to_filtered_search('assignee:')
filtered_search.set('assignee:')
expect(first('#js-dropdown-assignee .filter-dropdown li')).to have_content(user.name)
expect(filter_dropdown.first('.filter-dropdown-item')).to have_content(user.name)
end
end
describe 'filtering' do
before do
send_keys_to_filtered_search('assignee:')
filtered_search.set('assignee:')
expect(find("#{js_dropdown_assignee} .filter-dropdown")).to have_content(user_john.name)
expect(find("#{js_dropdown_assignee} .filter-dropdown")).to have_content(user_jacob.name)
expect(find("#{js_dropdown_assignee} .filter-dropdown")).to have_content(user.name)
end
it 'filters by name' do
send_keys_to_filtered_search('j')
filtered_search.send_keys('j')
expect(dropdown_assignee_size).to eq(2)
expect(find("#{js_dropdown_assignee} .filter-dropdown")).to have_content(user_john.name)
expect(find("#{js_dropdown_assignee} .filter-dropdown")).to have_content(user_jacob.name)
expect(find("#{js_dropdown_assignee} .filter-dropdown")).to have_no_content(user.name)
end
it 'filters by case insensitive name' do
send_keys_to_filtered_search('J')
filtered_search.send_keys('J')
expect(dropdown_assignee_size).to eq(2)
expect(find("#{js_dropdown_assignee} .filter-dropdown")).to have_content(user_john.name)
expect(find("#{js_dropdown_assignee} .filter-dropdown")).to have_content(user_jacob.name)
expect(find("#{js_dropdown_assignee} .filter-dropdown")).to have_no_content(user.name)
end
it 'filters by username with symbol' do
send_keys_to_filtered_search('@ot')
filtered_search.send_keys('@ot')
expect(dropdown_assignee_size).to eq(2)
expect(find("#{js_dropdown_assignee} .filter-dropdown")).to have_content(user_jacob.name)
expect(find("#{js_dropdown_assignee} .filter-dropdown")).to have_content(user.name)
expect(find("#{js_dropdown_assignee} .filter-dropdown")).to have_no_content(user_john.name)
end
it 'filters by case insensitive username with symbol' do
send_keys_to_filtered_search('@OT')
filtered_search.send_keys('@OT')
expect(dropdown_assignee_size).to eq(2)
expect(find("#{js_dropdown_assignee} .filter-dropdown")).to have_content(user_jacob.name)
expect(find("#{js_dropdown_assignee} .filter-dropdown")).to have_content(user.name)
expect(find("#{js_dropdown_assignee} .filter-dropdown")).to have_no_content(user_john.name)
end
it 'filters by username without symbol' do
send_keys_to_filtered_search('ot')
filtered_search.send_keys('ot')
expect(dropdown_assignee_size).to eq(2)
expect(find("#{js_dropdown_assignee} .filter-dropdown")).to have_content(user_jacob.name)
expect(find("#{js_dropdown_assignee} .filter-dropdown")).to have_content(user.name)
expect(find("#{js_dropdown_assignee} .filter-dropdown")).to have_no_content(user_john.name)
end
it 'filters by case insensitive username without symbol' do
send_keys_to_filtered_search('OT')
filtered_search.send_keys('OT')
expect(dropdown_assignee_size).to eq(2)
expect(find("#{js_dropdown_assignee} .filter-dropdown")).to have_content(user_jacob.name)
expect(find("#{js_dropdown_assignee} .filter-dropdown")).to have_content(user.name)
expect(find("#{js_dropdown_assignee} .filter-dropdown")).to have_no_content(user_john.name)
end
end
......@@ -129,7 +137,7 @@ describe 'Dropdown assignee', js: true, feature: true do
end
it 'fills in the assignee username when the assignee has been filtered' do
send_keys_to_filtered_search('roo')
filtered_search.send_keys('roo')
click_assignee(user.name)
expect(page).to have_css(js_dropdown_assignee, visible: false)
......@@ -173,7 +181,7 @@ describe 'Dropdown assignee', js: true, feature: true do
describe 'caching requests' do
it 'caches requests after the first load' do
filtered_search.set('assignee')
send_keys_to_filtered_search(':')
filtered_search.send_keys(':')
initial_size = dropdown_assignee_size
expect(initial_size).to be > 0
......@@ -182,7 +190,7 @@ describe 'Dropdown assignee', js: true, feature: true do
project.team << [new_user, :master]
find('.filtered-search-input-container .clear-search').click
filtered_search.set('assignee')
send_keys_to_filtered_search(':')
filtered_search.send_keys(':')
expect(dropdown_assignee_size).to eq(initial_size)
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment