Fix spec/features/participants_autocomplete_spec.rb

Signed-off-by: Rémy Coutable <remy@rymai.me>
This commit is contained in:
Rémy Coutable 2017-03-22 19:04:29 +01:00
parent f879e40da7
commit 709a566700
No known key found for this signature in database
GPG key ID: 46DF07E5CD9E96AB

View file

@ -1,101 +1,62 @@
require 'spec_helper' require 'spec_helper'
feature 'Member autocomplete', feature: true do feature 'Member autocomplete', :js do
include WaitForAjax
let(:project) { create(:project, :public) } let(:project) { create(:project, :public) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:participant) { create(:user) }
let(:author) { create(:user) } let(:author) { create(:user) }
let(:note) { create(:note, noteable: noteable, project: noteable.project) }
before do before do
allow_any_instance_of(Commit).to receive(:author).and_return(author) note # actually create the note
login_as user login_as(user)
end end
shared_examples "open suggestions" do shared_examples "open suggestions when typing @" do
it 'displays suggestions' do
expect(page).to have_selector('.atwho-view', visible: true)
end
it 'suggests author' do
page.within('.atwho-view', visible: true) do
expect(page).to have_content(author.username)
end
end
it 'suggests participant' do
page.within('.atwho-view', visible: true) do
expect(page).to have_content(participant.username)
end
end
end
context 'adding a new note on a Issue', js: true do
before do before do
issue = create(:issue, author: author, project: project)
create(:note, note: 'Ultralight Beam', noteable: issue,
project: project, author: participant)
visit_issue(project, issue)
end
context 'when typing @' do
include_examples "open suggestions"
before do
open_member_suggestions
end
end
end
context 'adding a new note on a Merge Request ', js: true do
before do
merge = create(:merge_request, source_project: project, target_project: project, author: author)
create(:note, note: 'Ultralight Beam', noteable: merge,
project: project, author: participant)
visit_merge_request(project, merge)
end
context 'when typing @' do
include_examples "open suggestions"
before do
open_member_suggestions
end
end
end
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
def open_member_suggestions
page.within('.new-note') do page.within('.new-note') do
find('#note_note').send_keys('@') find('#note_note').send_keys('@')
end end
wait_for_ajax
end end
def visit_issue(project, issue) it 'suggests noteable author and note author' do
visit namespace_project_issue_path(project.namespace, project, issue) page.within('.atwho-view', visible: true) do
expect(page).to have_content(author.username)
expect(page).to have_content(note.author.username)
end
end
end end
def visit_merge_request(project, merge) context 'adding a new note on a Issue' do
visit namespace_project_merge_request_path(project.namespace, project, merge) let(:noteable) { create(:issue, author: author, project: project) }
before do
visit namespace_project_issue_path(project.namespace, project, noteable)
end end
def visit_commit(project, commit) include_examples "open suggestions when typing @"
visit namespace_project_commit_path(project.namespace, project, commit) end
context 'adding a new note on a Merge Request' do
let(:noteable) do
create(:merge_request, source_project: project,
target_project: project, author: author)
end
before do
visit namespace_project_merge_request_path(project.namespace, project, noteable)
end
include_examples "open suggestions when typing @"
end
context 'adding a new note on a Commit' do
let(:noteable) { project.commit }
let(:note) { create(:note_on_commit, project: project, commit_id: project.commit.id) }
before do
allow_any_instance_of(Commit).to receive(:author).and_return(author)
visit namespace_project_commit_path(project.namespace, project, noteable)
end
include_examples "open suggestions when typing @"
end end
end end