Commit ce5ef225 authored by Coung Ngo's avatar Coung Ngo

Update specs to not find by #note-body or #note_note

Update specs to prefer more natural Capybara actions
for improved readability
parent d69809a3
...@@ -13,6 +13,8 @@ RSpec.describe 'Issue promotion', :js do ...@@ -13,6 +13,8 @@ RSpec.describe 'Issue promotion', :js do
let(:user) { create(:user) } let(:user) { create(:user) }
before do before do
stub_feature_flags(tribute_autocomplete: false)
sign_in(user) sign_in(user)
end end
...@@ -51,13 +53,10 @@ RSpec.describe 'Issue promotion', :js do ...@@ -51,13 +53,10 @@ RSpec.describe 'Issue promotion', :js do
visit project_issue_path(project, issue) visit project_issue_path(project, issue)
end end
it 'displays warning' do it 'displays description' do
note = find('#note-body') fill_in 'Comment', with: '/promote'
type(note, '/promote')
wait_for_requests
expect(page).to have_content 'Promote issue to an epic' expect(find_autocomplete_menu).to have_text 'Promote issue to an epic'
end end
it 'promotes the issue' do it 'promotes the issue' do
...@@ -100,12 +99,9 @@ RSpec.describe 'Issue promotion', :js do ...@@ -100,12 +99,9 @@ RSpec.describe 'Issue promotion', :js do
end end
it 'displays warning' do it 'displays warning' do
note = find('#note-body') fill_in 'Comment', with: '/promote'
type(note, '/promote')
wait_for_requests expect(find_autocomplete_menu).to have_text 'Promote confidential issue to a non-confidential epic'
expect(page).to have_content 'Promote confidential issue to a non-confidential epic'
end end
it 'promotes the issue' do it 'promotes the issue' do
...@@ -124,12 +120,7 @@ RSpec.describe 'Issue promotion', :js do ...@@ -124,12 +120,7 @@ RSpec.describe 'Issue promotion', :js do
private private
# `note` is a textarea where the given text should be typed. def find_autocomplete_menu
# We don't want to find it each time this function gets called. find('.atwho-view ul', visible: true)
def type(note, text)
page.within('.timeline-content-form') do
note.set('')
note.native.send_keys(text)
end
end end
end end
...@@ -6,43 +6,33 @@ RSpec.describe 'GFM autocomplete EE', :js do ...@@ -6,43 +6,33 @@ RSpec.describe 'GFM autocomplete EE', :js do
let_it_be(:user) { create(:user, name: '💃speciąl someone💃', username: 'someone.special') } let_it_be(:user) { create(:user, name: '💃speciąl someone💃', username: 'someone.special') }
let_it_be(:another_user) { create(:user, name: 'another user', username: 'another.user') } let_it_be(:another_user) { create(:user, name: 'another user', username: 'another.user') }
let_it_be(:group) { create(:group) } let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, group: group) }
let_it_be(:issue) { create(:issue, project: project) }
let_it_be(:epic) { create(:epic, group: group) } let_it_be(:epic) { create(:epic, group: group) }
let_it_be(:project) { create(:project, group: group) }
let_it_be(:issue) { create(:issue, project: project, assignees: [user]) }
before do before do
project.add_maintainer(user) project.add_maintainer(user)
end end
context 'assignees' do context 'assignees' do
let(:issue_assignee) { create(:issue, project: project) }
describe 'when tribute_autocomplete feature flag is off' do describe 'when tribute_autocomplete feature flag is off' do
before do before do
stub_feature_flags(tribute_autocomplete: false) stub_feature_flags(tribute_autocomplete: false)
issue_assignee.update!(assignees: [user])
sign_in(user) sign_in(user)
visit project_issue_path(project, issue_assignee)
wait_for_requests visit project_issue_path(project, issue)
end end
it 'only lists users who are currently assigned to the issue when using /unassign' do it 'only lists users who are currently assigned to the issue when using /unassign' do
note = find('#note-body') fill_in 'Comment', with: '/una'
page.within '.timeline-content-form' do
note.native.send_keys('/una')
end
find('.atwho-view li', text: '/unassign') find_highlighted_autocomplete_item.click
note.native.send_keys(:tab)
wait_for_requests wait_for_requests
users = find('#at-view-users .atwho-view-ul') expect(find_autocomplete_menu).to have_text(user.username)
expect(users).to have_content(user.username) expect(find_autocomplete_menu).not_to have_text(another_user.username)
expect(users).not_to have_content(another_user.username)
end end
end end
...@@ -51,40 +41,45 @@ RSpec.describe 'GFM autocomplete EE', :js do ...@@ -51,40 +41,45 @@ RSpec.describe 'GFM autocomplete EE', :js do
stub_licensed_features(epics: true) stub_licensed_features(epics: true)
stub_feature_flags(tribute_autocomplete: true) stub_feature_flags(tribute_autocomplete: true)
issue_assignee.update!(assignees: [user])
sign_in(user) sign_in(user)
visit project_issue_path(project, issue_assignee)
wait_for_requests visit project_issue_path(project, issue)
end end
it 'only lists users who are currently assigned to the issue when using /unassign' do it 'only lists users who are currently assigned to the issue when using /unassign' do
note = find('#note-body') note = find_field('Comment')
page.within '.timeline-content-form' do note.native.send_keys('/unassign ')
note.native.send_keys('/unassign ') # The `/unassign` ajax response might replace the one by `@` below causing a failed test
# The `/unassign` ajax response might replace the one by `@` below causing a failed test # so we need to wait for the `/assign` ajax request to finish first
# so we need to wait for the `/assign` ajax request to finish first wait_for_requests
wait_for_requests note.native.send_keys('@')
note.native.send_keys('@') wait_for_requests
wait_for_requests
end expect(find_tribute_autocomplete_menu).to have_text(user.username)
expect(find_tribute_autocomplete_menu).not_to have_text(another_user.username)
users = find('.tribute-container ul', visible: true)
expect(users).to have_content(user.username)
expect(users).not_to have_content(another_user.username)
end end
it 'shows epics' do it 'shows epics' do
note = find('#note-body') fill_in 'Comment', with: '&'
page.within('.timeline-content-form') do
note.native.send_keys('&')
end
wait_for_requests wait_for_requests
expect(find('.tribute-container ul', visible: true).text).to have_content(epic.title) expect(find_tribute_autocomplete_menu).to have_text(epic.title)
end end
end end
end end
private
def find_autocomplete_menu
find('.atwho-view ul', visible: true)
end
def find_highlighted_autocomplete_item
find('.atwho-view li.cur', visible: true)
end
def find_tribute_autocomplete_menu
find('.tribute-container ul', visible: true)
end
end end
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'Issue markdown toolbar', :js do RSpec.describe 'Issue markdown toolbar', :js do
let(:project) { create(:project, :public) } let_it_be(:project) { create(:project, :public) }
let(:issue) { create(:issue, project: project) } let_it_be(:issue) { create(:issue, project: project) }
let(:user) { create(:user) } let_it_be(:user) { create(:user) }
before do before do
sign_in(user) sign_in(user)
...@@ -14,28 +14,22 @@ RSpec.describe 'Issue markdown toolbar', :js do ...@@ -14,28 +14,22 @@ RSpec.describe 'Issue markdown toolbar', :js do
end end
it "doesn't include first new line when adding bold" do it "doesn't include first new line when adding bold" do
find('#note-body').native.send_keys('test') fill_in 'Comment', with: "test\nbold"
find('#note-body').native.send_key(:enter)
find('#note-body').native.send_keys('bold')
find('.js-main-target-form #note-body') page.evaluate_script('document.getElementById("note-body").setSelectionRange(4, 9)')
page.evaluate_script('document.querySelectorAll(".js-main-target-form #note-body")[0].setSelectionRange(4, 9)')
first('.toolbar-btn').click click_button 'Add bold text'
expect(find('#note-body')[:value]).to eq("test\n**bold**\n") expect(find_field('Comment').value).to eq("test\n**bold**\n")
end end
it "doesn't include first new line when adding underline" do it "doesn't include first new line when adding underline" do
find('#note-body').native.send_keys('test') fill_in 'Comment', with: "test\nunderline"
find('#note-body').native.send_key(:enter)
find('#note-body').native.send_keys('underline')
find('.js-main-target-form #note-body') page.evaluate_script('document.getElementById("note-body").setSelectionRange(4, 50)')
page.evaluate_script('document.querySelectorAll(".js-main-target-form #note-body")[0].setSelectionRange(4, 50)')
all('.toolbar-btn')[1].click click_button 'Add italic text'
expect(find('#note-body')[:value]).to eq("test\n_underline_\n") expect(find_field('Comment').value).to eq("test\n_underline_\n")
end end
end end
...@@ -57,17 +57,9 @@ RSpec.describe "User comments on issue", :js do ...@@ -57,17 +57,9 @@ RSpec.describe "User comments on issue", :js do
project.add_maintainer(user) project.add_maintainer(user)
create(:label, project: project, title: 'label') create(:label, project: project, title: 'label')
page.within '.timeline-content-form' do fill_in 'Comment', with: '/l'
find('#note-body').native.send_keys('/l')
end
wait_for_requests
expect(page).to have_selector('.atwho-container')
page.within '.atwho-container #at-view-commands' do expect(find_highlighted_autocomplete_item).to have_content('/label')
expect(find('li', match: :first)).to have_content('/label')
end
end end
end end
...@@ -110,4 +102,10 @@ RSpec.describe "User comments on issue", :js do ...@@ -110,4 +102,10 @@ RSpec.describe "User comments on issue", :js do
end end
end end
end end
private
def find_highlighted_autocomplete_item
find('.atwho-view li.cur', visible: true)
end
end end
...@@ -142,10 +142,8 @@ RSpec.describe "Issues > User edits issue", :js do ...@@ -142,10 +142,8 @@ RSpec.describe "Issues > User edits issue", :js do
it 'can remove label without removing label added via quick action', :aggregate_failures do it 'can remove label without removing label added via quick action', :aggregate_failures do
# Add `syzygy` label with a quick action # Add `syzygy` label with a quick action
note = find('#note-body') fill_in 'Comment', with: '/label ~syzygy'
page.within '.timeline-content-form' do
note.native.send_keys('/label ~syzygy')
end
click_button 'Comment' click_button 'Comment'
wait_for_requests wait_for_requests
......
...@@ -182,9 +182,9 @@ RSpec.describe 'Merge request > User posts notes', :js do ...@@ -182,9 +182,9 @@ RSpec.describe 'Merge request > User posts notes', :js do
find('.js-note-edit').click find('.js-note-edit').click
page.within('.current-note-edit-form') do page.within('.current-note-edit-form') do
expect(find('#note_note').value).to include('This is the new content') expect(find_field('note[note]').value).to include('This is the new content')
first('.js-md').click first('.js-md').click
expect(find('#note_note').value).to include('This is the new content****') expect(find_field('note[note]').value).to include('This is the new content****')
end end
end end
......
...@@ -28,8 +28,8 @@ RSpec.describe 'Merge request > User sees notes from forked project', :js do ...@@ -28,8 +28,8 @@ RSpec.describe 'Merge request > User sees notes from forked project', :js do
page.within('.discussion-notes') do page.within('.discussion-notes') do
find_field('Reply…').click find_field('Reply…').click
scroll_to(page.find('#note_note', visible: false)) scroll_to(find_field('note[note]', visible: false))
find('#note_note').send_keys('A reply comment') fill_in 'note[note]', with: 'A reply comment'
find('.js-comment-button').click find('.js-comment-button').click
end end
......
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'Member autocomplete', :js do RSpec.describe 'Member autocomplete', :js do
let(:project) { create(:project, :public) } let_it_be(:project) { create(:project, :public, :repository) }
let(:user) { create(:user) } let_it_be(:user) { create(:user) }
let(:author) { create(:user) } let_it_be(:author) { create(:user) }
let(:note) { create(:note, noteable: noteable, project: noteable.project) } let(:note) { create(:note, noteable: noteable, project: noteable.project) }
before do before do
...@@ -15,20 +15,16 @@ RSpec.describe 'Member autocomplete', :js do ...@@ -15,20 +15,16 @@ RSpec.describe 'Member autocomplete', :js do
shared_examples "open suggestions when typing @" do |resource_name| shared_examples "open suggestions when typing @" do |resource_name|
before do before do
page.within('.new-note') do if resource_name == 'commit'
if resource_name == 'commit' fill_in 'note[note]', with: '@'
find('#note_note').send_keys('@') else
else fill_in 'Comment', with: '@'
find('#note-body').send_keys('@')
end
end end
end end
it 'suggests noteable author and note author' do it 'suggests noteable author and note author' do
page.within('.atwho-view', visible: true) do expect(find_autocomplete_menu).to have_text(author.username)
expect(page).to have_content(author.username) expect(find_autocomplete_menu).to have_text(note.author.username)
expect(page).to have_content(note.author.username)
end
end end
end end
...@@ -51,22 +47,17 @@ RSpec.describe 'Member autocomplete', :js do ...@@ -51,22 +47,17 @@ RSpec.describe 'Member autocomplete', :js do
stub_feature_flags(tribute_autocomplete: true) stub_feature_flags(tribute_autocomplete: true)
visit project_issue_path(project, noteable) visit project_issue_path(project, noteable)
page.within('.new-note') do fill_in 'Comment', with: '@'
find('#note-body').send_keys('@')
end
end end
it 'suggests noteable author and note author' do it 'suggests noteable author and note author' do
page.within('.tribute-container', visible: true) do expect(find_tribute_autocomplete_menu).to have_content(author.username)
expect(page).to have_content(author.username) expect(find_tribute_autocomplete_menu).to have_content(note.author.username)
expect(page).to have_content(note.author.username)
end
end end
end end
end end
context 'adding a new note on a Merge Request' do context 'adding a new note on a Merge Request' do
let(:project) { create(:project, :public, :repository) }
let(:noteable) do let(:noteable) do
create(:merge_request, source_project: project, create(:merge_request, source_project: project,
target_project: project, author: author) target_project: project, author: author)
...@@ -80,7 +71,6 @@ RSpec.describe 'Member autocomplete', :js do ...@@ -80,7 +71,6 @@ RSpec.describe 'Member autocomplete', :js do
end end
context 'adding a new note on a Commit' do context 'adding a new note on a Commit' do
let(:project) { create(:project, :public, :repository) }
let(:noteable) { project.commit } let(:noteable) { project.commit }
let(:note) { create(:note_on_commit, project: project, commit_id: project.commit.id) } let(:note) { create(:note_on_commit, project: project, commit_id: project.commit.id) }
...@@ -94,4 +84,14 @@ RSpec.describe 'Member autocomplete', :js do ...@@ -94,4 +84,14 @@ RSpec.describe 'Member autocomplete', :js do
include_examples "open suggestions when typing @", 'commit' include_examples "open suggestions when typing @", 'commit'
end end
private
def find_autocomplete_menu
find('.atwho-view ul', visible: true)
end
def find_tribute_autocomplete_menu
find('.tribute-container ul', visible: true)
end
end end
...@@ -29,7 +29,6 @@ RSpec.describe 'Projects > Snippets > User comments on a snippet', :js do ...@@ -29,7 +29,6 @@ RSpec.describe 'Projects > Snippets > User comments on a snippet', :js do
end end
it 'has autocomplete' do it 'has autocomplete' do
find('#note_note').native.send_keys('')
fill_in 'note[note]', with: '@' fill_in 'note[note]', with: '@'
expect(page).to have_selector('.atwho-view') expect(page).to have_selector('.atwho-view')
......
...@@ -108,9 +108,6 @@ RSpec.describe 'Comments on personal snippets', :js do ...@@ -108,9 +108,6 @@ RSpec.describe 'Comments on personal snippets', :js do
end end
it 'does not have autocomplete' do it 'does not have autocomplete' do
wait_for_requests
find('#note_note').native.send_keys('')
fill_in 'note[note]', with: '@' fill_in 'note[note]', with: '@'
wait_for_requests wait_for_requests
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment