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,20 +147,29 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -153,20 +147,29 @@ 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
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: ':' fill_in 'Comment', with: ':'
wait_for_requests
expect(find_autocomplete_menu).not_to have_css('.cur')
fill_in 'Comment', with: ':1'
wait_for_requests 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
...@@ -215,12 +218,16 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -215,12 +218,16 @@ RSpec.describe 'GFM autocomplete', :js do
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,28 +516,33 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -534,28 +516,33 @@ 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')
fill_in 'Comment', with: '@'
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')
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 context 'when autocompleting for groups' do
...@@ -572,42 +559,8 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -572,42 +559,8 @@ RSpec.describe 'GFM autocomplete', :js do
end end
end end
context 'if a selected value has special characters' do context 'when /assign quick action is selected' do
it 'wraps the result in double quotes' do it 'lists users who are currently not assigned to the issue' do
fill_in 'Comment', with: "~#{label.title[0]}"
find_highlighted_tribute_autocomplete_menu.click
expect(find_field('Comment').value).to have_text("~\"#{label.title}\"")
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
fill_in 'Comment', with: ':cartwheel_'
find_highlighted_tribute_autocomplete_menu.click
expect(find_field('Comment').value).to have_text('cartwheel_tone1')
end
it 'autocompletes for quick actions' do
fill_in 'Comment', with: '/as'
find_highlighted_tribute_autocomplete_menu.click
expect(find_field('Comment').value).to have_text('/assign')
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 = find_field('Comment')
note.native.send_keys('/assign ') note.native.send_keys('/assign ')
# The `/assign` ajax response might replace the one by `@` below causing a failed test # The `/assign` ajax response might replace the one by `@` below causing a failed test
...@@ -635,6 +588,33 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -635,6 +588,33 @@ RSpec.describe 'GFM autocomplete', :js do
expect(find_tribute_autocomplete_menu).to have_text(user2.username) expect(find_tribute_autocomplete_menu).to have_text(user2.username)
end end
end end
end
context 'if a selected value has special characters' do
it 'wraps the result in double quotes' do
fill_in 'Comment', with: "~#{label.title[0]}"
find_highlighted_tribute_autocomplete_menu.click
expect(find_field('Comment').value).to have_text("~\"#{label.title}\"")
end
it 'does not wrap for emoji values' do
fill_in 'Comment', with: ':cartwheel_'
find_highlighted_tribute_autocomplete_menu.click
expect(find_field('Comment').value).to have_text('cartwheel_tone1')
end
it 'autocompletes for quick actions' do
fill_in 'Comment', with: '/as'
find_highlighted_tribute_autocomplete_menu.click
expect(find_field('Comment').value).to have_text('/assign')
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
......
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