participants_autocomplete_spec.rb 1.99 KB
Newer Older
1 2
require 'spec_helper'

3
feature 'Member autocomplete', :js do
4
  let(:project) { create(:project, :public) }
5 6
  let(:user) { create(:user) }
  let(:author) { create(:user) }
7
  let(:note) { create(:note, noteable: noteable, project: noteable.project) }
8 9

  before do
10
    note # actually create the note
11
    sign_in(user)
12 13
  end

14
  shared_examples "open suggestions when typing @" do |resource_name|
15 16
    before do
      page.within('.new-note') do
17 18 19 20 21
        if resource_name == 'issue'
          find('#note-body').send_keys('@')
        else
          find('#note_note').send_keys('@')
        end
22 23 24
      end
    end

25
    it 'suggests noteable author and note author' do
26
      page.within('.atwho-view', visible: true) do
27 28
        expect(page).to have_content(author.username)
        expect(page).to have_content(note.author.username)
29 30 31 32
      end
    end
  end

33 34
  context 'adding a new note on a Issue' do
    let(:noteable) { create(:issue, author: author, project: project) }
35
    before do
36
      visit project_issue_path(project, noteable)
37 38
    end

39
    include_examples "open suggestions when typing @", 'issue'
40 41
  end

42
  context 'adding a new note on a Merge Request' do
43
    let(:project) { create(:project, :public, :repository) }
44 45 46 47
    let(:noteable) do
      create(:merge_request, source_project: project,
                             target_project: project, author: author)
    end
48
    before do
49
      visit project_merge_request_path(project, noteable)
50 51
    end

52
    include_examples "open suggestions when typing @", 'merge_request'
53 54
  end

55
  context 'adding a new note on a Commit' do
56
    let(:project) { create(:project, :public, :repository) }
57 58
    let(:noteable) { project.commit }
    let(:note) { create(:note_on_commit, project: project, commit_id: project.commit.id) }
59 60

    before do
61 62
      allow(User).to receive(:find_by_any_email)
        .with(noteable.author_email.downcase).and_return(author)
63

64
      visit project_commit_path(project, noteable)
65
    end
66

67
    include_examples "open suggestions when typing @", 'commit'
68
  end
69
end