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
let(:user) { create(:user) }
before do
stub_feature_flags(tribute_autocomplete: false)
sign_in(user)
end
......@@ -51,13 +53,10 @@ RSpec.describe 'Issue promotion', :js do
visit project_issue_path(project, issue)
end
it 'displays warning' do
note = find('#note-body')
type(note, '/promote')
wait_for_requests
it 'displays description' do
fill_in 'Comment', with: '/promote'
expect(page).to have_content 'Promote issue to an epic'
expect(find_autocomplete_menu).to have_text 'Promote issue to an epic'
end
it 'promotes the issue' do
......@@ -100,12 +99,9 @@ RSpec.describe 'Issue promotion', :js do
end
it 'displays warning' do
note = find('#note-body')
type(note, '/promote')
fill_in 'Comment', with: '/promote'
wait_for_requests
expect(page).to have_content 'Promote confidential issue to a non-confidential epic'
expect(find_autocomplete_menu).to have_text 'Promote confidential issue to a non-confidential epic'
end
it 'promotes the issue' do
......@@ -124,12 +120,7 @@ RSpec.describe 'Issue promotion', :js do
private
# `note` is a textarea where the given text should be typed.
# We don't want to find it each time this function gets called.
def type(note, text)
page.within('.timeline-content-form') do
note.set('')
note.native.send_keys(text)
end
def find_autocomplete_menu
find('.atwho-view ul', visible: true)
end
end
......@@ -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(:another_user) { create(:user, name: 'another user', username: 'another.user') }
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(:project) { create(:project, group: group) }
let_it_be(:issue) { create(:issue, project: project, assignees: [user]) }
before do
project.add_maintainer(user)
end
context 'assignees' do
let(:issue_assignee) { create(:issue, project: project) }
describe 'when tribute_autocomplete feature flag is off' do
before do
stub_feature_flags(tribute_autocomplete: false)
issue_assignee.update!(assignees: [user])
sign_in(user)
visit project_issue_path(project, issue_assignee)
wait_for_requests
visit project_issue_path(project, issue)
end
it 'only lists users who are currently assigned to the issue when using /unassign' do
note = find('#note-body')
page.within '.timeline-content-form' do
note.native.send_keys('/una')
end
fill_in 'Comment', with: '/una'
find('.atwho-view li', text: '/unassign')
note.native.send_keys(:tab)
find_highlighted_autocomplete_item.click
wait_for_requests
users = find('#at-view-users .atwho-view-ul')
expect(users).to have_content(user.username)
expect(users).not_to have_content(another_user.username)
expect(find_autocomplete_menu).to have_text(user.username)
expect(find_autocomplete_menu).not_to have_text(another_user.username)
end
end
......@@ -51,40 +41,45 @@ RSpec.describe 'GFM autocomplete EE', :js do
stub_licensed_features(epics: true)
stub_feature_flags(tribute_autocomplete: true)
issue_assignee.update!(assignees: [user])
sign_in(user)
visit project_issue_path(project, issue_assignee)
wait_for_requests
visit project_issue_path(project, issue)
end
it 'only lists users who are currently assigned to the issue when using /unassign' do
note = find('#note-body')
page.within '.timeline-content-form' do
note.native.send_keys('/unassign ')
# 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
wait_for_requests
note.native.send_keys('@')
wait_for_requests
end
users = find('.tribute-container ul', visible: true)
expect(users).to have_content(user.username)
expect(users).not_to have_content(another_user.username)
note = find_field('Comment')
note.native.send_keys('/unassign ')
# 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
wait_for_requests
note.native.send_keys('@')
wait_for_requests
expect(find_tribute_autocomplete_menu).to have_text(user.username)
expect(find_tribute_autocomplete_menu).not_to have_text(another_user.username)
end
it 'shows epics' do
note = find('#note-body')
page.within('.timeline-content-form') do
note.native.send_keys('&')
end
fill_in 'Comment', with: '&'
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
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
......@@ -3,9 +3,9 @@
require 'spec_helper'
RSpec.describe 'Issue markdown toolbar', :js do
let(:project) { create(:project, :public) }
let(:issue) { create(:issue, project: project) }
let(:user) { create(:user) }
let_it_be(:project) { create(:project, :public) }
let_it_be(:issue) { create(:issue, project: project) }
let_it_be(:user) { create(:user) }
before do
sign_in(user)
......@@ -14,28 +14,22 @@ RSpec.describe 'Issue markdown toolbar', :js do
end
it "doesn't include first new line when adding bold" do
find('#note-body').native.send_keys('test')
find('#note-body').native.send_key(:enter)
find('#note-body').native.send_keys('bold')
fill_in 'Comment', with: "test\nbold"
find('.js-main-target-form #note-body')
page.evaluate_script('document.querySelectorAll(".js-main-target-form #note-body")[0].setSelectionRange(4, 9)')
page.evaluate_script('document.getElementById("note-body").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
it "doesn't include first new line when adding underline" do
find('#note-body').native.send_keys('test')
find('#note-body').native.send_key(:enter)
find('#note-body').native.send_keys('underline')
fill_in 'Comment', with: "test\nunderline"
find('.js-main-target-form #note-body')
page.evaluate_script('document.querySelectorAll(".js-main-target-form #note-body")[0].setSelectionRange(4, 50)')
page.evaluate_script('document.getElementById("note-body").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
......@@ -57,17 +57,9 @@ RSpec.describe "User comments on issue", :js do
project.add_maintainer(user)
create(:label, project: project, title: 'label')
page.within '.timeline-content-form' do
find('#note-body').native.send_keys('/l')
end
wait_for_requests
expect(page).to have_selector('.atwho-container')
fill_in 'Comment', with: '/l'
page.within '.atwho-container #at-view-commands' do
expect(find('li', match: :first)).to have_content('/label')
end
expect(find_highlighted_autocomplete_item).to have_content('/label')
end
end
......@@ -110,4 +102,10 @@ RSpec.describe "User comments on issue", :js do
end
end
end
private
def find_highlighted_autocomplete_item
find('.atwho-view li.cur', visible: true)
end
end
......@@ -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
# Add `syzygy` label with a quick action
note = find('#note-body')
page.within '.timeline-content-form' do
note.native.send_keys('/label ~syzygy')
end
fill_in 'Comment', with: '/label ~syzygy'
click_button 'Comment'
wait_for_requests
......
......@@ -182,9 +182,9 @@ RSpec.describe 'Merge request > User posts notes', :js do
find('.js-note-edit').click
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
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
......
......@@ -28,8 +28,8 @@ RSpec.describe 'Merge request > User sees notes from forked project', :js do
page.within('.discussion-notes') do
find_field('Reply…').click
scroll_to(page.find('#note_note', visible: false))
find('#note_note').send_keys('A reply comment')
scroll_to(find_field('note[note]', visible: false))
fill_in 'note[note]', with: 'A reply comment'
find('.js-comment-button').click
end
......
......@@ -3,9 +3,9 @@
require 'spec_helper'
RSpec.describe 'Member autocomplete', :js do
let(:project) { create(:project, :public) }
let(:user) { create(:user) }
let(:author) { create(:user) }
let_it_be(:project) { create(:project, :public, :repository) }
let_it_be(:user) { create(:user) }
let_it_be(:author) { create(:user) }
let(:note) { create(:note, noteable: noteable, project: noteable.project) }
before do
......@@ -15,20 +15,16 @@ RSpec.describe 'Member autocomplete', :js do
shared_examples "open suggestions when typing @" do |resource_name|
before do
page.within('.new-note') do
if resource_name == 'commit'
find('#note_note').send_keys('@')
else
find('#note-body').send_keys('@')
end
if resource_name == 'commit'
fill_in 'note[note]', with: '@'
else
fill_in 'Comment', with: '@'
end
end
it 'suggests noteable author and note author' do
page.within('.atwho-view', visible: true) do
expect(page).to have_content(author.username)
expect(page).to have_content(note.author.username)
end
expect(find_autocomplete_menu).to have_text(author.username)
expect(find_autocomplete_menu).to have_text(note.author.username)
end
end
......@@ -51,22 +47,17 @@ RSpec.describe 'Member autocomplete', :js do
stub_feature_flags(tribute_autocomplete: true)
visit project_issue_path(project, noteable)
page.within('.new-note') do
find('#note-body').send_keys('@')
end
fill_in 'Comment', with: '@'
end
it 'suggests noteable author and note author' do
page.within('.tribute-container', visible: true) do
expect(page).to have_content(author.username)
expect(page).to have_content(note.author.username)
end
expect(find_tribute_autocomplete_menu).to have_content(author.username)
expect(find_tribute_autocomplete_menu).to have_content(note.author.username)
end
end
end
context 'adding a new note on a Merge Request' do
let(:project) { create(:project, :public, :repository) }
let(:noteable) do
create(:merge_request, source_project: project,
target_project: project, author: author)
......@@ -80,7 +71,6 @@ RSpec.describe 'Member autocomplete', :js do
end
context 'adding a new note on a Commit' do
let(:project) { create(:project, :public, :repository) }
let(:noteable) { project.commit }
let(:note) { create(:note_on_commit, project: project, commit_id: project.commit.id) }
......@@ -94,4 +84,14 @@ RSpec.describe 'Member autocomplete', :js do
include_examples "open suggestions when typing @", 'commit'
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
......@@ -29,7 +29,6 @@ RSpec.describe 'Projects > Snippets > User comments on a snippet', :js do
end
it 'has autocomplete' do
find('#note_note').native.send_keys('')
fill_in 'note[note]', with: '@'
expect(page).to have_selector('.atwho-view')
......
......@@ -108,9 +108,6 @@ RSpec.describe 'Comments on personal snippets', :js do
end
it 'does not have autocomplete' do
wait_for_requests
find('#note_note').native.send_keys('')
fill_in 'note[note]', with: '@'
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