2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
module FilteredSearchHelpers
|
|
|
|
def filtered_search
|
|
|
|
page.find('.filtered-search')
|
|
|
|
end
|
|
|
|
|
|
|
|
# Enables input to be set (similar to copy and paste)
|
|
|
|
def input_filtered_search(search_term, submit: true, extra_space: true)
|
|
|
|
search = search_term
|
|
|
|
if extra_space
|
|
|
|
# Add an extra space to engage visual tokens
|
|
|
|
search = "#{search_term} "
|
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
filtered_search.set(search, rapid: false)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
if submit
|
2017-09-10 17:25:29 +05:30
|
|
|
# Wait for the lazy author/assignee tokens that
|
|
|
|
# swap out the username with an avatar and name
|
|
|
|
wait_for_requests
|
2017-08-17 22:00:37 +05:30
|
|
|
filtered_search.send_keys(:enter)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
# Select a label clicking in the search dropdown instead
|
|
|
|
# of entering label names on the input.
|
|
|
|
def select_label_on_dropdown(label_title)
|
2020-04-08 14:13:33 +05:30
|
|
|
input_filtered_search("label:=", submit: false)
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
within('#js-dropdown-label') do
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
find('li', text: label_title).click
|
|
|
|
end
|
|
|
|
|
|
|
|
filtered_search.send_keys(:enter)
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
def expect_filtered_search_dropdown_results(filter_dropdown, count)
|
|
|
|
expect(filter_dropdown).to have_selector('.filter-dropdown .filter-dropdown-item', count: count)
|
|
|
|
end
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
def expect_issues_list_count(open_count, closed_count = 0)
|
|
|
|
all_count = open_count + closed_count
|
|
|
|
|
|
|
|
expect(page).to have_issuable_counts(open: open_count, closed: closed_count, all: all_count)
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
expect(page).to have_selector('.issue', count: open_count)
|
2018-05-09 12:01:36 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
# Enables input to be added character by character
|
|
|
|
def input_filtered_search_keys(search_term)
|
|
|
|
# Add an extra space to engage visual tokens
|
|
|
|
filtered_search.send_keys("#{search_term} ")
|
|
|
|
filtered_search.send_keys(:enter)
|
|
|
|
end
|
|
|
|
|
|
|
|
def expect_filtered_search_input(input)
|
|
|
|
expect(find('.filtered-search').value).to eq(input)
|
|
|
|
end
|
|
|
|
|
|
|
|
def clear_search_field
|
|
|
|
find('.filtered-search-box .clear-search').click
|
|
|
|
end
|
|
|
|
|
|
|
|
def reset_filters
|
|
|
|
clear_search_field
|
|
|
|
filtered_search.send_keys(:enter)
|
|
|
|
end
|
|
|
|
|
|
|
|
def init_label_search
|
2020-04-08 14:13:33 +05:30
|
|
|
filtered_search.set('label:=')
|
2017-08-17 22:00:37 +05:30
|
|
|
# This ensures the dropdown is shown
|
|
|
|
expect(find('#js-dropdown-label')).not_to have_css('.filter-dropdown-loading')
|
|
|
|
end
|
|
|
|
|
|
|
|
def expect_filtered_search_input_empty
|
|
|
|
expect(find('.filtered-search').value).to eq('')
|
|
|
|
end
|
|
|
|
|
|
|
|
# Iterates through each visual token inside
|
|
|
|
# .tokens-container to make sure the correct names and values are rendered
|
|
|
|
def expect_tokens(tokens)
|
2018-03-17 18:26:18 +05:30
|
|
|
page.within '.filtered-search-box .tokens-container' do
|
2019-07-31 22:56:46 +05:30
|
|
|
token_elements = page.all(:css, 'li.filtered-search-token')
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
tokens.each_with_index do |token, index|
|
|
|
|
el = token_elements[index]
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
expect(el.find('.name')).to have_content(token[:name])
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(el.find('.operator')).to have_content(token[:operator]) if token[:operator].present?
|
2019-07-31 22:56:46 +05:30
|
|
|
expect(el.find('.value')).to have_content(token[:value]) if token[:value].present?
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
# gl-emoji content is blank when the emoji unicode is not supported
|
2019-07-31 22:56:46 +05:30
|
|
|
if token[:emoji_name].present?
|
|
|
|
selector = %(gl-emoji[data-name="#{token[:emoji_name]}"])
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(el.find('.value')).to have_css(selector)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
def create_token(token_name, token_value = nil, symbol = nil, token_operator = '=')
|
|
|
|
{ name: token_name, operator: token_operator, value: "#{symbol}#{token_value}" }
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def author_token(author_name = nil)
|
|
|
|
create_token('Author', author_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def assignee_token(assignee_name = nil)
|
|
|
|
create_token('Assignee', assignee_name)
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
def milestone_token(milestone_name = nil, has_symbol = true, operator = '=')
|
2018-03-17 18:26:18 +05:30
|
|
|
symbol = has_symbol ? '%' : nil
|
2020-03-13 15:44:24 +05:30
|
|
|
create_token('Milestone', milestone_name, symbol, operator)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
def release_token(release_tag = nil)
|
|
|
|
create_token('Release', release_tag)
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def label_token(label_name = nil, has_symbol = true)
|
|
|
|
symbol = has_symbol ? '~' : nil
|
|
|
|
create_token('Label', label_name, symbol)
|
|
|
|
end
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
def reaction_token(reaction_name = nil, is_emoji = true)
|
|
|
|
if is_emoji
|
|
|
|
{ name: 'My-Reaction', emoji_name: reaction_name }
|
|
|
|
else
|
|
|
|
create_token('My-Reaction', reaction_name)
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def default_placeholder
|
|
|
|
'Search or filter results...'
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_filtered_search_placeholder
|
|
|
|
find('.filtered-search')['placeholder']
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_recent_searches
|
2017-09-10 17:25:29 +05:30
|
|
|
execute_script('window.localStorage.clear();')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def set_recent_searches(key, input)
|
|
|
|
execute_script("window.localStorage.setItem('#{key}', '#{input}');")
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def wait_for_filtered_search(text)
|
|
|
|
Timeout.timeout(Capybara.default_max_wait_time) do
|
|
|
|
loop until find('.filtered-search').value.strip == text
|
|
|
|
end
|
|
|
|
end
|
2019-07-31 22:56:46 +05:30
|
|
|
|
|
|
|
def close_dropdown_menu_if_visible
|
|
|
|
find('.dropdown-menu-toggle', visible: :all).tap do |toggle|
|
|
|
|
toggle.click if toggle.visible?
|
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|