From 625ecdbcc848f05eafaf167255901efd2d32cb37 Mon Sep 17 00:00:00 2001 From: Clement Ho Date: Fri, 16 Dec 2016 01:05:27 -0600 Subject: Create dropdown hint spec --- spec/features/issues/filter_issues_spec.rb | 682 --------------------- .../issues/filtered_search/dropdown_hint_spec.rb | 113 ++++ .../issues/filtered_search/filter_issues_spec.rb | 682 +++++++++++++++++++++ .../issues/filtered_search/search_bar_spec.rb | 86 +++ spec/features/issues/search_bar_spec.rb | 53 -- 5 files changed, 881 insertions(+), 735 deletions(-) delete mode 100644 spec/features/issues/filter_issues_spec.rb create mode 100644 spec/features/issues/filtered_search/dropdown_hint_spec.rb create mode 100644 spec/features/issues/filtered_search/filter_issues_spec.rb create mode 100644 spec/features/issues/filtered_search/search_bar_spec.rb delete mode 100644 spec/features/issues/search_bar_spec.rb diff --git a/spec/features/issues/filter_issues_spec.rb b/spec/features/issues/filter_issues_spec.rb deleted file mode 100644 index 0b94bcc4e3f..00000000000 --- a/spec/features/issues/filter_issues_spec.rb +++ /dev/null @@ -1,682 +0,0 @@ -require 'rails_helper' - -describe 'Filter issues', feature: true do - include WaitForAjax - - let!(:group) { create(:group) } - let!(:project) { create(:project, group: group) } - let!(:user) { create(:user) } - let!(:user2) { create(:user) } - let!(:milestone) { create(:milestone, project: project) } - let!(:label) { create(:label, project: project) } - let!(:wontfix) { create(:label, project: project, title: "Won't fix") } - - let!(:bug_label) { create(:label, project: project, title: 'bug') } - let!(:caps_sensitive_label) { create(:label, project: project, title: 'CAPS_sensitive') } - let!(:milestone) { create(:milestone, title: "8", project: project) } - let!(:multiple_words_label) { create(:label, project: project, title: "Two words") } - - let!(:closed_issue) { create(:issue, title: 'bug that is closed', project: project, state: :closed) } - - def input_filtered_search(search_term) - filtered_search = find('.filtered-search') - filtered_search.set(search_term) - filtered_search.send_keys(:enter) - end - - def expect_filtered_search_input(input) - expect(find('.filtered-search').value).to eq(input) - end - - def expect_no_issues_list - page.within '.issues-list' do - expect(page).not_to have_selector('.issue') - end - end - - 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) - page.within '.issues-list' do - expect(page).to have_selector('.issue', count: open_count) - end - end - - before do - project.team << [user, :master] - project.team << [user2, :master] - group.add_developer(user) - group.add_developer(user2) - login_as(user) - create(:issue, project: project) - - create(:issue, title: "Bug report 1", project: project) - create(:issue, title: "Bug report 2", project: project) - create(:issue, title: "issue with 'single quotes'", project: project) - create(:issue, title: "issue with \"double quotes\"", project: project) - create(:issue, title: "issue with !@\#{$%^&*()-+", project: project) - create(:issue, title: "issue by assignee", project: project, milestone: milestone, author: user, assignee: user) - create(:issue, title: "issue by assignee with searchTerm", project: project, milestone: milestone, author: user, assignee: user) - - issue = create(:issue, - title: "Bug 2", - project: project, - milestone: milestone, - author: user, - assignee: user) - issue.labels << bug_label - - issue_with_caps_label = create(:issue, - title: "issue by assignee with searchTerm and label", - project: project, - milestone: milestone, - author: user, - assignee: user) - issue_with_caps_label.labels << caps_sensitive_label - - issue_with_everything = create(:issue, - title: "Bug report with everything you thought was possible", - project: project, - milestone: milestone, - author: user, - assignee: user) - issue_with_everything.labels << bug_label - issue_with_everything.labels << caps_sensitive_label - - multiple_words_label_issue = create(:issue, title: "Issue with multiple words label", project: project) - multiple_words_label_issue.labels << multiple_words_label - - future_milestone = create(:milestone, title: "future", project: project, due_date: Time.now + 1.month) - - create(:issue, - title: "Issue with future milestone", - milestone: future_milestone, - project: project) - - visit namespace_project_issues_path(project.namespace, project) - end - - describe 'filter issues by author' do - context 'only author', js: true do - it 'filters issues by searched author' do - input_filtered_search("author:@#{user.username}") - expect_issues_list_count(5) - end - - it 'filters issues by invalid author' do - # YOLO - end - - it 'filters issues by multiple authors' do - # YOLO - end - end - - context 'author with other filters', js: true do - it 'filters issues by searched author and text' do - search = "author:@#{user.username} issue" - input_filtered_search(search) - expect_issues_list_count(3) - expect_filtered_search_input(search) - end - - it 'filters issues by searched author, assignee and text' do - search = "author:@#{user.username} assignee:@#{user.username} issue" - input_filtered_search(search) - expect_issues_list_count(3) - expect_filtered_search_input(search) - end - - it 'filters issues by searched author, assignee, label, and text' do - search = "author:@#{user.username} assignee:@#{user.username} label:~#{caps_sensitive_label.title} issue" - input_filtered_search(search) - expect_issues_list_count(1) - expect_filtered_search_input(search) - end - - it 'filters issues by searched author, assignee, label, milestone and text' do - search = "author:@#{user.username} assignee:@#{user.username} label:~#{caps_sensitive_label.title} milestone:%#{milestone.title} issue" - input_filtered_search(search) - expect_issues_list_count(1) - expect_filtered_search_input(search) - end - end - - context 'sorting', js: true do - # TODO - end - end - - describe 'filter issues by assignee' do - context 'only assignee', js: true do - it 'filters issues by searched assignee' do - search = "assignee:@#{user.username}" - input_filtered_search(search) - expect_issues_list_count(5) - expect_filtered_search_input(search) - end - - it 'filters issues by no assignee' do - search = "assignee:none" - input_filtered_search(search) - expect_issues_list_count(8, 1) - expect_filtered_search_input(search) - end - - it 'filters issues by invalid assignee' do - # YOLO - end - - it 'filters issues by multiple assignees' do - # YOLO - end - end - - context 'assignee with other filters', js: true do - it 'filters issues by searched assignee and text' do - search = "assignee:@#{user.username} searchTerm" - input_filtered_search(search) - expect_issues_list_count(2) - expect_filtered_search_input(search) - end - - it 'filters issues by searched assignee, author and text' do - search = "assignee:@#{user.username} author:@#{user.username} searchTerm" - input_filtered_search(search) - expect_issues_list_count(2) - expect_filtered_search_input(search) - end - - it 'filters issues by searched assignee, author, label, text' do - search = "assignee:@#{user.username} author:@#{user.username} label:~#{caps_sensitive_label.title} searchTerm" - input_filtered_search(search) - expect_issues_list_count(1) - expect_filtered_search_input(search) - end - - it 'filters issues by searched assignee, author, label, milestone and text' do - search = "assignee:@#{user.username} author:@#{user.username} label:~#{caps_sensitive_label.title} milestone:%#{milestone.title} searchTerm" - input_filtered_search(search) - expect_issues_list_count(1) - expect_filtered_search_input(search) - end - end - - context 'sorting', js: true do - # TODO - end - end - - describe 'filter issues by label' do - context 'only label', js: true do - it 'filters issues by searched label' do - search = "label:~#{bug_label.title}" - input_filtered_search(search) - expect_issues_list_count(2) - expect_filtered_search_input(search) - end - - it 'filters issues by no label' do - search = "label:none" - input_filtered_search(search) - expect_issues_list_count(9, 1) - expect_filtered_search_input(search) - end - - it 'filters issues by invalid label' do - # YOLO - end - - it 'filters issues by multiple labels' do - search = "label:~#{bug_label.title} label:~#{caps_sensitive_label.title}" - input_filtered_search(search) - expect_issues_list_count(1) - expect_filtered_search_input(search) - end - - it 'filters issues by label containing special characters' do - special_label = create(:label, project: project, title: '!@#{$%^&*()-+[]<>?/:{}|\}') - special_issue = create(:issue, title: "Issue with special character label", project: project) - special_issue.labels << special_label - - search = "label:~#{special_label.title}" - input_filtered_search(search) - expect_issues_list_count(1) - expect_filtered_search_input(search) - end - - it 'does not show issues' do - new_label = create(:label, project: project, title: "new_label") - - search = "label:~#{new_label.title}" - input_filtered_search(search) - expect_no_issues_list() - expect_filtered_search_input(search) - end - end - - context 'label with multiple words', js: true do - it 'special characters' do - special_multiple_label = create(:label, project: project, title: "Utmost |mp0rt@nce") - special_multiple_issue = create(:issue, title: "Issue with special character multiple words label", project: project) - special_multiple_issue.labels << special_multiple_label - - search = "label:~'#{special_multiple_label.title}'" - input_filtered_search(search) - expect_issues_list_count(1) - - # filtered search defaults quotations to double quotes - expect_filtered_search_input("label:~\"#{special_multiple_label.title}\"") - end - - it 'single quotes' do - search = "label:~'#{multiple_words_label.title}'" - input_filtered_search(search) - expect_issues_list_count(1) - - expect_filtered_search_input("label:~\"#{multiple_words_label.title}\"") - end - - it 'double quotes' do - search = "label:~\"#{multiple_words_label.title}\"" - input_filtered_search(search) - expect_issues_list_count(1) - expect_filtered_search_input(search) - end - - it 'single quotes containing double quotes' do - double_quotes_label = create(:label, project: project, title: 'won"t fix') - double_quotes_label_issue = create(:issue, title: "Issue with double quotes label", project: project) - double_quotes_label_issue.labels << double_quotes_label - - search = "label:~'#{double_quotes_label.title}'" - input_filtered_search(search) - expect_issues_list_count(1) - expect_filtered_search_input(search) - end - - it 'double quotes containing single quotes' do - single_quotes_label = create(:label, project: project, title: "won't fix") - single_quotes_label_issue = create(:issue, title: "Issue with single quotes label", project: project) - single_quotes_label_issue.labels << single_quotes_label - - search = "label:~\"#{single_quotes_label.title}\"" - input_filtered_search(search) - expect_issues_list_count(1) - expect_filtered_search_input(search) - end - end - - context 'label with other filters', js: true do - it 'filters issues by searched label and text' do - search = "label:~#{caps_sensitive_label.title} bug" - input_filtered_search(search) - expect_issues_list_count(1) - expect_filtered_search_input(search) - end - - it 'filters issues by searched label, author and text' do - search = "label:~#{caps_sensitive_label.title} author:@#{user.username} bug" - input_filtered_search(search) - expect_issues_list_count(1) - expect_filtered_search_input(search) - end - - it 'filters issues by searched label, author, assignee and text' do - search = "label:~#{caps_sensitive_label.title} author:@#{user.username} assignee:@#{user.username} bug" - input_filtered_search(search) - expect_issues_list_count(1) - expect_filtered_search_input(search) - end - - it 'filters issues by searched label, author, assignee, milestone and text' do - search = "label:~#{caps_sensitive_label.title} author:@#{user.username} assignee:@#{user.username} milestone:%#{milestone.title} bug" - input_filtered_search(search) - expect_issues_list_count(1) - expect_filtered_search_input(search) - end - end - - context 'multiple labels with other filters', js: true do - it 'filters issues by searched label, label2, and text' do - search = "label:~#{bug_label.title} label:~#{caps_sensitive_label.title} bug" - input_filtered_search(search) - expect_issues_list_count(1) - expect_filtered_search_input(search) - end - - it 'filters issues by searched label, label2, author and text' do - search = "label:~#{bug_label.title} label:~#{caps_sensitive_label.title} author:@#{user.username} bug" - input_filtered_search(search) - expect_issues_list_count(1) - expect_filtered_search_input(search) - end - - it 'filters issues by searched label, label2, author, assignee and text' do - search = "label:~#{bug_label.title} label:~#{caps_sensitive_label.title} author:@#{user.username} assignee:@#{user.username} bug" - input_filtered_search(search) - expect_issues_list_count(1) - expect_filtered_search_input(search) - end - - it 'filters issues by searched label, label2, author, assignee, milestone and text' do - search = "label:~#{bug_label.title} label:~#{caps_sensitive_label.title} author:@#{user.username} assignee:@#{user.username} milestone:%#{milestone.title} bug" - input_filtered_search(search) - expect_issues_list_count(1) - expect_filtered_search_input(search) - end - end - - context 'issue label clicked', js: true do - before do - find('.issues-list .issue .issue-info a .label', text: multiple_words_label.title).click - sleep 1 - end - - it 'filters' do - expect_issues_list_count(1) - end - - it 'displays in search bar' do - expect(find('.filtered-search').value).to eq("label:~\"#{multiple_words_label.title}\"") - end - end - - context 'sorting', js: true do - # TODO - end - end - - describe 'filter issues by milestone' do - context 'only milestone', js: true do - it 'filters issues by searched milestone' do - input_filtered_search("milestone:%#{milestone.title}") - expect_issues_list_count(5) - end - - it 'filters issues by no milestone' do - input_filtered_search("milestone:none") - expect_issues_list_count(7, 1) - end - - it 'filters issues by upcoming milestones' do - input_filtered_search("milestone:upcoming") - expect_issues_list_count(1) - end - - it 'filters issues by invalid milestones' do - # YOLO - end - - it 'filters issues by multiple milestones' do - # YOLO - end - - it 'filters issues by milestone containing special characters' do - special_milestone = create(:milestone, title: '!@\#{$%^&*()}', project: project) - create(:issue, title: "Issue with special character milestone", project: project, milestone: special_milestone) - - search = "milestone:%#{special_milestone.title}" - input_filtered_search(search) - expect_issues_list_count(1) - expect_filtered_search_input(search) - end - - it 'does not show issues' do - new_milestone = create(:milestone, title: "new", project: project) - - search = "milestone:%#{new_milestone.title}" - input_filtered_search(search) - expect_no_issues_list() - expect_filtered_search_input(search) - end - end - - context 'milestone with other filters', js: true do - it 'filters issues by searched milestone and text' do - search = "milestone:%#{milestone.title} bug" - input_filtered_search(search) - expect_issues_list_count(2) - expect_filtered_search_input(search) - end - - it 'filters issues by searched milestone, author and text' do - search = "milestone:%#{milestone.title} author:@#{user.username} bug" - input_filtered_search(search) - expect_issues_list_count(2) - expect_filtered_search_input(search) - end - - it 'filters issues by searched milestone, author, assignee and text' do - search = "milestone:%#{milestone.title} author:@#{user.username} assignee:@#{user.username} bug" - input_filtered_search(search) - expect_issues_list_count(2) - expect_filtered_search_input(search) - end - - it 'filters issues by searched milestone, author, assignee, label and text' do - search = "milestone:%#{milestone.title} author:@#{user.username} assignee:@#{user.username} label:~#{bug_label.title} bug" - input_filtered_search(search) - expect_issues_list_count(2) - expect_filtered_search_input(search) - end - end - - context 'sorting', js: true do - # TODO - end - end - - describe 'filter issues by text' do - context 'only text', js: true do - it 'filters issues by searched text' do - search = 'Bug' - input_filtered_search(search) - expect_issues_list_count(4, 1) - expect_filtered_search_input(search) - end - - it 'filters issues by multiple searched text' do - search = 'Bug report' - input_filtered_search(search) - expect_issues_list_count(3) - expect_filtered_search_input(search) - end - - it 'filters issues by case insensitive searched text' do - search = 'bug report' - input_filtered_search(search) - expect_issues_list_count(3) - expect_filtered_search_input(search) - end - - it 'filters issues by searched text containing single quotes' do - search = '\'single quotes\'' - input_filtered_search(search) - expect_issues_list_count(1) - expect_filtered_search_input(search) - end - - it 'filters issues by searched text containing double quotes' do - search = '"double quotes"' - input_filtered_search(search) - expect_issues_list_count(1) - expect_filtered_search_input(search) - end - - it 'filters issues by searched text containing special characters' do - search = '!@#{$%^&*()-+' - input_filtered_search(search) - expect_issues_list_count(1) - expect_filtered_search_input(search) - end - - it 'does not show any issues' do - search = 'testing' - input_filtered_search(search) - expect_no_issues_list() - expect_filtered_search_input(search) - end - end - - context 'searched text with other filters', js: true do - it 'filters issues by searched text and author' do - input_filtered_search("bug author:@#{user.username}") - expect_issues_list_count(2) - expect_filtered_search_input("author:@#{user.username} bug") - end - - it 'filters issues by searched text, author and more text' do - input_filtered_search("bug author:@#{user.username} report") - expect_issues_list_count(1) - expect_filtered_search_input("author:@#{user.username} bug report") - end - - it 'filters issues by searched text, author and assignee' do - input_filtered_search("bug author:@#{user.username} assignee:@#{user.username}") - expect_issues_list_count(2) - expect_filtered_search_input("author:@#{user.username} assignee:@#{user.username} bug") - end - - it 'filters issues by searched text, author, more text and assignee' do - input_filtered_search("bug author:@#{user.username} report assignee:@#{user.username}") - expect_issues_list_count(1) - expect_filtered_search_input("author:@#{user.username} assignee:@#{user.username} bug report") - end - - it 'filters issues by searched text, author, more text, assignee and even more text' do - input_filtered_search("bug author:@#{user.username} report assignee:@#{user.username} with") - expect_issues_list_count(1) - expect_filtered_search_input("author:@#{user.username} assignee:@#{user.username} bug report with") - end - - it 'filters issues by searched text, author, assignee and label' do - input_filtered_search("bug author:@#{user.username} assignee:@#{user.username} label:~#{bug_label.title}") - expect_issues_list_count(2) - expect_filtered_search_input("author:@#{user.username} assignee:@#{user.username} label:~#{bug_label.title} bug") - end - - it 'filters issues by searched text, author, text, assignee, text, label and text' do - input_filtered_search("bug author:@#{user.username} report assignee:@#{user.username} with label:~#{bug_label.title} everything") - expect_issues_list_count(1) - expect_filtered_search_input("author:@#{user.username} assignee:@#{user.username} label:~#{bug_label.title} bug report with everything") - end - - it 'filters issues by searched text, author, assignee, label and milestone' do - input_filtered_search("bug author:@#{user.username} assignee:@#{user.username} label:~#{bug_label.title} milestone:%#{milestone.title}") - expect_issues_list_count(2) - expect_filtered_search_input("author:@#{user.username} assignee:@#{user.username} label:~#{bug_label.title} milestone:%#{milestone.title} bug") - end - - it 'filters issues by searched text, author, text, assignee, text, label, text, milestone and text' do - input_filtered_search("bug author:@#{user.username} report assignee:@#{user.username} with label:~#{bug_label.title} everything milestone:%#{milestone.title} you") - expect_issues_list_count(1) - expect_filtered_search_input("author:@#{user.username} assignee:@#{user.username} label:~#{bug_label.title} milestone:%#{milestone.title} bug report with everything you") - end - - it 'filters issues by searched text, author, assignee, multiple labels and milestone' do - input_filtered_search("bug author:@#{user.username} assignee:@#{user.username} label:~#{bug_label.title} label:~#{caps_sensitive_label.title} milestone:%#{milestone.title}") - expect_issues_list_count(1) - expect_filtered_search_input("author:@#{user.username} assignee:@#{user.username} label:~#{bug_label.title} label:~#{caps_sensitive_label.title} milestone:%#{milestone.title} bug") - end - - it 'filters issues by searched text, author, text, assignee, text, label1, text, label2, text, milestone and text' do - input_filtered_search("bug author:@#{user.username} report assignee:@#{user.username} with label:~#{bug_label.title} everything label:~#{caps_sensitive_label.title} you milestone:%#{milestone.title} thought") - expect_issues_list_count(1) - expect_filtered_search_input("author:@#{user.username} assignee:@#{user.username} label:~#{bug_label.title} label:~#{caps_sensitive_label.title} milestone:%#{milestone.title} bug report with everything you thought") - end - end - - context 'sorting', js: true do - it 'sorts by oldest updated' do - create(:issue, - title: '3 days ago', - project: project, - author: user, - created_at: 3.days.ago, - updated_at: 3.days.ago) - - old_issue = create(:issue, - title: '5 days ago', - project: project, - author: user, - created_at: 5.days.ago, - updated_at: 5.days.ago) - - input_filtered_search('days ago') - expect_issues_list_count(2) - - sort_toggle = find('.filtered-search-container .dropdown-toggle') - sort_toggle.click - - find('.filtered-search-container .dropdown-menu li a', text: 'Oldest updated').click - wait_for_ajax - - expect(find('.issues-list .issue:first-of-type .issue-title-text a')).to have_content(old_issue.title) - end - end - end - - describe 'retains filter when switching issue states', js: true do - before do - input_filtered_search('bug') - - # Wait for search results to load - sleep 2 - end - - it 'open state' do - find('.issues-state-filters a', text: 'Closed').click - wait_for_ajax - - find('.issues-state-filters a', text: 'Open').click - wait_for_ajax - - expect(page).to have_selector('.issues-list .issue', count: 4) - end - - it 'closed state' do - find('.issues-state-filters a', text: 'Closed').click - wait_for_ajax - expect(page).to have_selector('.issues-list .issue', count: 1) - expect(find('.issues-list .issue:first-of-type .issue-title-text a')).to have_content(closed_issue.title) - end - - it 'all state' do - find('.issues-state-filters a', text: 'All').click - wait_for_ajax - expect(page).to have_selector('.issues-list .issue', count: 5) - end - end - - describe 'RSS feeds' do - it 'updates atom feed link for project issues' do - visit namespace_project_issues_path(project.namespace, project, milestone_title: milestone.title, assignee_id: user.id) - link = find('.nav-controls a', text: 'Subscribe') - params = CGI.parse(URI.parse(link[:href]).query) - auto_discovery_link = find('link[type="application/atom+xml"]', visible: false) - auto_discovery_params = CGI.parse(URI.parse(auto_discovery_link[:href]).query) - expect(params).to include('private_token' => [user.private_token]) - expect(params).to include('milestone_title' => [milestone.title]) - expect(params).to include('assignee_id' => [user.id.to_s]) - expect(auto_discovery_params).to include('private_token' => [user.private_token]) - expect(auto_discovery_params).to include('milestone_title' => [milestone.title]) - expect(auto_discovery_params).to include('assignee_id' => [user.id.to_s]) - end - - it 'updates atom feed link for group issues' do - visit issues_group_path(group, milestone_title: milestone.title, assignee_id: user.id) - link = find('.nav-controls a', text: 'Subscribe') - params = CGI.parse(URI.parse(link[:href]).query) - auto_discovery_link = find('link[type="application/atom+xml"]', visible: false) - auto_discovery_params = CGI.parse(URI.parse(auto_discovery_link[:href]).query) - expect(params).to include('private_token' => [user.private_token]) - expect(params).to include('milestone_title' => [milestone.title]) - expect(params).to include('assignee_id' => [user.id.to_s]) - expect(auto_discovery_params).to include('private_token' => [user.private_token]) - expect(auto_discovery_params).to include('milestone_title' => [milestone.title]) - expect(auto_discovery_params).to include('assignee_id' => [user.id.to_s]) - end - end -end diff --git a/spec/features/issues/filtered_search/dropdown_hint_spec.rb b/spec/features/issues/filtered_search/dropdown_hint_spec.rb new file mode 100644 index 00000000000..364d4bf4db1 --- /dev/null +++ b/spec/features/issues/filtered_search/dropdown_hint_spec.rb @@ -0,0 +1,113 @@ +require 'rails_helper' + +describe 'Dropdown hint', js: true, feature: true do + include WaitForAjax + + let!(:project) { create(:empty_project) } + let!(:user) { create(:user) } + let(:filtered_search) { find('.filtered-search') } + before do + project.team << [user, :master] + login_as(user) + create(:issue, project: project) + + visit namespace_project_issues_path(project.namespace, project) + end + + describe 'behavior' do + before do + expect(page).to have_css('#js-dropdown-hint', visible: false) + filtered_search.click(); + end + + it 'opens when the search bar is first focused' do + expect(page).to have_css('#js-dropdown-hint', visible: true) + end + + it 'closes when the search bar is unfocused' do + find('body').click(); + expect(page).to have_css('#js-dropdown-hint', visible: false) + end + end + + describe 'filtering' do + it 'does not filter `Keep typing and press Enter`' do + filtered_search.set('randomtext') + expect(page).to have_css('#js-dropdown-hint', text: 'Keep typing and press Enter', visible: false) + expect(page.all('#js-dropdown-hint .filter-dropdown .filter-dropdown-item').size).to eq(0) + end + + it 'filters with text' do + filtered_search.set('a') + expect(page.all('#js-dropdown-hint .filter-dropdown .filter-dropdown-item').size).to eq(3) + end + end + + describe 'selecting from dropdown with no input' do + before do + filtered_search.click + end + + it 'opens the author dropdown when you click on author' do + find('#js-dropdown-hint .filter-dropdown .filter-dropdown-item', text: 'author').click + expect(page).to have_css('#js-dropdown-hint', visible: false) + expect(page).to have_css('#js-dropdown-author', visible: true) + expect(filtered_search.value).to eq('author:') + end + + it 'opens the assignee dropdown when you click on assignee' do + find('#js-dropdown-hint .filter-dropdown .filter-dropdown-item', text: 'assignee').click + expect(page).to have_css('#js-dropdown-hint', visible: false) + expect(page).to have_css('#js-dropdown-assignee', visible: true) + expect(filtered_search.value).to eq('assignee:') + end + + it 'opens the milestone dropdown when you click on milestone' do + find('#js-dropdown-hint .filter-dropdown .filter-dropdown-item', text: 'milestone').click + expect(page).to have_css('#js-dropdown-hint', visible: false) + expect(page).to have_css('#js-dropdown-milestone', visible: true) + expect(filtered_search.value).to eq('milestone:') + end + + it 'opens the label dropdown when you click on label' do + find('#js-dropdown-hint .filter-dropdown .filter-dropdown-item', text: 'label').click + expect(page).to have_css('#js-dropdown-hint', visible: false) + expect(page).to have_css('#js-dropdown-label', visible: true) + expect(filtered_search.value).to eq('label:') + end + end + + describe 'selecting from dropdown with some input' do + it 'opens the author dropdown when you click on author' do + filtered_search.set('auth') + find('#js-dropdown-hint .filter-dropdown .filter-dropdown-item', text: 'author').click + expect(page).to have_css('#js-dropdown-hint', visible: false) + expect(page).to have_css('#js-dropdown-author', visible: true) + expect(filtered_search.value).to eq('author:') + end + + it 'opens the assignee dropdown when you click on assignee' do + filtered_search.set('assign') + find('#js-dropdown-hint .filter-dropdown .filter-dropdown-item', text: 'assignee').click + expect(page).to have_css('#js-dropdown-hint', visible: false) + expect(page).to have_css('#js-dropdown-assignee', visible: true) + expect(filtered_search.value).to eq('assignee:') + end + + it 'opens the milestone dropdown when you click on milestone' do + filtered_search.set('mile') + find('#js-dropdown-hint .filter-dropdown .filter-dropdown-item', text: 'milestone').click + expect(page).to have_css('#js-dropdown-hint', visible: false) + expect(page).to have_css('#js-dropdown-milestone', visible: true) + expect(filtered_search.value).to eq('milestone:') + end + + it 'opens the label dropdown when you click on label' do + filtered_search.set('lab') + find('#js-dropdown-hint .filter-dropdown .filter-dropdown-item', text: 'label').click + expect(page).to have_css('#js-dropdown-hint', visible: false) + expect(page).to have_css('#js-dropdown-label', visible: true) + expect(filtered_search.value).to eq('label:') + end + end +end diff --git a/spec/features/issues/filtered_search/filter_issues_spec.rb b/spec/features/issues/filtered_search/filter_issues_spec.rb new file mode 100644 index 00000000000..283814d2cbb --- /dev/null +++ b/spec/features/issues/filtered_search/filter_issues_spec.rb @@ -0,0 +1,682 @@ +require 'rails_helper' + +describe 'Filter issues', feature: true do + include WaitForAjax + + let!(:group) { create(:group) } + let!(:project) { create(:project, group: group) } + let!(:user) { create(:user) } + let!(:user2) { create(:user) } + let!(:milestone) { create(:milestone, project: project) } + let!(:label) { create(:label, project: project) } + let!(:wontfix) { create(:label, project: project, title: "Won't fix") } + + let!(:bug_label) { create(:label, project: project, title: 'bug') } + let!(:caps_sensitive_label) { create(:label, project: project, title: 'CAPS_sensitive') } + let!(:milestone) { create(:milestone, title: "8", project: project) } + let!(:multiple_words_label) { create(:label, project: project, title: "Two words") } + + let!(:closed_issue) { create(:issue, title: 'bug that is closed', project: project, state: :closed) } + + def input_filtered_search(search_term) + filtered_search = find('.filtered-search') + filtered_search.set(search_term) + filtered_search.send_keys(:enter) + end + + def expect_filtered_search_input(input) + expect(find('.filtered-search').value).to eq(input) + end + + def expect_no_issues_list + page.within '.issues-list' do + expect(page).not_to have_selector('.issue') + end + end + + 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) + page.within '.issues-list' do + expect(page).to have_selector('.issue', count: open_count) + end + end + + before do + project.team << [user, :master] + project.team << [user2, :master] + group.add_developer(user) + group.add_developer(user2) + login_as(user) + create(:issue, project: project) + + create(:issue, title: "Bug report 1", project: project) + create(:issue, title: "Bug report 2", project: project) + create(:issue, title: "issue with 'single quotes'", project: project) + create(:issue, title: "issue with \"double quotes\"", project: project) + create(:issue, title: "issue with !@\#{$%^&*()-+", project: project) + create(:issue, title: "issue by assignee", project: project, milestone: milestone, author: user, assignee: user) + create(:issue, title: "issue by assignee with searchTerm", project: project, milestone: milestone, author: user, assignee: user) + + issue = create(:issue, + title: "Bug 2", + project: project, + milestone: milestone, + author: user, + assignee: user) + issue.labels << bug_label + + issue_with_caps_label = create(:issue, + title: "issue by assignee with searchTerm and label", + project: project, + milestone: milestone, + author: user, + assignee: user) + issue_with_caps_label.labels << caps_sensitive_label + + issue_with_everything = create(:issue, + title: "Bug report with everything you thought was possible", + project: project, + milestone: milestone, + author: user, + assignee: user) + issue_with_everything.labels << bug_label + issue_with_everything.labels << caps_sensitive_label + + multiple_words_label_issue = create(:issue, title: "Issue with multiple words label", project: project) + multiple_words_label_issue.labels << multiple_words_label + + future_milestone = create(:milestone, title: "future", project: project, due_date: Time.now + 1.month) + + create(:issue, + title: "Issue with future milestone", + milestone: future_milestone, + project: project) + + visit namespace_project_issues_path(project.namespace, project) + end + + describe 'filter issues by author' do + context 'only author', js: true do + it 'filters issues by searched author' do + input_filtered_search("author:@#{user.username}") + expect_issues_list_count(5) + end + + it 'filters issues by invalid author' do + # YOLO + end + + it 'filters issues by multiple authors' do + # YOLO + end + end + + context 'author with other filters', js: true do + it 'filters issues by searched author and text' do + search = "author:@#{user.username} issue" + input_filtered_search(search) + expect_issues_list_count(3) + expect_filtered_search_input(search) + end + + it 'filters issues by searched author, assignee and text' do + search = "author:@#{user.username} assignee:@#{user.username} issue" + input_filtered_search(search) + expect_issues_list_count(3) + expect_filtered_search_input(search) + end + + it 'filters issues by searched author, assignee, label, and text' do + search = "author:@#{user.username} assignee:@#{user.username} label:~#{caps_sensitive_label.title} issue" + input_filtered_search(search) + expect_issues_list_count(1) + expect_filtered_search_input(search) + end + + it 'filters issues by searched author, assignee, label, milestone and text' do + search = "author:@#{user.username} assignee:@#{user.username} label:~#{caps_sensitive_label.title} milestone:%#{milestone.title} issue" + input_filtered_search(search) + expect_issues_list_count(1) + expect_filtered_search_input(search) + end + end + + context 'sorting', js: true do + # TODO + end + end + + describe 'filter issues by assignee' do + context 'only assignee', js: true do + it 'filters issues by searched assignee' do + search = "assignee:@#{user.username}" + input_filtered_search(search) + expect_issues_list_count(5) + expect_filtered_search_input(search) + end + + it 'filters issues by no assignee' do + search = "assignee:none" + input_filtered_search(search) + expect_issues_list_count(8, 1) + expect_filtered_search_input(search) + end + + it 'filters issues by invalid assignee' do + # YOLO + end + + it 'filters issues by multiple assignees' do + # YOLO + end + end + + context 'assignee with other filters', js: true do + it 'filters issues by searched assignee and text' do + search = "assignee:@#{user.username} searchTerm" + input_filtered_search(search) + expect_issues_list_count(2) + expect_filtered_search_input(search) + end + + it 'filters issues by searched assignee, author and text' do + search = "assignee:@#{user.username} author:@#{user.username} searchTerm" + input_filtered_search(search) + expect_issues_list_count(2) + expect_filtered_search_input(search) + end + + it 'filters issues by searched assignee, author, label, text' do + search = "assignee:@#{user.username} author:@#{user.username} label:~#{caps_sensitive_label.title} searchTerm" + input_filtered_search(search) + expect_issues_list_count(1) + expect_filtered_search_input(search) + end + + it 'filters issues by searched assignee, author, label, milestone and text' do + search = "assignee:@#{user.username} author:@#{user.username} label:~#{caps_sensitive_label.title} milestone:%#{milestone.title} searchTerm" + input_filtered_search(search) + expect_issues_list_count(1) + expect_filtered_search_input(search) + end + end + + context 'sorting', js: true do + # TODO + end + end + + describe 'filter issues by label' do + context 'only label', js: true do + it 'filters issues by searched label' do + search = "label:~#{bug_label.title}" + input_filtered_search(search) + expect_issues_list_count(2) + expect_filtered_search_input(search) + end + + it 'filters issues by no label' do + search = "label:none" + input_filtered_search(search) + expect_issues_list_count(9, 1) + expect_filtered_search_input(search) + end + + it 'filters issues by invalid label' do + # YOLO + end + + it 'filters issues by multiple labels' do + search = "label:~#{bug_label.title} label:~#{caps_sensitive_label.title}" + input_filtered_search(search) + expect_issues_list_count(1) + expect_filtered_search_input(search) + end + + it 'filters issues by label containing special characters' do + special_label = create(:label, project: project, title: '!@#{$%^&*()-+[]<>?/:{}|\}') + special_issue = create(:issue, title: "Issue with special character label", project: project) + special_issue.labels << special_label + + search = "label:~#{special_label.title}" + input_filtered_search(search) + expect_issues_list_count(1) + expect_filtered_search_input(search) + end + + it 'does not show issues' do + new_label = create(:label, project: project, title: "new_label") + + search = "label:~#{new_label.title}" + input_filtered_search(search) + expect_no_issues_list() + expect_filtered_search_input(search) + end + end + + context 'label with multiple words', js: true do + it 'special characters' do + special_multiple_label = create(:label, project: project, title: "Utmost |mp0rt@nce") + special_multiple_issue = create(:issue, title: "Issue with special character multiple words label", project: project) + special_multiple_issue.labels << special_multiple_label + + search = "label:~'#{special_multiple_label.title}'" + input_filtered_search(search) + expect_issues_list_count(1) + + # filtered search defaults quotations to double quotes + expect_filtered_search_input("label:~\"#{special_multiple_label.title}\"") + end + + it 'single quotes' do + search = "label:~'#{multiple_words_label.title}'" + input_filtered_search(search) + expect_issues_list_count(1) + + expect_filtered_search_input("label:~\"#{multiple_words_label.title}\"") + end + + it 'double quotes' do + search = "label:~\"#{multiple_words_label.title}\"" + input_filtered_search(search) + expect_issues_list_count(1) + expect_filtered_search_input(search) + end + + it 'single quotes containing double quotes' do + double_quotes_label = create(:label, project: project, title: 'won"t fix') + double_quotes_label_issue = create(:issue, title: "Issue with double quotes label", project: project) + double_quotes_label_issue.labels << double_quotes_label + + search = "label:~'#{double_quotes_label.title}'" + input_filtered_search(search) + expect_issues_list_count(1) + expect_filtered_search_input(search) + end + + it 'double quotes containing single quotes' do + single_quotes_label = create(:label, project: project, title: "won't fix") + single_quotes_label_issue = create(:issue, title: "Issue with single quotes label", project: project) + single_quotes_label_issue.labels << single_quotes_label + + search = "label:~\"#{single_quotes_label.title}\"" + input_filtered_search(search) + expect_issues_list_count(1) + expect_filtered_search_input(search) + end + end + + context 'label with other filters', js: true do + it 'filters issues by searched label and text' do + search = "label:~#{caps_sensitive_label.title} bug" + input_filtered_search(search) + expect_issues_list_count(1) + expect_filtered_search_input(search) + end + + it 'filters issues by searched label, author and text' do + search = "label:~#{caps_sensitive_label.title} author:@#{user.username} bug" + input_filtered_search(search) + expect_issues_list_count(1) + expect_filtered_search_input(search) + end + + it 'filters issues by searched label, author, assignee and text' do + search = "label:~#{caps_sensitive_label.title} author:@#{user.username} assignee:@#{user.username} bug" + input_filtered_search(search) + expect_issues_list_count(1) + expect_filtered_search_input(search) + end + + it 'filters issues by searched label, author, assignee, milestone and text' do + search = "label:~#{caps_sensitive_label.title} author:@#{user.username} assignee:@#{user.username} milestone:%#{milestone.title} bug" + input_filtered_search(search) + expect_issues_list_count(1) + expect_filtered_search_input(search) + end + end + + context 'multiple labels with other filters', js: true do + it 'filters issues by searched label, label2, and text' do + search = "label:~#{bug_label.title} label:~#{caps_sensitive_label.title} bug" + input_filtered_search(search) + expect_issues_list_count(1) + expect_filtered_search_input(search) + end + + it 'filters issues by searched label, label2, author and text' do + search = "label:~#{bug_label.title} label:~#{caps_sensitive_label.title} author:@#{user.username} bug" + input_filtered_search(search) + expect_issues_list_count(1) + expect_filtered_search_input(search) + end + + it 'filters issues by searched label, label2, author, assignee and text' do + search = "label:~#{bug_label.title} label:~#{caps_sensitive_label.title} author:@#{user.username} assignee:@#{user.username} bug" + input_filtered_search(search) + expect_issues_list_count(1) + expect_filtered_search_input(search) + end + + it 'filters issues by searched label, label2, author, assignee, milestone and text' do + search = "label:~#{bug_label.title} label:~#{caps_sensitive_label.title} author:@#{user.username} assignee:@#{user.username} milestone:%#{milestone.title} bug" + input_filtered_search(search) + expect_issues_list_count(1) + expect_filtered_search_input(search) + end + end + + context 'issue label clicked', js: true do + before do + find('.issues-list .issue .issue-info a .label', text: multiple_words_label.title).click + sleep 1 + end + + it 'filters' do + expect_issues_list_count(1) + end + + it 'displays in search bar' do + expect(find('.filtered-search').value).to eq("label:~\"#{multiple_words_label.title}\"") + end + end + + context 'sorting', js: true do + # TODO + end + end + + describe 'filter issues by milestone' do + context 'only milestone', js: true do + it 'filters issues by searched milestone' do + input_filtered_search("milestone:%#{milestone.title}") + expect_issues_list_count(5) + end + + it 'filters issues by no milestone' do + input_filtered_search("milestone:none") + expect_issues_list_count(7, 1) + end + + it 'filters issues by upcoming milestones' do + input_filtered_search("milestone:upcoming") + expect_issues_list_count(1) + end + + it 'filters issues by invalid milestones' do + # YOLO + end + + it 'filters issues by multiple milestones' do + # YOLO + end + + it 'filters issues by milestone containing special characters' do + special_milestone = create(:milestone, title: '!@\#{$%^&*()}', project: project) + create(:issue, title: "Issue with special character milestone", project: project, milestone: special_milestone) + + search = "milestone:%#{special_milestone.title}" + input_filtered_search(search) + expect_issues_list_count(1) + expect_filtered_search_input(search) + end + + it 'does not show issues' do + new_milestone = create(:milestone, title: "new", project: project) + + search = "milestone:%#{new_milestone.title}" + input_filtered_search(search) + expect_no_issues_list() + expect_filtered_search_input(search) + end + end + + context 'milestone with other filters', js: true do + it 'filters issues by searched milestone and text' do + search = "milestone:%#{milestone.title} bug" + input_filtered_search(search) + expect_issues_list_count(2) + expect_filtered_search_input(search) + end + + it 'filters issues by searched milestone, author and text' do + search = "milestone:%#{milestone.title} author:@#{user.username} bug" + input_filtered_search(search) + expect_issues_list_count(2) + expect_filtered_search_input(search) + end + + it 'filters issues by searched milestone, author, assignee and text' do + search = "milestone:%#{milestone.title} author:@#{user.username} assignee:@#{user.username} bug" + input_filtered_search(search) + expect_issues_list_count(2) + expect_filtered_search_input(search) + end + + it 'filters issues by searched milestone, author, assignee, label and text' do + search = "milestone:%#{milestone.title} author:@#{user.username} assignee:@#{user.username} label:~#{bug_label.title} bug" + input_filtered_search(search) + expect_issues_list_count(2) + expect_filtered_search_input(search) + end + end + + context 'sorting', js: true do + # TODO + end + end + + describe 'filter issues by text' do + context 'only text', js: true do + it 'filters issues by searched text' do + search = 'Bug' + input_filtered_search(search) + expect_issues_list_count(4, 1) + expect_filtered_search_input(search) + end + + it 'filters issues by multiple searched text' do + search = 'Bug report' + input_filtered_search(search) + expect_issues_list_count(3) + expect_filtered_search_input(search) + end + + it 'filters issues by case insensitive searched text' do + search = 'bug report' + input_filtered_search(search) + expect_issues_list_count(3) + expect_filtered_search_input(search) + end + + it 'filters issues by searched text containing single quotes' do + search = '\'single quotes\'' + input_filtered_search(search) + expect_issues_list_count(1) + expect_filtered_search_input(search) + end + + it 'filters issues by searched text containing double quotes' do + search = '"double quotes"' + input_filtered_search(search) + expect_issues_list_count(1) + expect_filtered_search_input(search) + end + + it 'filters issues by searched text containing special characters' do + search = '!@#{$%^&*()-+' + input_filtered_search(search) + expect_issues_list_count(1) + expect_filtered_search_input(search) + end + + it 'does not show any issues' do + search = 'testing' + input_filtered_search(search) + expect_no_issues_list() + expect_filtered_search_input(search) + end + end + + context 'searched text with other filters', js: true do + it 'filters issues by searched text and author' do + input_filtered_search("bug author:@#{user.username}") + expect_issues_list_count(2) + expect_filtered_search_input("author:@#{user.username} bug") + end + + it 'filters issues by searched text, author and more text' do + input_filtered_search("bug author:@#{user.username} report") + expect_issues_list_count(1) + expect_filtered_search_input("author:@#{user.username} bug report") + end + + it 'filters issues by searched text, author and assignee' do + input_filtered_search("bug author:@#{user.username} assignee:@#{user.username}") + expect_issues_list_count(2) + expect_filtered_search_input("author:@#{user.username} assignee:@#{user.username} bug") + end + + it 'filters issues by searched text, author, more text and assignee' do + input_filtered_search("bug author:@#{user.username} report assignee:@#{user.username}") + expect_issues_list_count(1) + expect_filtered_search_input("author:@#{user.username} assignee:@#{user.username} bug report") + end + + it 'filters issues by searched text, author, more text, assignee and even more text' do + input_filtered_search("bug author:@#{user.username} report assignee:@#{user.username} with") + expect_issues_list_count(1) + expect_filtered_search_input("author:@#{user.username} assignee:@#{user.username} bug report with") + end + + it 'filters issues by searched text, author, assignee and label' do + input_filtered_search("bug author:@#{user.username} assignee:@#{user.username} label:~#{bug_label.title}") + expect_issues_list_count(2) + expect_filtered_search_input("author:@#{user.username} assignee:@#{user.username} label:~#{bug_label.title} bug") + end + + it 'filters issues by searched text, author, text, assignee, text, label and text' do + input_filtered_search("bug author:@#{user.username} report assignee:@#{user.username} with label:~#{bug_label.title} everything") + expect_issues_list_count(1) + expect_filtered_search_input("author:@#{user.username} assignee:@#{user.username} label:~#{bug_label.title} bug report with everything") + end + + it 'filters issues by searched text, author, assignee, label and milestone' do + input_filtered_search("bug author:@#{user.username} assignee:@#{user.username} label:~#{bug_label.title} milestone:%#{milestone.title}") + expect_issues_list_count(2) + expect_filtered_search_input("author:@#{user.username} assignee:@#{user.username} label:~#{bug_label.title} milestone:%#{milestone.title} bug") + end + + it 'filters issues by searched text, author, text, assignee, text, label, text, milestone and text' do + input_filtered_search("bug author:@#{user.username} report assignee:@#{user.username} with label:~#{bug_label.title} everything milestone:%#{milestone.title} you") + expect_issues_list_count(1) + expect_filtered_search_input("author:@#{user.username} assignee:@#{user.username} label:~#{bug_label.title} milestone:%#{milestone.title} bug report with everything you") + end + + it 'filters issues by searched text, author, assignee, multiple labels and milestone' do + input_filtered_search("bug author:@#{user.username} assignee:@#{user.username} label:~#{bug_label.title} label:~#{caps_sensitive_label.title} milestone:%#{milestone.title}") + expect_issues_list_count(1) + expect_filtered_search_input("author:@#{user.username} assignee:@#{user.username} label:~#{bug_label.title} label:~#{caps_sensitive_label.title} milestone:%#{milestone.title} bug") + end + + it 'filters issues by searched text, author, text, assignee, text, label1, text, label2, text, milestone and text' do + input_filtered_search("bug author:@#{user.username} report assignee:@#{user.username} with label:~#{bug_label.title} everything label:~#{caps_sensitive_label.title} you milestone:%#{milestone.title} thought") + expect_issues_list_count(1) + expect_filtered_search_input("author:@#{user.username} assignee:@#{user.username} label:~#{bug_label.title} label:~#{caps_sensitive_label.title} milestone:%#{milestone.title} bug report with everything you thought") + end + end + + context 'sorting', js: true do + it 'sorts by oldest updated' do + create(:issue, + title: '3 days ago', + project: project, + author: user, + created_at: 3.days.ago, + updated_at: 3.days.ago) + + old_issue = create(:issue, + title: '5 days ago', + project: project, + author: user, + created_at: 5.days.ago, + updated_at: 5.days.ago) + + input_filtered_search('days ago') + expect_issues_list_count(2) + + sort_toggle = find('.filtered-search-container .dropdown-toggle') + sort_toggle.click + + find('.filtered-search-container .dropdown-menu li a', text: 'Oldest updated').click + wait_for_ajax + + expect(find('.issues-list .issue:first-of-type .issue-title-text a')).to have_content(old_issue.title) + end + end + end + + describe 'retains filter when switching issue states', js: true do + before do + input_filtered_search('bug') + + # Wait for search results to load + sleep 2 + end + + it 'open state' do + find('.issues-state-filters a', text: 'Closed').click + wait_for_ajax + + find('.issues-state-filters a', text: 'Open').click + wait_for_ajax + + expect(page).to have_selector('.issues-list .issue', count: 4) + end + + it 'closed state' do + find('.issues-state-filters a', text: 'Closed').click + wait_for_ajax + expect(page).to have_selector('.issues-list .issue', count: 1) + expect(find('.issues-list .issue:first-of-type .issue-title-text a')).to have_content(closed_issue.title) + end + + it 'all state' do + find('.issues-state-filters a', text: 'All').click + wait_for_ajax + expect(page).to have_selector('.issues-list .issue', count: 5) + end + end + + describe 'RSS feeds' do + it 'updates atom feed link for project issues' do + visit namespace_project_issues_path(project.namespace, project, milestone_title: milestone.title, assignee_id: user.id) + link = find('.nav-controls a', text: 'Subscribe') + params = CGI.parse(URI.parse(link[:href]).query) + auto_discovery_link = find('link[type="application/atom+xml"]', visible: false) + auto_discovery_params = CGI.parse(URI.parse(auto_discovery_link[:href]).query) + expect(params).to include('private_token' => [user.private_token]) + expect(params).to include('milestone_title' => [milestone.title]) + expect(params).to include('assignee_id' => [user.id.to_s]) + expect(auto_discovery_params).to include('private_token' => [user.private_token]) + expect(auto_discovery_params).to include('milestone_title' => [milestone.title]) + expect(auto_discovery_params).to include('assignee_id' => [user.id.to_s]) + end + + it 'updates atom feed link for group issues' do + visit issues_group_path(group, milestone_title: milestone.title, assignee_id: user.id) + link = find('.nav-controls a', text: 'Subscribe') + params = CGI.parse(URI.parse(link[:href]).query) + auto_discovery_link = find('link[type="application/atom+xml"]', visible: false) + auto_discovery_params = CGI.parse(URI.parse(auto_discovery_link[:href]).query) + expect(params).to include('private_token' => [user.private_token]) + expect(params).to include('milestone_title' => [milestone.title]) + expect(params).to include('assignee_id' => [user.id.to_s]) + expect(auto_discovery_params).to include('private_token' => [user.private_token]) + expect(auto_discovery_params).to include('milestone_title' => [milestone.title]) + expect(auto_discovery_params).to include('assignee_id' => [user.id.to_s]) + end + end +end diff --git a/spec/features/issues/filtered_search/search_bar_spec.rb b/spec/features/issues/filtered_search/search_bar_spec.rb new file mode 100644 index 00000000000..5862214cdc3 --- /dev/null +++ b/spec/features/issues/filtered_search/search_bar_spec.rb @@ -0,0 +1,86 @@ +require 'rails_helper' + +describe 'Search bar', js: true, feature: true do + include WaitForAjax + + let!(:project) { create(:empty_project) } + let!(:user) { create(:user) } + + before do + project.team << [user, :master] + login_as(user) + create(:issue, project: project) + + visit namespace_project_issues_path(project.namespace, project) + end + + def getLeftStyle(style) + leftStyle = /left:\s\d*[.]\d*px/.match(style) + leftStyle.to_s.gsub('left: ', '').to_f; + end + + describe 'clear search button' do + it 'clears text' do + search_text = 'search_text' + filtered_search = find('.filtered-search') + filtered_search.set(search_text) + + expect(filtered_search.value).to eq(search_text) + find('.filtered-search-input-container .clear-search').click + expect(filtered_search.value).to eq('') + end + + it 'hides by default' do + expect(page).to have_css('.clear-search', visible: false) + end + + it 'hides after clicked' do + filtered_search = find('.filtered-search') + filtered_search.set('a') + find('.filtered-search-input-container .clear-search').click + expect(page).to have_css('.clear-search', visible: false) + end + + it 'hides when there is no text' do + filtered_search = find('.filtered-search') + filtered_search.set('a') + filtered_search.set('') + expect(page).to have_css('.clear-search', visible: false) + end + + it 'shows when there is text' do + filtered_search = find('.filtered-search') + filtered_search.set('a') + + expect(page).to have_css('.clear-search', visible: true) + end + + it 'resets the dropdown hint filter' do + filtered_search = find('.filtered-search') + filtered_search.click(); + original_size = page.all('#js-dropdown-hint .filter-dropdown .filter-dropdown-item').size + + filtered_search.set('author') + expect(page.all('#js-dropdown-hint .filter-dropdown .filter-dropdown-item').size).to eq(1) + + find('.filtered-search-input-container .clear-search').click + filtered_search.click() + expect(page.all('#js-dropdown-hint .filter-dropdown .filter-dropdown-item').size).to eq(original_size) + end + + it 'resets the dropdown filters' do + filtered_search = find('.filtered-search') + filtered_search.set('a') + hintStyle = page.find('#js-dropdown-hint')['style'] + hintOffset = getLeftStyle(hintStyle) + + filtered_search.set('author:') + expect(page.all('#js-dropdown-hint .filter-dropdown .filter-dropdown-item').size).to eq(0) + + find('.filtered-search-input-container .clear-search').click + filtered_search.click() + expect(page.all('#js-dropdown-hint .filter-dropdown .filter-dropdown-item').size).to be > 0 + expect(getLeftStyle(page.find('#js-dropdown-hint')['style'])).to eq (hintOffset) + end + end +end diff --git a/spec/features/issues/search_bar_spec.rb b/spec/features/issues/search_bar_spec.rb deleted file mode 100644 index d0abdc284ea..00000000000 --- a/spec/features/issues/search_bar_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -require 'rails_helper' - -describe 'Search bar', js: true, feature: true do - include WaitForAjax - - let!(:project) { create(:empty_project) } - let!(:user) { create(:user) } - - before do - project.team << [user, :master] - login_as(user) - create(:issue, project: project) - - visit namespace_project_issues_path(project.namespace, project) - end - - describe 'clear search button' do - it 'clears text' do - search_text = 'search_text' - filtered_search = find('.filtered-search') - filtered_search.set(search_text) - - expect(filtered_search.value).to eq(search_text) - find('.filtered-search-input-container .clear-search').click - expect(filtered_search.value).to eq('') - end - - it 'hides by default' do - expect(page).to have_css('.clear-search', visible: false) - end - - it 'hides after clicked' do - filtered_search = find('.filtered-search') - filtered_search.set('a') - find('.filtered-search-input-container .clear-search').click - expect(page).to have_css('.clear-search', visible: false) - end - - it 'hides when there is no text' do - filtered_search = find('.filtered-search') - filtered_search.set('a') - filtered_search.set('') - expect(page).to have_css('.clear-search', visible: false) - end - - it 'shows when there is text' do - filtered_search = find('.filtered-search') - filtered_search.set('a') - - expect(page).to have_css('.clear-search', visible: true) - end - end -end -- cgit v1.2.1