Commit 15a4cac9 authored by George Andrinopoulos's avatar George Andrinopoulos Committed by Rémy Coutable

Refactor dropdown_assignee_spec

parent 668844f5
---
title: Refactor dropdown_assignee_spec
merge_request: 9711
author: George Andrinopoulos
require 'rails_helper' require 'rails_helper'
describe 'Dropdown assignee', js: true, feature: true do describe 'Dropdown assignee', :feature, :js do
include WaitForAjax
let!(:project) { create(:empty_project) } let!(:project) { create(:empty_project) }
let!(:user) { create(:user, name: 'administrator', username: 'root') } let!(:user) { create(:user, name: 'administrator', username: 'root') }
let!(:user_john) { create(:user, name: 'John', username: 'th0mas') } let!(:user_john) { create(:user, name: 'John', username: 'th0mas') }
let!(:user_jacob) { create(:user, name: 'Jacob', username: 'otter32') } let!(:user_jacob) { create(:user, name: 'Jacob', username: 'otter32') }
let(:filtered_search) { find('.filtered-search') } let(:filtered_search) { find('.filtered-search') }
let(:js_dropdown_assignee) { '#js-dropdown-assignee' } let(:js_dropdown_assignee) { '#js-dropdown-assignee' }
let(:filter_dropdown) { find("#{js_dropdown_assignee} .filter-dropdown") }
def send_keys_to_filtered_search(input)
input.split("").each do |i|
filtered_search.send_keys(i)
sleep 5
wait_for_ajax
end
end
def dropdown_assignee_size def dropdown_assignee_size
page.all('#js-dropdown-assignee .filter-dropdown .filter-dropdown-item').size filter_dropdown.all('.filter-dropdown-item').size
end end
def click_assignee(text) def click_assignee(text)
...@@ -56,63 +47,80 @@ describe 'Dropdown assignee', js: true, feature: true do ...@@ -56,63 +47,80 @@ describe 'Dropdown assignee', js: true, feature: true do
end end
it 'should hide loading indicator when loaded' do 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 end
it 'should load all the assignees when opened' do 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) expect(dropdown_assignee_size).to eq(3)
end end
it 'shows current user at top of dropdown' do 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
end end
describe 'filtering' do describe 'filtering' do
before 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 end
it 'filters by name' do 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 end
it 'filters by case insensitive name' do 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 end
it 'filters by username with symbol' do 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 end
it 'filters by case insensitive username with symbol' do 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 end
it 'filters by username without symbol' do 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 end
it 'filters by case insensitive username without symbol' do 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
end end
...@@ -129,7 +137,7 @@ describe 'Dropdown assignee', js: true, feature: true do ...@@ -129,7 +137,7 @@ describe 'Dropdown assignee', js: true, feature: true do
end end
it 'fills in the assignee username when the assignee has been filtered' do 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) click_assignee(user.name)
expect(page).to have_css(js_dropdown_assignee, visible: false) expect(page).to have_css(js_dropdown_assignee, visible: false)
...@@ -173,7 +181,7 @@ describe 'Dropdown assignee', js: true, feature: true do ...@@ -173,7 +181,7 @@ describe 'Dropdown assignee', js: true, feature: true do
describe 'caching requests' do describe 'caching requests' do
it 'caches requests after the first load' do it 'caches requests after the first load' do
filtered_search.set('assignee') filtered_search.set('assignee')
send_keys_to_filtered_search(':') filtered_search.send_keys(':')
initial_size = dropdown_assignee_size initial_size = dropdown_assignee_size
expect(initial_size).to be > 0 expect(initial_size).to be > 0
...@@ -182,7 +190,7 @@ describe 'Dropdown assignee', js: true, feature: true do ...@@ -182,7 +190,7 @@ describe 'Dropdown assignee', js: true, feature: true do
project.team << [new_user, :master] project.team << [new_user, :master]
find('.filtered-search-input-container .clear-search').click find('.filtered-search-input-container .clear-search').click
filtered_search.set('assignee') filtered_search.set('assignee')
send_keys_to_filtered_search(':') filtered_search.send_keys(':')
expect(dropdown_assignee_size).to eq(initial_size) expect(dropdown_assignee_size).to eq(initial_size)
end 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