BigW Consortium Gitlab

search_spec.rb 8.53 KB
Newer Older
1 2
require 'spec_helper'

3
describe "Search", feature: true  do
4
  include FilteredSearchHelpers
5

6
  let(:user) { create(:user) }
7
  let(:project) { create(:empty_project, namespace: user.namespace) }
8
  let!(:issue) { create(:issue, project: project, assignees: [user]) }
Phil Hughes committed
9
  let!(:issue2) { create(:issue, project: project, author: user) }
10

11
  before do
12 13
    login_with(user)
    project.team << [user, :reporter]
14
    visit search_path
15
  end
16

17
  it 'does not show top right search form' do
18 19
    expect(page).not_to have_selector('.search')
  end
20

21 22
  context 'search filters', js: true do
    let(:group) { create(:group) }
23
    let!(:group_project) { create(:empty_project, group: group) }
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

    before do
      group.add_owner(user)
    end

    it 'shows group name after filtering' do
      find('.js-search-group-dropdown').click
      wait_for_ajax

      page.within '.search-holder' do
        click_link group.name
      end

      expect(find('.js-search-group-dropdown')).to have_content(group.name)
    end

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
    it 'filters by group projects after filtering by group' do
      find('.js-search-group-dropdown').click
      wait_for_ajax

      page.within '.search-holder' do
        click_link group.name
      end

      expect(find('.js-search-group-dropdown')).to have_content(group.name)

      page.within('.project-filter') do
        find('.js-search-project-dropdown').click
        wait_for_ajax

        expect(page).to have_link(group_project.name_with_namespace)
      end
    end

58 59 60 61 62 63 64 65 66 67 68 69
    it 'shows project name after filtering' do
      page.within('.project-filter') do
        find('.js-search-project-dropdown').click
        wait_for_ajax

        click_link project.name_with_namespace
      end

      expect(find('.js-search-project-dropdown')).to have_content(project.name_with_namespace)
    end
  end

70 71 72 73 74 75 76 77
  describe 'searching for Projects' do
    it 'finds a project' do
      page.within '.search-holder' do
        fill_in "search", with: project.name[0..3]
        click_button "Search"
      end

      expect(page).to have_content project.name
78
    end
79 80
  end

81
  context 'search for comments' do
82
    context 'when comment belongs to a invalid commit' do
83
      let(:project) { create(:project, :repository) }
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
      let(:note) { create(:note_on_commit, author: user, project: project, commit_id: project.repository.commit.id, note: 'Bug here') }

      before { note.update_attributes(commit_id: 12345678) }

      it 'finds comment' do
        visit namespace_project_path(project.namespace, project)

        page.within '.search' do
          fill_in 'search', with: note.note
          click_button 'Go'
        end

        click_link 'Comments'

        expect(page).to have_text("Commit deleted")
        expect(page).to have_text("12345678")
      end
    end

103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
    it 'finds a snippet' do
      snippet = create(:project_snippet, :private, project: project, author: user, title: 'Some title')
      note = create(:note,
                    noteable: snippet,
                    author: user,
                    note: 'Supercalifragilisticexpialidocious',
                    project: project)
      # Must visit project dashboard since global search won't search
      # everything (e.g. comments, snippets, etc.)
      visit namespace_project_path(project.namespace, project)

      page.within '.search' do
        fill_in 'search', with: note.note
        click_button 'Go'
      end

      click_link 'Comments'

      expect(page).to have_link(snippet.title)
    end
123 124

    it 'finds a commit' do
125
      project = create(:project, :repository) { |p| p.add_reporter(user) }
126 127 128 129 130 131 132 133 134 135 136 137 138
      visit namespace_project_path(project.namespace, project)

      page.within '.search' do
        fill_in 'search', with: 'add'
        click_button 'Go'
      end

      click_link "Commits"

      expect(page).to have_selector('.commit-row-description')
    end

    it 'finds a code' do
139
      project = create(:project, :repository) { |p| p.add_reporter(user) }
140 141 142
      visit namespace_project_path(project.namespace, project)

      page.within '.search' do
143
        fill_in 'search', with: 'application.js'
144 145 146 147 148 149
        click_button 'Go'
      end

      click_link "Code"

      expect(page).to have_selector('.file-content .code')
150 151

      expect(page).to have_selector("span.line[lang='javascript']")
152
    end
153
  end
154 155

  describe 'Right header search field', feature: true do
156 157 158 159 160 161 162 163 164 165
    it 'allows enter key to search', js: true do
      visit namespace_project_path(project.namespace, project)
      fill_in 'search', with: 'gitlab'
      find('#search').native.send_keys(:enter)

      page.within '.title' do
        expect(page).to have_content 'Search'
      end
    end

166 167 168 169 170
    describe 'Search in project page' do
      before do
        visit namespace_project_path(project.namespace, project)
      end

171
      it 'shows top right search form' do
172 173 174
        expect(page).to have_selector('#search')
      end

175
      it 'contains location badge in top right search form' do
176 177 178 179
        expect(page).to have_selector('.has-location-badge')
      end

      context 'clicking the search field', js: true do
180
        it 'shows category search dropdown' do
181 182
          page.find('#search').click

183
          expect(page).to have_selector('.dropdown-header', text: /#{project.name}/i)
184 185 186 187
        end
      end

      context 'click the links in the category search dropdown', js: true do
Luke "Jared" Bennett committed
188 189
        let!(:merge_request) { create(:merge_request, source_project: project, author: user, assignee: user) }

190 191 192 193
        before do
          page.find('#search').click
        end

194
        it 'takes user to her issues page when issues assigned is clicked' do
195 196 197
          find('.dropdown-menu').click_link 'Issues assigned to me'
          sleep 2

Clement Ho committed
198
          expect(page).to have_selector('.filtered-search')
199 200
          expect_tokens([{ name: 'assignee', value: "@#{user.username}" }])
          expect_filtered_search_input_empty
201 202
        end

203
        it 'takes user to her issues page when issues authored is clicked' do
204 205 206
          find('.dropdown-menu').click_link "Issues I've created"
          sleep 2

Clement Ho committed
207
          expect(page).to have_selector('.filtered-search')
208 209
          expect_tokens([{ name: 'author', value: "@#{user.username}" }])
          expect_filtered_search_input_empty
210 211
        end

212
        it 'takes user to her MR page when MR assigned is clicked' do
213 214 215 216
          find('.dropdown-menu').click_link 'Merge requests assigned to me'
          sleep 2

          expect(page).to have_selector('.merge-requests-holder')
217 218
          expect_tokens([{ name: 'assignee', value: "@#{user.username}" }])
          expect_filtered_search_input_empty
219 220
        end

221
        it 'takes user to her MR page when MR authored is clicked' do
222 223 224 225
          find('.dropdown-menu').click_link "Merge requests I've created"
          sleep 2

          expect(page).to have_selector('.merge-requests-holder')
226 227
          expect_tokens([{ name: 'author', value: "@#{user.username}" }])
          expect_filtered_search_input_empty
228 229 230 231 232 233 234 235 236 237
        end
      end

      context 'entering text into the search field', js: true do
        before do
          page.within '.search-input-wrap' do
            fill_in "search", with: project.name[0..3]
          end
        end

238
        it 'does not display the category search dropdown' do
239
          expect(page).not_to have_selector('.dropdown-header', text: /#{project.name}/i)
240 241 242 243
        end
      end
    end
  end
244 245

  describe 'search for commits' do
246 247
    let(:project) { create(:project, :repository) }

248 249 250 251
    before do
      visit search_path(project_id: project.id)
    end

252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
    it 'redirects to commit page when search by sha and only commit found' do
      fill_in 'search', with: '6d394385cf567f80a8fd85055db1ab4c5295806f'

      click_button 'Search'

      expect(page).to have_current_path(namespace_project_commit_path(project.namespace, project, '6d394385cf567f80a8fd85055db1ab4c5295806f'))
    end

    it 'redirects to single commit regardless of query case' do
      fill_in 'search', with: '6D394385cf'

      click_button 'Search'

      expect(page).to have_current_path(namespace_project_commit_path(project.namespace, project, '6d394385cf567f80a8fd85055db1ab4c5295806f'))
    end

    it 'holds on /search page when the only commit is found by message' do
      create_commit('Message referencing another sha: "deadbeef" ', project, user, 'master')

      fill_in 'search', with: 'deadbeef'
      click_button 'Search'

      expect(page).to have_current_path('/search', only_path: true)
    end

277 278 279 280 281 282 283 284 285
    it 'shows multiple matching commits' do
      fill_in 'search', with: 'See merge request'

      click_button 'Search'
      click_link 'Commits'

      expect(page).to have_selector('.commit-row-description', count: 9)
    end
  end
286
end