Commit 72ffc05f authored by Coung Ngo's avatar Coung Ngo

Re-organise `gfm_autocomplete_spec.rb` spec

Refactor the file to organise tests into related sections

- autocomplete highlighting
- assignees
parent c2734e5e
......@@ -117,12 +117,6 @@ RSpec.describe 'GFM autocomplete', :js do
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
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)
......@@ -153,20 +147,29 @@ RSpec.describe 'GFM autocomplete', :js do
expect(find_autocomplete_menu).to have_text('alert milestone')
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: ':'
wait_for_requests
expect(find_autocomplete_menu).not_to have_css('.cur')
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
it 'selects the first item for assignee dropdowns' do
fill_in 'Comment', with: '@'
describe 'assignees' do
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
it 'includes items for assignee dropdowns with non-ASCII characters in name' do
......@@ -215,12 +218,16 @@ RSpec.describe 'GFM autocomplete', :js do
expect(find_field('Comment').value).not_to have_text '@undefined'
end
it 'selects the first item for non-assignee dropdowns if a query is entered' do
fill_in 'Comment', with: ':1'
context 'when /assign quick action is selected' do
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
context 'if a selected value has special characters' do
......@@ -232,14 +239,6 @@ RSpec.describe 'GFM autocomplete', :js do
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]}"
find_highlighted_autocomplete_item.click
expect(find_field('Comment').value).to have_text("@#{user.username}")
end
it 'doesn\'t wrap for emoji values' do
fill_in 'Comment', with: ':cartwheel_'
......@@ -263,17 +262,6 @@ RSpec.describe 'GFM autocomplete', :js do
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
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'
......@@ -498,12 +486,6 @@ RSpec.describe 'GFM autocomplete', :js do
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
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)
......@@ -534,28 +516,33 @@ RSpec.describe 'GFM autocomplete', :js do
expect(find_tribute_autocomplete_menu).to have_text('alert milestone')
end
it 'selects the first item for assignee dropdowns' do
fill_in 'Comment', with: '@'
describe 'autocomplete highlighting' do
it 'auto-selects the first item with query', :aggregate_failures do
fill_in 'Comment', with: ':1'
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')
end
end
it 'includes items for assignee dropdowns with non-ASCII characters in name' do
fill_in 'Comment', with: "@#{user.name[0...8]}"
describe 'assignees' do
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
it 'selects the first item for non-assignee dropdowns if a query is entered' do
fill_in 'Comment', with: ':1'
it 'includes items for assignee dropdowns with non-ASCII characters in name' do
fill_in 'Comment', with: "@#{user.name[0...8]}"
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
context 'when autocompleting for groups' do
......@@ -572,42 +559,8 @@ RSpec.describe 'GFM autocomplete', :js do
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 '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
context 'when /assign quick action is selected' do
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
......@@ -635,6 +588,33 @@ RSpec.describe 'GFM autocomplete', :js do
expect(find_tribute_autocomplete_menu).to have_text(user2.username)
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
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