summaryrefslogtreecommitdiff
path: root/spec/features/issues/gfm_autocomplete_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/features/issues/gfm_autocomplete_spec.rb')
-rw-r--r--spec/features/issues/gfm_autocomplete_spec.rb163
1 files changed, 122 insertions, 41 deletions
diff --git a/spec/features/issues/gfm_autocomplete_spec.rb b/spec/features/issues/gfm_autocomplete_spec.rb
index 07bf821a590..9b2a11c4b0e 100644
--- a/spec/features/issues/gfm_autocomplete_spec.rb
+++ b/spec/features/issues/gfm_autocomplete_spec.rb
@@ -294,6 +294,15 @@ RSpec.describe 'GFM autocomplete', :js do
user_item = find('.atwho-view li', text: user.username)
expect(user_item).to have_content(user.username)
end
+
+ it 'does not limit quick actions autocomplete list to 5' do
+ note = find('#note-body')
+ page.within '.timeline-content-form' do
+ note.native.send_keys('/')
+ end
+
+ expect(page).to have_selector('.atwho-view li', minimum: 6, visible: true)
+ end
end
context 'assignees' do
@@ -426,36 +435,16 @@ RSpec.describe 'GFM autocomplete', :js do
visit project_issue_path(project, issue)
note = find('#note-body')
- start_comment_with_emoji(note)
+ start_comment_with_emoji(note, '.atwho-view li')
start_and_cancel_discussion
note.fill_in(with: '')
- start_comment_with_emoji(note)
+ start_comment_with_emoji(note, '.atwho-view li')
note.native.send_keys(:enter)
expect(note.value).to eql('Hello :100: ')
end
-
- def start_comment_with_emoji(note)
- note.native.send_keys('Hello :10')
-
- wait_for_requests
-
- find('.atwho-view li', text: '100')
- end
-
- def start_and_cancel_discussion
- click_button('Reply...')
-
- fill_in('note_note', with: 'Whoops!')
-
- page.accept_alert 'Are you sure you want to cancel creating this comment?' do
- click_button('Cancel')
- end
-
- wait_for_requests
- end
end
shared_examples 'autocomplete suggestions' do
@@ -599,6 +588,33 @@ RSpec.describe 'GFM autocomplete', :js do
expect(page).not_to have_selector('.tribute-container', visible: true)
end
+ it 'does not open autocomplete menu when ":" is prefixed by a number and letters' do
+ note = find('#note-body')
+
+ # Number.
+ page.within '.timeline-content-form' do
+ note.native.send_keys('7:')
+ end
+
+ expect(page).not_to have_selector('.tribute-container', visible: true)
+
+ # ASCII letter.
+ page.within '.timeline-content-form' do
+ note.set('')
+ note.native.send_keys('w:')
+ end
+
+ expect(page).not_to have_selector('.tribute-container', visible: true)
+
+ # Non-ASCII letter.
+ page.within '.timeline-content-form' do
+ note.set('')
+ note.native.send_keys('Ё:')
+ end
+
+ expect(page).not_to have_selector('.tribute-container', visible: true)
+ end
+
it 'selects the first item for assignee dropdowns' do
page.within '.timeline-content-form' do
find('#note-body').native.send_keys('@')
@@ -624,6 +640,16 @@ RSpec.describe 'GFM autocomplete', :js do
expect(find('.tribute-container ul', visible: true)).to have_content(user.name)
end
+ it 'selects the first item for non-assignee dropdowns if a query is entered' do
+ page.within '.timeline-content-form' do
+ find('#note-body').native.send_keys(':1')
+ end
+
+ wait_for_requests
+
+ expect(find('.tribute-container ul', visible: true)).to have_selector('.highlight:first-of-type')
+ end
+
context 'when autocompleting for groups' do
it 'shows the group when searching for the name of the group' do
page.within '.timeline-content-form' do
@@ -687,20 +713,34 @@ RSpec.describe 'GFM autocomplete', :js do
expect_to_wrap(false, user_item, note, user.username)
end
- it 'triggers autocomplete after selecting a quick action' do
+ it 'does not wrap for emoji values' do
note = find('#note-body')
page.within '.timeline-content-form' do
- note.native.send_keys('/as')
+ note.native.send_keys(":cartwheel_")
end
- find('.atwho-view li', text: '/assign')
- note.native.send_keys(:tab)
- note.native.send_keys(:right)
+ emoji_item = first('.tribute-container li', text: 'cartwheel_tone1', visible: true)
- wait_for_requests
+ expect_to_wrap(false, emoji_item, note, 'cartwheel_tone1')
+ end
- user_item = find('.tribute-container ul', text: user.username, visible: true)
- expect(user_item).to have_content(user.username)
+ it 'does not open autocomplete if there is no space before' do
+ page.within '.timeline-content-form' do
+ find('#note-body').native.send_keys("hello:#{user.username[0..2]}")
+ end
+
+ expect(page).not_to have_selector('.tribute-container')
+ end
+
+ it 'autocompletes for quick actions' do
+ note = find('#note-body')
+ page.within '.timeline-content-form' do
+ note.native.send_keys('/as')
+ wait_for_requests
+ note.native.send_keys(:tab)
+ end
+
+ expect(note.value).to have_text('/assign')
end
end
@@ -719,15 +759,14 @@ RSpec.describe 'GFM autocomplete', :js do
note = find('#note-body')
page.within '.timeline-content-form' do
- note.native.send_keys('/as')
+ note.native.send_keys('/assign ')
+ # The `/assign` 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
- find('.atwho-view li', text: '/assign')
- note.native.send_keys(:tab)
- note.native.send_keys(:right)
-
- wait_for_requests
-
expect(find('.tribute-container ul', visible: true)).not_to have_content(user.username)
expect(find('.tribute-container ul', visible: true)).to have_content(unassigned_user.username)
end
@@ -739,12 +778,14 @@ RSpec.describe 'GFM autocomplete', :js do
page.within '.timeline-content-form' do
note.native.send_keys('/assign @user2')
note.native.send_keys(:enter)
- note.native.send_keys('/assign @')
- note.native.send_keys(:right)
+ note.native.send_keys('/assign ')
+ # The `/assign` 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
- wait_for_requests
-
expect(find('.tribute-container ul', visible: true)).not_to have_content(user.username)
expect(find('.tribute-container ul', visible: true)).to have_content(unassigned_user.username)
end
@@ -824,6 +865,26 @@ RSpec.describe 'GFM autocomplete', :js do
end
end
+ context 'when other notes are destroyed' do
+ let!(:discussion) { create(:discussion_note_on_issue, noteable: issue, project: issue.project) }
+
+ # This is meant to protect against this issue https://gitlab.com/gitlab-org/gitlab/-/issues/228729
+ it 'keeps autocomplete key listeners' do
+ visit project_issue_path(project, issue)
+ note = find('#note-body')
+
+ start_comment_with_emoji(note, '.tribute-container li')
+
+ start_and_cancel_discussion
+
+ note.fill_in(with: '')
+ start_comment_with_emoji(note, '.tribute-container li')
+ note.native.send_keys(:enter)
+
+ expect(note.value).to eql('Hello :100: ')
+ end
+ end
+
shared_examples 'autocomplete suggestions' do
it 'suggests objects correctly' do
page.within '.timeline-content-form' do
@@ -913,4 +974,24 @@ RSpec.describe 'GFM autocomplete', :js do
note.native.send_keys(text)
end
end
+
+ def start_comment_with_emoji(note, selector)
+ note.native.send_keys('Hello :10')
+
+ wait_for_requests
+
+ find(selector, text: '100')
+ end
+
+ def start_and_cancel_discussion
+ click_button('Reply...')
+
+ fill_in('note_note', with: 'Whoops!')
+
+ page.accept_alert 'Are you sure you want to cancel creating this comment?' do
+ click_button('Cancel')
+ end
+
+ wait_for_requests
+ end
end