BigW Consortium Gitlab

participants_autocomplete_spec.rb 2.69 KB
Newer Older
1 2 3 4 5 6 7 8 9
require 'spec_helper'

feature 'Member autocomplete', feature: true do
  let(:project) { create(:project, :public) }
  let(:user) { create(:user) }
  let(:participant) { create(:user) }
  let(:author) { create(:user) }

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

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

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

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

32
  context 'adding a new note on a Issue', js: true do
33
    before do
34
      issue = create(:issue, author: author, project: project)
35 36
      create(:note, note: 'Ultralight Beam', noteable: issue,
                    project: project, author: participant)
37 38 39
      visit_issue(project, issue)
    end

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

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

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

64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
  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

81 82 83 84 85 86 87 88
  def open_member_suggestions
    sleep 1
    page.within('.new-note') do
      sleep 1
      find('#note_note').native.send_keys('@')
    end
  end

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

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

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