2017-02-01 16:53:41 +00:00
require 'spec_helper'
2016-12-16 22:25:52 +00:00
2017-06-29 04:13:10 +00:00
describe 'Dropdown label' , js : true do
2017-02-15 22:13:53 +00:00
include FilteredSearchHelpers
2017-08-02 19:55:11 +00:00
let ( :project ) { create ( :project ) }
2017-02-01 16:53:41 +00:00
let ( :user ) { create ( :user ) }
2016-12-16 22:25:52 +00:00
let ( :filtered_search ) { find ( '.filtered-search' ) }
let ( :js_dropdown_label ) { '#js-dropdown-label' }
2017-02-01 16:53:41 +00:00
let ( :filter_dropdown ) { find ( " #{ js_dropdown_label } .filter-dropdown " ) }
shared_context 'with labels' do
let! ( :bug_label ) { create ( :label , project : project , title : 'bug-label' ) }
let! ( :uppercase_label ) { create ( :label , project : project , title : 'BUG-LABEL' ) }
let! ( :two_words_label ) { create ( :label , project : project , title : 'High Priority' ) }
let! ( :wont_fix_label ) { create ( :label , project : project , title : 'Won"t Fix' ) }
let! ( :wont_fix_single_label ) { create ( :label , project : project , title : 'Won\'t Fix' ) }
let! ( :special_label ) { create ( :label , project : project , title : '!@#$%^+&*()' ) }
let! ( :long_label ) { create ( :label , project : project , title : 'this is a very long title this is a very long title this is a very long title this is a very long title this is a very long title' ) }
end
2016-12-16 22:25:52 +00:00
2017-02-01 16:53:41 +00:00
def search_for_label ( label )
init_label_search
filtered_search . send_keys ( label )
2016-12-16 22:25:52 +00:00
end
def click_label ( text )
2017-02-01 16:53:41 +00:00
filter_dropdown . find ( '.filter-dropdown-item' , text : text ) . click
end
def clear_search_field
2017-03-30 02:04:05 +00:00
find ( '.filtered-search-box .clear-search' ) . click
2016-12-16 22:25:52 +00:00
end
before do
2017-02-01 16:53:41 +00:00
project . add_master ( user )
2017-06-21 23:44:10 +00:00
sign_in ( user )
2016-12-16 22:25:52 +00:00
create ( :issue , project : project )
2017-07-06 16:20:50 +00:00
visit project_issues_path ( project )
2016-12-16 22:25:52 +00:00
end
2017-01-20 17:57:31 +00:00
describe 'keyboard navigation' do
it 'selects label' do
2017-02-01 16:53:41 +00:00
bug_label = create ( :label , project : project , title : 'bug-label' )
init_label_search
2017-01-20 17:57:31 +00:00
filtered_search . native . send_keys ( :down , :down , :enter )
2017-08-16 12:11:35 +00:00
expect_tokens ( [ label_token ( bug_label . title ) ] )
2017-01-30 22:53:18 +00:00
expect_filtered_search_input_empty
2017-01-20 17:57:31 +00:00
end
end
2016-12-16 22:25:52 +00:00
describe 'behavior' do
it 'opens when the search bar has label:' do
filtered_search . set ( 'label:' )
2017-01-12 01:47:42 +00:00
2017-02-01 16:53:41 +00:00
expect ( page ) . to have_css ( js_dropdown_label )
2016-12-16 22:25:52 +00:00
end
it 'closes when the search bar is unfocused' do
2017-02-01 16:53:41 +00:00
find ( 'body' ) . click
2017-01-12 01:47:42 +00:00
2017-02-01 16:53:41 +00:00
expect ( page ) . not_to have_css ( js_dropdown_label )
2016-12-16 22:25:52 +00:00
end
2017-02-01 16:53:41 +00:00
it 'shows loading indicator when opened and hides it when loaded' do
2016-12-16 22:25:52 +00:00
filtered_search . set ( 'label:' )
2017-01-12 01:47:42 +00:00
2017-02-01 16:53:41 +00:00
expect ( find ( js_dropdown_label ) ) . to have_css ( '.filter-dropdown-loading' )
expect ( find ( js_dropdown_label ) ) . not_to have_css ( '.filter-dropdown-loading' )
2016-12-16 22:25:52 +00:00
end
2017-02-01 16:53:41 +00:00
it 'loads all the labels when opened' do
bug_label = create ( :label , project : project , title : 'bug-label' )
filtered_search . set ( 'label:' )
2017-01-12 01:47:42 +00:00
2017-02-01 16:53:41 +00:00
expect ( filter_dropdown ) . to have_content ( bug_label . title )
2017-04-07 13:57:03 +00:00
expect ( filter_dropdown ) . to have_selector ( '.filter-dropdown-item' , count : 1 )
2016-12-16 22:25:52 +00:00
end
end
describe 'filtering' do
2017-02-01 16:53:41 +00:00
include_context 'with labels'
2017-01-12 01:47:42 +00:00
2017-02-01 16:53:41 +00:00
before do
init_label_search
2016-12-16 22:25:52 +00:00
end
2017-02-01 16:53:41 +00:00
it 'filters by case-insensitive name with or without symbol' do
2017-01-30 22:53:18 +00:00
filtered_search . send_keys ( 'b' )
2017-01-12 01:47:42 +00:00
2017-02-01 16:53:41 +00:00
expect ( filter_dropdown . find ( '.filter-dropdown-item' , text : bug_label . title ) ) . to be_visible
expect ( filter_dropdown . find ( '.filter-dropdown-item' , text : uppercase_label . title ) ) . to be_visible
2017-04-07 13:57:03 +00:00
expect ( filter_dropdown ) . to have_selector ( '.filter-dropdown-item' , count : 2 )
2016-12-16 22:25:52 +00:00
2017-02-01 16:53:41 +00:00
clear_search_field
init_label_search
2017-01-12 01:47:42 +00:00
2017-01-30 22:53:18 +00:00
filtered_search . send_keys ( '~bu' )
2017-01-12 01:47:42 +00:00
2017-02-01 16:53:41 +00:00
expect ( filter_dropdown . find ( '.filter-dropdown-item' , text : bug_label . title ) ) . to be_visible
expect ( filter_dropdown . find ( '.filter-dropdown-item' , text : uppercase_label . title ) ) . to be_visible
2017-04-07 13:57:03 +00:00
expect ( filter_dropdown ) . to have_selector ( '.filter-dropdown-item' , count : 2 )
2016-12-16 22:25:52 +00:00
end
2017-02-01 16:53:41 +00:00
it 'filters by multiple words with or without symbol' do
filtered_search . send_keys ( 'Hig' )
2017-01-12 01:47:42 +00:00
2017-02-01 16:53:41 +00:00
expect ( filter_dropdown . find ( '.filter-dropdown-item' , text : two_words_label . title ) ) . to be_visible
2017-04-07 13:57:03 +00:00
expect ( filter_dropdown ) . to have_selector ( '.filter-dropdown-item' , count : 1 )
2016-12-18 23:04:29 +00:00
2017-02-01 16:53:41 +00:00
clear_search_field
init_label_search
filtered_search . send_keys ( '~Hig' )
2017-01-12 01:47:42 +00:00
2017-02-01 16:53:41 +00:00
expect ( filter_dropdown . find ( '.filter-dropdown-item' , text : two_words_label . title ) ) . to be_visible
2017-04-07 13:57:03 +00:00
expect ( filter_dropdown ) . to have_selector ( '.filter-dropdown-item' , count : 1 )
2016-12-16 22:25:52 +00:00
end
2017-02-01 16:53:41 +00:00
it 'filters by multiple words containing single quotes with or without symbol' do
filtered_search . send_keys ( 'won\'t' )
2017-01-12 01:47:42 +00:00
2017-02-01 16:53:41 +00:00
expect ( filter_dropdown . find ( '.filter-dropdown-item' , text : wont_fix_single_label . title ) ) . to be_visible
2017-04-07 13:57:03 +00:00
expect ( filter_dropdown ) . to have_selector ( '.filter-dropdown-item' , count : 1 )
2016-12-16 22:25:52 +00:00
2017-02-01 16:53:41 +00:00
clear_search_field
init_label_search
filtered_search . send_keys ( '~won\'t' )
2017-01-12 01:47:42 +00:00
2017-02-01 16:53:41 +00:00
expect ( filter_dropdown . find ( '.filter-dropdown-item' , text : wont_fix_single_label . title ) ) . to be_visible
2017-04-07 13:57:03 +00:00
expect ( filter_dropdown ) . to have_selector ( '.filter-dropdown-item' , count : 1 )
2016-12-16 22:25:52 +00:00
end
2017-02-01 16:53:41 +00:00
it 'filters by multiple words containing double quotes with or without symbol' do
filtered_search . send_keys ( 'won"t' )
2017-01-12 01:47:42 +00:00
2017-02-01 16:53:41 +00:00
expect ( filter_dropdown . find ( '.filter-dropdown-item' , text : wont_fix_label . title ) ) . to be_visible
2017-04-07 13:57:03 +00:00
expect ( filter_dropdown ) . to have_selector ( '.filter-dropdown-item' , count : 1 )
2016-12-16 22:25:52 +00:00
2017-02-01 16:53:41 +00:00
clear_search_field
init_label_search
2017-01-12 01:47:42 +00:00
2017-02-01 16:53:41 +00:00
filtered_search . send_keys ( '~won"t' )
expect ( filter_dropdown . find ( '.filter-dropdown-item' , text : wont_fix_label . title ) ) . to be_visible
2017-04-07 13:57:03 +00:00
expect ( filter_dropdown ) . to have_selector ( '.filter-dropdown-item' , count : 1 )
2016-12-16 22:25:52 +00:00
end
2017-02-01 16:53:41 +00:00
it 'filters by special characters with or without symbol' do
filtered_search . send_keys ( '^+' )
2017-01-12 01:47:42 +00:00
2017-02-01 16:53:41 +00:00
expect ( filter_dropdown . find ( '.filter-dropdown-item' , text : special_label . title ) ) . to be_visible
2017-04-07 13:57:03 +00:00
expect ( filter_dropdown ) . to have_selector ( '.filter-dropdown-item' , count : 1 )
2016-12-16 22:25:52 +00:00
2017-02-01 16:53:41 +00:00
clear_search_field
init_label_search
2017-01-12 01:47:42 +00:00
2017-02-01 16:53:41 +00:00
filtered_search . send_keys ( '~^+' )
expect ( filter_dropdown . find ( '.filter-dropdown-item' , text : special_label . title ) ) . to be_visible
2017-04-07 13:57:03 +00:00
expect ( filter_dropdown ) . to have_selector ( '.filter-dropdown-item' , count : 1 )
2016-12-16 22:25:52 +00:00
end
end
describe 'selecting from dropdown' do
2017-02-01 16:53:41 +00:00
include_context 'with labels'
2016-12-16 22:25:52 +00:00
before do
2017-02-01 16:53:41 +00:00
init_label_search
2016-12-16 22:25:52 +00:00
end
it 'fills in the label name when the label has not been filled' do
click_label ( bug_label . title )
2017-01-12 01:47:42 +00:00
2017-02-01 16:53:41 +00:00
expect ( page ) . not_to have_css ( js_dropdown_label )
2017-08-16 12:11:35 +00:00
expect_tokens ( [ label_token ( bug_label . title ) ] )
2017-01-30 22:53:18 +00:00
expect_filtered_search_input_empty
2016-12-16 22:25:52 +00:00
end
it 'fills in the label name when the label is partially filled' do
2017-02-01 16:53:41 +00:00
filtered_search . send_keys ( 'bu' )
2016-12-16 22:25:52 +00:00
click_label ( bug_label . title )
2017-01-12 01:47:42 +00:00
2017-02-01 16:53:41 +00:00
expect ( page ) . not_to have_css ( js_dropdown_label )
2017-08-16 12:11:35 +00:00
expect_tokens ( [ label_token ( bug_label . title ) ] )
2017-01-30 22:53:18 +00:00
expect_filtered_search_input_empty
2016-12-16 22:25:52 +00:00
end
it 'fills in the label name that contains multiple words' do
click_label ( two_words_label . title )
2017-01-12 01:47:42 +00:00
2017-02-01 16:53:41 +00:00
expect ( page ) . not_to have_css ( js_dropdown_label )
2017-08-16 12:11:35 +00:00
expect_tokens ( [ label_token ( " \" #{ two_words_label . title } \" " ) ] )
2017-01-30 22:53:18 +00:00
expect_filtered_search_input_empty
2016-12-16 22:25:52 +00:00
end
it 'fills in the label name that contains multiple words and is very long' do
click_label ( long_label . title )
2017-01-12 01:47:42 +00:00
2017-02-01 16:53:41 +00:00
expect ( page ) . not_to have_css ( js_dropdown_label )
2017-08-16 12:11:35 +00:00
expect_tokens ( [ label_token ( " \" #{ long_label . title } \" " ) ] )
2017-01-30 22:53:18 +00:00
expect_filtered_search_input_empty
2016-12-16 22:25:52 +00:00
end
it 'fills in the label name that contains double quotes' do
click_label ( wont_fix_label . title )
2017-01-12 01:47:42 +00:00
2017-02-01 16:53:41 +00:00
expect ( page ) . not_to have_css ( js_dropdown_label )
2017-08-16 12:11:35 +00:00
expect_tokens ( [ label_token ( " ' #{ wont_fix_label . title } ' " ) ] )
2017-01-30 22:53:18 +00:00
expect_filtered_search_input_empty
2016-12-16 22:25:52 +00:00
end
it 'fills in the label name with the correct capitalization' do
click_label ( uppercase_label . title )
2017-01-12 01:47:42 +00:00
2017-02-01 16:53:41 +00:00
expect ( page ) . not_to have_css ( js_dropdown_label )
2017-08-16 12:11:35 +00:00
expect_tokens ( [ label_token ( uppercase_label . title ) ] )
2017-01-30 22:53:18 +00:00
expect_filtered_search_input_empty
2016-12-16 22:25:52 +00:00
end
it 'fills in the label name with special characters' do
click_label ( special_label . title )
2017-01-12 01:47:42 +00:00
2017-02-01 16:53:41 +00:00
expect ( page ) . not_to have_css ( js_dropdown_label )
2017-08-16 12:11:35 +00:00
expect_tokens ( [ label_token ( special_label . title ) ] )
2017-01-30 22:53:18 +00:00
expect_filtered_search_input_empty
2016-12-16 22:25:52 +00:00
end
it 'selects `no label`' do
2017-02-01 16:53:41 +00:00
find ( " #{ js_dropdown_label } .filter-dropdown-item " , text : 'No Label' ) . click
2017-01-12 01:47:42 +00:00
2017-02-01 16:53:41 +00:00
expect ( page ) . not_to have_css ( js_dropdown_label )
2017-08-16 12:11:35 +00:00
expect_tokens ( [ label_token ( 'none' , false ) ] )
2017-01-30 22:53:18 +00:00
expect_filtered_search_input_empty
2016-12-16 22:25:52 +00:00
end
end
describe 'input has existing content' do
it 'opens label dropdown with existing search term' do
filtered_search . set ( 'searchTerm label:' )
2017-02-01 16:53:41 +00:00
expect ( page ) . to have_css ( js_dropdown_label )
2016-12-16 22:25:52 +00:00
end
it 'opens label dropdown with existing author' do
filtered_search . set ( 'author:@person label:' )
2017-02-01 16:53:41 +00:00
expect ( page ) . to have_css ( js_dropdown_label )
2016-12-16 22:25:52 +00:00
end
it 'opens label dropdown with existing assignee' do
filtered_search . set ( 'assignee:@person label:' )
2017-02-01 16:53:41 +00:00
expect ( page ) . to have_css ( js_dropdown_label )
2016-12-16 22:25:52 +00:00
end
it 'opens label dropdown with existing label' do
filtered_search . set ( 'label:~urgent label:' )
2017-02-01 16:53:41 +00:00
expect ( page ) . to have_css ( js_dropdown_label )
2016-12-16 22:25:52 +00:00
end
it 'opens label dropdown with existing milestone' do
filtered_search . set ( 'milestone:%v2.0 label:' )
2017-02-01 16:53:41 +00:00
expect ( page ) . to have_css ( js_dropdown_label )
2016-12-16 22:25:52 +00:00
end
end
2017-01-23 19:12:02 +00:00
describe 'caching requests' do
it 'caches requests after the first load' do
2017-02-01 16:53:41 +00:00
create ( :label , project : project , title : 'bug-label' )
init_label_search
2017-01-23 19:12:02 +00:00
2017-04-07 13:57:03 +00:00
expect ( filter_dropdown ) . to have_selector ( '.filter-dropdown-item' , count : 1 )
2017-01-23 19:12:02 +00:00
create ( :label , project : project )
2017-02-01 16:53:41 +00:00
clear_search_field
init_label_search
2017-01-23 19:12:02 +00:00
2017-04-07 13:57:03 +00:00
expect ( filter_dropdown ) . to have_selector ( '.filter-dropdown-item' , count : 1 )
2017-01-23 19:12:02 +00:00
end
end
2016-12-16 22:25:52 +00:00
end