Commit 25828de6 authored by Kerri Miller's avatar Kerri Miller

Merge branch 'cngo-organize-gfm-autocomplete_specrb' into 'master'

Re-organise `gfm_autocomplete_spec.rb` spec

See merge request gitlab-org/gitlab!57698
parents eaebd64a 72ffc05f
...@@ -117,12 +117,6 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -117,12 +117,6 @@ RSpec.describe 'GFM autocomplete', :js do
end end
end end
it 'opens autocomplete menu when field starts with text' do
fill_in 'Comment', with: '@'
expect(find_autocomplete_menu).to be_visible
end
it 'opens autocomplete menu for Issues when field starts with text with item escaping HTML characters' do it 'opens autocomplete menu for Issues when field starts with text with item escaping HTML characters' do
issue_xss_title = 'This will execute alert<img src=x onerror=alert(2)&lt;img src=x onerror=alert(1)&gt;' issue_xss_title = 'This will execute alert<img src=x onerror=alert(2)&lt;img src=x onerror=alert(1)&gt;'
create(:issue, project: project, title: issue_xss_title) create(:issue, project: project, title: issue_xss_title)
...@@ -153,74 +147,87 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -153,74 +147,87 @@ RSpec.describe 'GFM autocomplete', :js do
expect(find_autocomplete_menu).to have_text('alert milestone') expect(find_autocomplete_menu).to have_text('alert milestone')
end end
it 'doesnt select the first item for non-assignee dropdowns' do describe 'autocomplete highlighting' do
fill_in 'Comment', with: ':' it 'auto-selects the first item when there is a query, and only for assignees with no query', :aggregate_failures do
fill_in 'Comment', with: ':'
wait_for_requests
expect(find_autocomplete_menu).not_to have_css('.cur')
wait_for_requests fill_in 'Comment', with: ':1'
wait_for_requests
expect(find_autocomplete_menu).to have_css('.cur:first-of-type')
expect(find_autocomplete_menu).not_to have_css('.cur') fill_in 'Comment', with: '@'
wait_for_requests
expect(find_autocomplete_menu).to have_css('.cur:first-of-type')
end
end end
it 'selects the first item for assignee dropdowns' do describe 'assignees' do
fill_in 'Comment', with: '@' it 'does not wrap with quotes for assignee values' do
fill_in 'Comment', with: "@#{user.username[0]}"
wait_for_requests find_highlighted_autocomplete_item.click
expect(find_autocomplete_menu).to have_css('.cur:first-of-type') expect(find_field('Comment').value).to have_text("@#{user.username}")
end end
it 'includes items for assignee dropdowns with non-ASCII characters in name' do it 'includes items for assignee dropdowns with non-ASCII characters in name' do
fill_in 'Comment', with: "@#{user.name[0...8]}" fill_in 'Comment', with: "@#{user.name[0...8]}"
wait_for_requests wait_for_requests
expect(find_autocomplete_menu).to have_text(user.name) expect(find_autocomplete_menu).to have_text(user.name)
end end
it 'searches across full name for assignees' do it 'searches across full name for assignees' do
fill_in 'Comment', with: '@speciąlsome' fill_in 'Comment', with: '@speciąlsome'
wait_for_requests wait_for_requests
expect(find_highlighted_autocomplete_item).to have_text(user.name) expect(find_highlighted_autocomplete_item).to have_text(user.name)
end end
it 'shows names that start with the query as the top result' do it 'shows names that start with the query as the top result' do
fill_in 'Comment', with: '@mar' fill_in 'Comment', with: '@mar'
wait_for_requests wait_for_requests
expect(find_highlighted_autocomplete_item).to have_text(user2.name) expect(find_highlighted_autocomplete_item).to have_text(user2.name)
end end
it 'shows usernames that start with the query as the top result' do it 'shows usernames that start with the query as the top result' do
fill_in 'Comment', with: '@msi' fill_in 'Comment', with: '@msi'
wait_for_requests wait_for_requests
expect(find_highlighted_autocomplete_item).to have_text(user2.name) expect(find_highlighted_autocomplete_item).to have_text(user2.name)
end end
# Regression test for https://gitlab.com/gitlab-org/gitlab/-/issues/321925 # Regression test for https://gitlab.com/gitlab-org/gitlab/-/issues/321925
it 'shows username when pasting then pressing Enter' do it 'shows username when pasting then pressing Enter' do
fill_in 'Comment', with: "@#{user.username}\n" fill_in 'Comment', with: "@#{user.username}\n"
expect(find_field('Comment').value).to have_text "@#{user.username}" expect(find_field('Comment').value).to have_text "@#{user.username}"
end end
it 'does not show `@undefined` when pressing `@` then Enter' do it 'does not show `@undefined` when pressing `@` then Enter' do
fill_in 'Comment', with: "@\n" fill_in 'Comment', with: "@\n"
expect(find_field('Comment').value).to have_text '@' expect(find_field('Comment').value).to have_text '@'
expect(find_field('Comment').value).not_to have_text '@undefined' expect(find_field('Comment').value).not_to have_text '@undefined'
end end
it 'selects the first item for non-assignee dropdowns if a query is entered' do context 'when /assign quick action is selected' do
fill_in 'Comment', with: ':1' it 'triggers user autocomplete and lists users who are currently not assigned to the issue' do
fill_in 'Comment', with: '/as'
wait_for_requests find_highlighted_autocomplete_item.click
expect(find_autocomplete_menu).to have_css('.cur:first-of-type') expect(find_autocomplete_menu).not_to have_text(user.username)
expect(find_autocomplete_menu).to have_text(user2.username)
end
end
end end
context 'if a selected value has special characters' do context 'if a selected value has special characters' do
...@@ -232,14 +239,6 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -232,14 +239,6 @@ RSpec.describe 'GFM autocomplete', :js do
expect(find_field('Comment').value).to have_text("~\"#{label.title}\"") expect(find_field('Comment').value).to have_text("~\"#{label.title}\"")
end end
it 'doesn\'t wrap for assignee values' do
fill_in 'Comment', with: "@#{user.username[0]}"
find_highlighted_autocomplete_item.click
expect(find_field('Comment').value).to have_text("@#{user.username}")
end
it 'doesn\'t wrap for emoji values' do it 'doesn\'t wrap for emoji values' do
fill_in 'Comment', with: ':cartwheel_' fill_in 'Comment', with: ':cartwheel_'
...@@ -263,17 +262,6 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -263,17 +262,6 @@ RSpec.describe 'GFM autocomplete', :js do
end end
end end
context 'assignees' do
it 'lists users who are currently not assigned to the issue when using /assign' do
fill_in 'Comment', with: '/as'
find_highlighted_autocomplete_item.click
expect(find_autocomplete_menu).not_to have_text(user.username)
expect(find_autocomplete_menu).to have_text(user2.username)
end
end
context 'labels' do context 'labels' do
it 'opens autocomplete menu for Labels when field starts with text with item escaping HTML characters' do it 'opens autocomplete menu for Labels when field starts with text with item escaping HTML characters' do
label_xss_title = 'alert label &lt;img src=x onerror="alert(\'Hello xss\');" a' label_xss_title = 'alert label &lt;img src=x onerror="alert(\'Hello xss\');" a'
...@@ -498,12 +486,6 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -498,12 +486,6 @@ RSpec.describe 'GFM autocomplete', :js do
end end
end end
it 'opens autocomplete menu when field starts with text' do
fill_in 'Comment', with: '@'
expect(find_tribute_autocomplete_menu).to be_visible
end
it 'opens autocomplete menu for Issues when field starts with text with item escaping HTML characters' do it 'opens autocomplete menu for Issues when field starts with text with item escaping HTML characters' do
issue_xss_title = 'This will execute alert<img src=x onerror=alert(2)&lt;img src=x onerror=alert(1)&gt;' issue_xss_title = 'This will execute alert<img src=x onerror=alert(2)&lt;img src=x onerror=alert(1)&gt;'
create(:issue, project: project, title: issue_xss_title) create(:issue, project: project, title: issue_xss_title)
...@@ -534,41 +516,77 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -534,41 +516,77 @@ RSpec.describe 'GFM autocomplete', :js do
expect(find_tribute_autocomplete_menu).to have_text('alert milestone') expect(find_tribute_autocomplete_menu).to have_text('alert milestone')
end end
it 'selects the first item for assignee dropdowns' do describe 'autocomplete highlighting' do
fill_in 'Comment', with: '@' it 'auto-selects the first item with query', :aggregate_failures do
fill_in 'Comment', with: ':1'
wait_for_requests wait_for_requests
expect(find_tribute_autocomplete_menu).to have_css('.highlight:first-of-type')
expect(find_tribute_autocomplete_menu).to have_css('.highlight:first-of-type') fill_in 'Comment', with: '@'
wait_for_requests
expect(find_tribute_autocomplete_menu).to have_css('.highlight:first-of-type')
end
end end
it 'includes items for assignee dropdowns with non-ASCII characters in name' do describe 'assignees' do
fill_in 'Comment', with: "@#{user.name[0...8]}" it 'does not wrap with quotes for assignee values' do
fill_in 'Comment', with: "@#{user.username[0..2]}"
wait_for_requests find_highlighted_tribute_autocomplete_menu.click
expect(find_tribute_autocomplete_menu).to have_text(user.name) expect(find_field('Comment').value).to have_text("@#{user.username}")
end end
it 'selects the first item for non-assignee dropdowns if a query is entered' do it 'includes items for assignee dropdowns with non-ASCII characters in name' do
fill_in 'Comment', with: ':1' fill_in 'Comment', with: "@#{user.name[0...8]}"
wait_for_requests wait_for_requests
expect(find_tribute_autocomplete_menu).to have_css('.highlight:first-of-type') expect(find_tribute_autocomplete_menu).to have_text(user.name)
end end
context 'when autocompleting for groups' do
it 'shows the group when searching for the name of the group' do
fill_in 'Comment', with: '@mygroup'
context 'when autocompleting for groups' do expect(find_tribute_autocomplete_menu).to have_text('My group')
it 'shows the group when searching for the name of the group' do end
fill_in 'Comment', with: '@mygroup'
it 'does not show the group when searching for the name of the parent of the group' do
fill_in 'Comment', with: '@ancestor'
expect(find_tribute_autocomplete_menu).to have_text('My group') expect(find_tribute_autocomplete_menu).not_to have_text('My group')
end
end end
it 'does not show the group when searching for the name of the parent of the group' do context 'when /assign quick action is selected' do
fill_in 'Comment', with: '@ancestor' it 'lists users who are currently not assigned to the issue' do
note = find_field('Comment')
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
expect(find_tribute_autocomplete_menu).not_to have_text('My group') expect(find_tribute_autocomplete_menu).not_to have_text(user.username)
expect(find_tribute_autocomplete_menu).to have_text(user2.username)
end
it 'lists users who are currently not assigned to the issue when using /assign on the second line' do
note = find_field('Comment')
note.native.send_keys('/assign @user2')
note.native.send_keys(:enter)
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
expect(find_tribute_autocomplete_menu).not_to have_text(user.username)
expect(find_tribute_autocomplete_menu).to have_text(user2.username)
end
end end
end end
...@@ -581,14 +599,6 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -581,14 +599,6 @@ RSpec.describe 'GFM autocomplete', :js do
expect(find_field('Comment').value).to have_text("~\"#{label.title}\"") expect(find_field('Comment').value).to have_text("~\"#{label.title}\"")
end end
it 'doesn\'t wrap for assignee values' do
fill_in 'Comment', with: "@#{user.username[0..2]}"
find_highlighted_tribute_autocomplete_menu.click
expect(find_field('Comment').value).to have_text("@#{user.username}")
end
it 'does not wrap for emoji values' do it 'does not wrap for emoji values' do
fill_in 'Comment', with: ':cartwheel_' fill_in 'Comment', with: ':cartwheel_'
...@@ -606,36 +616,6 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -606,36 +616,6 @@ RSpec.describe 'GFM autocomplete', :js do
end end
end end
context 'assignees' do
it 'lists users who are currently not assigned to the issue when using /assign' do
note = find_field('Comment')
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
expect(find_tribute_autocomplete_menu).not_to have_text(user.username)
expect(find_tribute_autocomplete_menu).to have_text(user2.username)
end
it 'lists users who are currently not assigned to the issue when using /assign on the second line' do
note = find_field('Comment')
note.native.send_keys('/assign @user2')
note.native.send_keys(:enter)
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
expect(find_tribute_autocomplete_menu).not_to have_text(user.username)
expect(find_tribute_autocomplete_menu).to have_text(user2.username)
end
end
context 'labels' do context 'labels' do
it 'opens autocomplete menu for Labels when field starts with text with item escaping HTML characters' do it 'opens autocomplete menu for Labels when field starts with text with item escaping HTML characters' do
label_xss_title = 'alert label &lt;img src=x onerror="alert(\'Hello xss\');" a' label_xss_title = 'alert label &lt;img src=x onerror="alert(\'Hello xss\');" a'
......
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