participants_autocomplete_spec.rb 2.7 KB
Newer Older
1 2 3
require 'spec_helper'

feature 'Member autocomplete', feature: true do
4 5
  include WaitForAjax

6 7 8 9 10 11
  let(:project) { create(:project, :public) }
  let(:user) { create(:user) }
  let(:participant) { create(:user) }
  let(:author) { create(:user) }

  before do
12
    allow_any_instance_of(Commit).to receive(:author).and_return(author)
13 14 15
    login_as user
  end

16
  shared_examples "open suggestions" do
17
    it 'displays suggestions' do
18 19 20
      expect(page).to have_selector('.atwho-view', visible: true)
    end

21
    it 'suggests author' do
22 23 24 25 26
      page.within('.atwho-view', visible: true) do
        expect(page).to have_content(author.username)
      end
    end

27
    it 'suggests participant' do
28 29 30 31 32 33
      page.within('.atwho-view', visible: true) do
        expect(page).to have_content(participant.username)
      end
    end
  end

Alfredo Sumaran's avatar
Alfredo Sumaran committed
34
  context 'adding a new note on a Issue', js: true do
35
    before do
36
      issue = create(:issue, author: author, project: project)
37 38
      create(:note, note: 'Ultralight Beam', noteable: issue,
                    project: project, author: participant)
39 40 41
      visit_issue(project, issue)
    end

42 43 44 45
    context 'when typing @' do
      include_examples "open suggestions"
      before do
        open_member_suggestions
46 47 48 49
      end
    end
  end

Alfredo Sumaran's avatar
Alfredo Sumaran committed
50
  context 'adding a new note on a Merge Request ', js: true do
51 52
    before do
      merge = create(:merge_request, source_project: project, target_project: project, author: author)
53 54
      create(:note, note: 'Ultralight Beam', noteable: merge,
                    project: project, author: participant)
55 56 57 58 59 60 61 62 63 64 65
      visit_merge_request(project, merge)
    end

    context 'when typing @' do
      include_examples "open suggestions"
      before do
        open_member_suggestions
      end
    end
  end

66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
  context 'adding a new note on a Commit ', js: true do
    let(:commit)  { project.commit }

    before do
      allow(commit).to receive(:author).and_return(author)
      create(:note_on_commit, author: participant, project: project, commit_id: project.repository.commit.id, note: 'No More Parties in LA')
      visit_commit(project, commit)
    end

    context 'when typing @' do
      include_examples "open suggestions"
      before do
        open_member_suggestions
      end
    end
  end

83 84
  def open_member_suggestions
    page.within('.new-note') do
85
      find('#note_note').send_keys('@')
86
    end
87
    wait_for_ajax
88 89
  end

90 91 92
  def visit_issue(project, issue)
    visit namespace_project_issue_path(project.namespace, project, issue)
  end
93 94 95 96

  def visit_merge_request(project, merge)
    visit namespace_project_merge_request_path(project.namespace, project, merge)
  end
97 98 99 100

  def visit_commit(project, commit)
    visit namespace_project_commit_path(project.namespace, project, commit)
  end
101
end