2019-07-25 01:24:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 03:56:52 -04:00
|
|
|
require 'spec_helper'
|
2016-07-21 07:42:37 -04:00
|
|
|
|
2020-06-16 14:09:01 -04:00
|
|
|
RSpec.describe 'GFM autocomplete', :js do
|
2020-06-29 11:08:56 -04:00
|
|
|
let_it_be(:user) { create(:user, name: '💃speciąl someone💃', username: 'someone.special') }
|
2021-02-22 13:10:55 -05:00
|
|
|
let_it_be(:user2) { create(:user, name: 'Marge Simpson', username: 'msimpson') }
|
2021-03-24 14:09:31 -04:00
|
|
|
|
2022-02-10 10:12:42 -05:00
|
|
|
let_it_be(:group) { create(:group, :crm_enabled) }
|
|
|
|
let_it_be(:project) { create(:project, group: group) }
|
2021-03-24 14:09:31 -04:00
|
|
|
let_it_be(:issue) { create(:issue, project: project, assignees: [user]) }
|
|
|
|
let_it_be(:label) { create(:label, project: project, title: 'special+') }
|
2021-04-07 08:08:53 -04:00
|
|
|
let_it_be(:label_scoped) { create(:label, project: project, title: 'scoped::label') }
|
|
|
|
let_it_be(:label_with_spaces) { create(:label, project: project, title: 'Accepting merge requests') }
|
2021-03-24 14:09:31 -04:00
|
|
|
let_it_be(:snippet) { create(:project_snippet, project: project, title: 'code snippet') }
|
2016-07-21 07:42:37 -04:00
|
|
|
|
2021-04-07 08:08:53 -04:00
|
|
|
let_it_be(:user_xss_title) { 'eve <img src=x onerror=alert(2)<img src=x onerror=alert(1)>' }
|
|
|
|
let_it_be(:user_xss) { create(:user, name: user_xss_title, username: 'xss.user') }
|
|
|
|
let_it_be(:label_xss_title) { 'alert label <img src=x onerror="alert(\'Hello xss\');" a' }
|
|
|
|
let_it_be(:label_xss) { create(:label, project: project, title: label_xss_title) }
|
|
|
|
|
2020-06-29 11:08:56 -04:00
|
|
|
before_all do
|
2022-02-10 10:12:42 -05:00
|
|
|
group.add_maintainer(user)
|
|
|
|
group.add_maintainer(user_xss)
|
|
|
|
group.add_maintainer(user2)
|
2020-06-29 11:08:56 -04:00
|
|
|
end
|
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
describe 'new issue page' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
visit new_project_issue_path(project)
|
2021-03-24 14:09:31 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
wait_for_requests
|
|
|
|
end
|
2018-11-12 04:21:25 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
it 'allows quick actions' do
|
|
|
|
fill_in 'Description', with: '/'
|
2016-07-21 07:42:37 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
expect(find_autocomplete_menu).to be_visible
|
2020-06-19 08:09:07 -04:00
|
|
|
end
|
2022-01-27 13:14:37 -05:00
|
|
|
end
|
2017-07-07 13:08:39 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
describe 'issue description' do
|
|
|
|
let(:issue_to_edit) { create(:issue, project: project) }
|
2021-03-24 14:09:31 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
visit project_issue_path(project, issue_to_edit)
|
2021-03-24 14:09:31 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
wait_for_requests
|
|
|
|
end
|
2021-03-24 14:09:31 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
it 'updates with GFM reference' do
|
|
|
|
click_button 'Edit title and description'
|
2021-03-24 14:09:31 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
wait_for_requests
|
2019-09-18 10:02:45 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
fill_in 'Description', with: "@#{user.name[0...3]}"
|
2017-07-07 13:08:39 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
wait_for_requests
|
2018-12-11 07:22:08 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
find_highlighted_autocomplete_item.click
|
2017-07-07 13:08:39 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
click_button 'Save changes'
|
2018-12-11 07:22:08 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
wait_for_requests
|
2017-07-07 13:08:39 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
expect(find('.description')).to have_text(user.to_reference)
|
|
|
|
end
|
2021-03-16 20:09:06 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
it 'allows quick actions' do
|
|
|
|
click_button 'Edit title and description'
|
2021-03-16 20:09:06 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
fill_in 'Description', with: '/'
|
2021-03-16 20:09:06 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
expect(find_autocomplete_menu).to be_visible
|
2016-07-21 07:42:37 -04:00
|
|
|
end
|
2022-01-27 13:14:37 -05:00
|
|
|
end
|
2016-07-21 07:42:37 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
describe 'issue comment' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
visit project_issue_path(project, issue)
|
2021-03-16 20:09:06 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
wait_for_requests
|
|
|
|
end
|
2020-06-29 11:08:56 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
describe 'triggering autocomplete' do
|
|
|
|
it 'only opens autocomplete menu when trigger character is after whitespace', :aggregate_failures do
|
|
|
|
fill_in 'Comment', with: 'testing@'
|
|
|
|
expect(page).not_to have_css('.atwho-view')
|
2018-10-19 06:14:17 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
fill_in 'Comment', with: '@@'
|
|
|
|
expect(page).not_to have_css('.atwho-view')
|
2018-10-19 06:14:17 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
fill_in 'Comment', with: "@#{user.username[0..2]}!"
|
|
|
|
expect(page).not_to have_css('.atwho-view')
|
2018-12-11 07:22:08 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
fill_in 'Comment', with: "hello:#{user.username[0..2]}"
|
|
|
|
expect(page).not_to have_css('.atwho-view')
|
2018-10-19 06:14:17 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
fill_in 'Comment', with: '7:'
|
|
|
|
expect(page).not_to have_css('.atwho-view')
|
2018-11-12 04:21:25 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
fill_in 'Comment', with: 'w:'
|
|
|
|
expect(page).not_to have_css('.atwho-view')
|
2018-11-12 04:21:25 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
fill_in 'Comment', with: 'Ё:'
|
|
|
|
expect(page).not_to have_css('.atwho-view')
|
2020-06-19 08:09:07 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
fill_in 'Comment', with: "test\n\n@"
|
|
|
|
expect(find_autocomplete_menu).to be_visible
|
2022-02-23 19:18:13 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not open label autocomplete menu after strikethrough', :aggregate_failures do
|
|
|
|
fill_in 'Comment', with: "~~"
|
|
|
|
expect(page).not_to have_css('.atwho-view')
|
|
|
|
|
|
|
|
fill_in 'Comment', with: "~~gone~~"
|
|
|
|
expect(page).not_to have_css('.atwho-view')
|
|
|
|
|
|
|
|
fill_in 'Comment', with: "~"
|
|
|
|
expect(find_autocomplete_menu).to be_visible
|
|
|
|
|
|
|
|
fill_in 'Comment', with: "test\n\n~"
|
|
|
|
expect(find_autocomplete_menu).to be_visible
|
2021-03-24 14:09:31 -04:00
|
|
|
end
|
2022-01-27 13:14:37 -05:00
|
|
|
end
|
2018-12-11 07:22:08 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
context 'xss checks' 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)<img src=x onerror=alert(1)>'
|
|
|
|
create(:issue, project: project, title: issue_xss_title)
|
2021-04-07 08:08:53 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
fill_in 'Comment', with: '#'
|
2021-04-07 08:08:53 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
wait_for_requests
|
2017-01-18 07:17:24 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
expect(find_autocomplete_menu).to have_text(issue_xss_title)
|
2021-03-24 14:09:31 -04:00
|
|
|
end
|
2017-01-18 07:17:24 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
it 'opens autocomplete menu for Username when field starts with text with item escaping HTML characters' do
|
|
|
|
fill_in 'Comment', with: '@ev'
|
2017-01-23 18:30:03 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
wait_for_requests
|
2021-01-28 07:09:54 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
expect(find_highlighted_autocomplete_item).to have_text(user_xss.username)
|
2021-03-24 14:09:31 -04:00
|
|
|
end
|
2021-01-28 07:09:54 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
it 'opens autocomplete menu for Milestone when field starts with text with item escaping HTML characters' do
|
|
|
|
milestone_xss_title = 'alert milestone <img src=x onerror="alert(\'Hello xss\');" a'
|
|
|
|
create(:milestone, project: project, title: milestone_xss_title)
|
2021-02-22 13:10:55 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
fill_in 'Comment', with: '%'
|
2021-02-22 13:10:55 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
wait_for_requests
|
2020-06-19 08:09:07 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
expect(find_autocomplete_menu).to have_text('alert milestone')
|
2016-12-23 04:05:01 -05:00
|
|
|
end
|
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
it 'opens autocomplete menu for Labels when field starts with text with item escaping HTML characters' do
|
|
|
|
fill_in 'Comment', with: '~'
|
2020-06-19 08:09:07 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
wait_for_requests
|
2020-06-19 08:09:07 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
expect(find_autocomplete_menu).to have_text('alert label')
|
2021-03-24 14:09:31 -04:00
|
|
|
end
|
2022-01-27 13:14:37 -05:00
|
|
|
end
|
2021-03-03 19:11:19 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
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')
|
2020-06-19 08:09:07 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
fill_in 'Comment', with: ':1'
|
|
|
|
wait_for_requests
|
|
|
|
expect(find_autocomplete_menu).to have_css('.cur:first-of-type')
|
2020-06-19 08:09:07 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
fill_in 'Comment', with: '@'
|
|
|
|
wait_for_requests
|
|
|
|
expect(find_autocomplete_menu).to have_css('.cur:first-of-type')
|
|
|
|
end
|
|
|
|
end
|
2020-06-19 08:09:07 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
describe 'assignees' do
|
|
|
|
it 'does not wrap with quotes for assignee values' do
|
|
|
|
fill_in 'Comment', with: "@#{user.username}"
|
2020-06-19 08:09:07 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
find_highlighted_autocomplete_item.click
|
2020-06-19 08:09:07 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
expect(find_field('Comment').value).to have_text("@#{user.username}")
|
2020-06-19 08:09:07 -04:00
|
|
|
end
|
2020-02-05 16:09:02 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
it 'includes items for assignee dropdowns with non-ASCII characters in name' do
|
|
|
|
fill_in 'Comment', with: "@#{user.name[0...8]}"
|
2020-12-15 13:10:06 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
wait_for_requests
|
2020-12-15 13:10:06 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
expect(find_autocomplete_menu).to have_text(user.name)
|
|
|
|
end
|
2020-12-15 13:10:06 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
it 'searches across full name for assignees' do
|
|
|
|
fill_in 'Comment', with: '@speciąlsome'
|
2020-12-15 13:10:06 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
wait_for_requests
|
2020-12-15 13:10:06 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
expect(find_highlighted_autocomplete_item).to have_text(user.name)
|
2020-12-15 13:10:06 -05:00
|
|
|
end
|
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
it 'shows names that start with the query as the top result' do
|
|
|
|
fill_in 'Comment', with: '@mar'
|
2020-03-23 17:09:46 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
wait_for_requests
|
2020-06-19 08:09:07 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
expect(find_highlighted_autocomplete_item).to have_text(user2.name)
|
2020-02-05 16:09:02 -05:00
|
|
|
end
|
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
it 'shows usernames that start with the query as the top result' do
|
|
|
|
fill_in 'Comment', with: '@msi'
|
2020-06-19 08:09:07 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
wait_for_requests
|
2020-02-05 16:09:02 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
expect(find_highlighted_autocomplete_item).to have_text(user2.name)
|
2021-03-24 14:09:31 -04:00
|
|
|
end
|
2020-03-23 17:09:46 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
# Regression test for https://gitlab.com/gitlab-org/gitlab/-/issues/321925
|
|
|
|
it 'shows username when pasting then pressing Enter' do
|
|
|
|
fill_in 'Comment', with: "@#{user.username}\n"
|
2020-03-23 17:09:46 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
expect(find_field('Comment').value).to have_text "@#{user.username}"
|
2021-03-24 14:09:31 -04:00
|
|
|
end
|
2020-06-19 08:09:07 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
it 'does not show `@undefined` when pressing `@` then Enter' do
|
|
|
|
fill_in 'Comment', with: "@\n"
|
2021-03-10 07:09:14 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
expect(find_field('Comment').value).to have_text '@'
|
|
|
|
expect(find_field('Comment').value).not_to have_text '@undefined'
|
|
|
|
end
|
2021-03-10 07:09:14 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
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'
|
2021-03-10 07:09:14 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
find_highlighted_autocomplete_item.click
|
2021-03-10 07:09:14 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
expect(find_autocomplete_menu).not_to have_text(user.username)
|
|
|
|
expect(find_autocomplete_menu).to have_text(user2.username)
|
2021-03-10 07:09:14 -05:00
|
|
|
end
|
|
|
|
end
|
2020-02-05 16:09:02 -05:00
|
|
|
end
|
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
context 'if a selected value has special characters' do
|
|
|
|
it 'wraps the result in double quotes' do
|
|
|
|
fill_in 'Comment', with: "~#{label.title[0..2]}"
|
2018-12-11 07:22:08 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
find_highlighted_autocomplete_item.click
|
2021-03-24 14:09:31 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
expect(find_field('Comment').value).to have_text("~\"#{label.title}\"")
|
2021-03-24 14:09:31 -04:00
|
|
|
end
|
2019-06-25 06:19:29 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
it 'doesn\'t wrap for emoji values' do
|
|
|
|
fill_in 'Comment', with: ':cartwheel_'
|
2020-06-19 08:09:07 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
find_highlighted_autocomplete_item.click
|
2021-03-16 20:09:06 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
expect(find_field('Comment').value).to have_text('cartwheel_tone1')
|
2021-03-16 20:09:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
context 'quick actions' do
|
|
|
|
it 'does not limit quick actions autocomplete list to 5' do
|
|
|
|
fill_in 'Comment', with: '/'
|
2019-06-25 06:19:29 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
expect(find_autocomplete_menu).to have_css('li', minimum: 6)
|
2021-03-16 20:09:06 -04:00
|
|
|
end
|
2022-01-27 13:14:37 -05:00
|
|
|
end
|
2020-06-19 08:09:07 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
context 'labels' do
|
|
|
|
it 'allows colons when autocompleting scoped labels' do
|
|
|
|
fill_in 'Comment', with: '~scoped:'
|
2020-08-18 14:10:10 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
wait_for_requests
|
2019-06-25 06:19:29 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
expect(find_autocomplete_menu).to have_text('scoped::label')
|
2021-03-24 14:09:31 -04:00
|
|
|
end
|
2019-06-25 06:19:29 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
it 'allows spaces when autocompleting multi-word labels' do
|
|
|
|
fill_in 'Comment', with: '~Accepting merge'
|
2019-06-25 06:19:29 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
wait_for_requests
|
2020-09-24 08:09:37 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
expect(find_autocomplete_menu).to have_text('Accepting merge requests')
|
2020-09-24 08:09:37 -04:00
|
|
|
end
|
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
it 'only autocompletes the last label' do
|
|
|
|
fill_in 'Comment', with: '~scoped:: foo bar ~Accepting merge'
|
2020-09-24 08:09:37 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
wait_for_requests
|
2020-07-31 11:10:14 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
expect(find_autocomplete_menu).to have_text('Accepting merge requests')
|
|
|
|
end
|
2018-10-05 05:42:38 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
it 'does not autocomplete labels if no tilde is typed' do
|
|
|
|
fill_in 'Comment', with: 'Accepting merge'
|
2021-03-24 14:09:31 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
wait_for_requests
|
2018-11-19 09:46:34 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
expect(page).not_to have_css('.atwho-view')
|
2020-06-19 08:09:07 -04:00
|
|
|
end
|
2022-01-27 13:14:37 -05:00
|
|
|
end
|
2018-11-19 09:46:34 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
context 'when other notes are destroyed' do
|
|
|
|
let!(:discussion) { create(:discussion_note_on_issue, noteable: issue, project: issue.project) }
|
2020-12-17 07:09:57 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
# This is meant to protect against this issue https://gitlab.com/gitlab-org/gitlab/-/issues/228729
|
|
|
|
it 'keeps autocomplete key listeners' do
|
|
|
|
note = find_field('Comment')
|
2020-12-17 07:09:57 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
start_comment_with_emoji(note, '.atwho-view li')
|
2020-12-17 07:09:57 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
start_and_cancel_discussion
|
2020-06-19 08:09:07 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
note.fill_in(with: '')
|
|
|
|
start_comment_with_emoji(note, '.atwho-view li')
|
|
|
|
note.native.send_keys(:enter)
|
2020-06-19 08:09:07 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
expect(note.value).to eql('Hello :100: ')
|
2021-04-07 08:08:53 -04:00
|
|
|
end
|
2022-01-27 13:14:37 -05:00
|
|
|
end
|
2018-11-19 09:46:34 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
shared_examples 'autocomplete suggestions' do
|
|
|
|
it 'suggests objects correctly' do
|
|
|
|
fill_in 'Comment', with: object.class.reference_prefix
|
2020-06-19 08:09:07 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
find_autocomplete_menu.find('li').click
|
2021-03-03 19:11:19 -05:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
expect(find_field('Comment').value).to have_text(expected_body)
|
2020-07-31 11:10:14 -04:00
|
|
|
end
|
2022-01-27 13:14:37 -05:00
|
|
|
end
|
2020-07-31 11:10:14 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
context 'issues' do
|
|
|
|
let(:object) { issue }
|
|
|
|
let(:expected_body) { object.to_reference }
|
2020-07-31 11:10:14 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
it_behaves_like 'autocomplete suggestions'
|
|
|
|
end
|
2020-07-31 11:10:14 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
context 'merge requests' do
|
|
|
|
let(:object) { create(:merge_request, source_project: project) }
|
|
|
|
let(:expected_body) { object.to_reference }
|
2020-07-31 11:10:14 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
it_behaves_like 'autocomplete suggestions'
|
|
|
|
end
|
2020-07-31 11:10:14 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
context 'project snippets' do
|
|
|
|
let!(:object) { snippet }
|
|
|
|
let(:expected_body) { object.to_reference }
|
2020-07-31 11:10:14 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
it_behaves_like 'autocomplete suggestions'
|
|
|
|
end
|
2020-07-31 11:10:14 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
context 'milestone' do
|
|
|
|
let_it_be(:milestone_expired) { create(:milestone, project: project, due_date: 5.days.ago) }
|
|
|
|
let_it_be(:milestone_no_duedate) { create(:milestone, project: project, title: 'Foo - No due date') }
|
|
|
|
let_it_be(:milestone1) { create(:milestone, project: project, title: 'Milestone-1', due_date: 20.days.from_now) }
|
|
|
|
let_it_be(:milestone2) { create(:milestone, project: project, title: 'Milestone-2', due_date: 15.days.from_now) }
|
|
|
|
let_it_be(:milestone3) { create(:milestone, project: project, title: 'Milestone-3', due_date: 10.days.from_now) }
|
2020-07-31 11:10:14 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
before do
|
|
|
|
fill_in 'Comment', with: '/milestone %'
|
2020-07-31 11:10:14 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
wait_for_requests
|
2020-06-19 08:09:07 -04:00
|
|
|
end
|
2020-07-22 05:09:38 -04:00
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
it 'shows milestons list in the autocomplete menu' do
|
|
|
|
page.within(find_autocomplete_menu) do
|
|
|
|
expect(page).to have_selector('li', count: 5)
|
2021-03-24 14:09:31 -04:00
|
|
|
end
|
2020-12-17 07:09:57 -05:00
|
|
|
end
|
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
it 'shows expired milestone at the bottom of the list' do
|
|
|
|
page.within(find_autocomplete_menu) do
|
|
|
|
expect(page.find('li:last-child')).to have_content milestone_expired.title
|
2021-03-24 14:09:31 -04:00
|
|
|
end
|
2020-09-01 20:10:29 -04:00
|
|
|
end
|
|
|
|
|
2022-01-27 13:14:37 -05:00
|
|
|
it 'shows milestone due earliest at the top of the list' do
|
|
|
|
page.within(find_autocomplete_menu) do
|
|
|
|
aggregate_failures do
|
|
|
|
expect(page.all('li')[0]).to have_content milestone3.title
|
|
|
|
expect(page.all('li')[1]).to have_content milestone2.title
|
|
|
|
expect(page.all('li')[2]).to have_content milestone1.title
|
|
|
|
expect(page.all('li')[3]).to have_content milestone_no_duedate.title
|
|
|
|
end
|
|
|
|
end
|
2021-03-24 14:09:31 -04:00
|
|
|
end
|
2020-11-11 04:09:06 -05:00
|
|
|
end
|
2022-02-10 10:12:42 -05:00
|
|
|
|
|
|
|
context 'contact' do
|
|
|
|
let_it_be(:contacts) { create_list(:contact, 2, group: group) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
fill_in 'Comment', with: '/add_contacts [contact:'
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows contacts list in the autocomplete menu' do
|
|
|
|
page.within(find_autocomplete_menu) do
|
|
|
|
expect(page).to have_selector('li', count: 2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows all contacts' do
|
|
|
|
page.within(find_autocomplete_menu) do
|
|
|
|
expected_data = contacts.map { |c| "#{c.first_name} #{c.last_name} #{c.email}"}
|
|
|
|
|
|
|
|
expect(page.all('li').map(&:text)).to match_array(expected_data)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-02-24 19:17:32 -05:00
|
|
|
|
|
|
|
context 'when typing enter for autocomplete in a markdown list' do
|
|
|
|
it 'does not create a new list item' do
|
|
|
|
fill_in 'Comment', with: "- @#{user.username}\n"
|
|
|
|
|
|
|
|
expect(find_field('Comment').value).to eq "- @#{user.username}\n"
|
|
|
|
end
|
|
|
|
end
|
2018-11-19 09:46:34 -05:00
|
|
|
end
|
|
|
|
|
2017-11-27 22:51:03 -05:00
|
|
|
private
|
|
|
|
|
2020-12-17 07:09:57 -05:00
|
|
|
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
|
2021-03-03 19:11:19 -05:00
|
|
|
fill_in('Reply to comment', with: 'Whoops!')
|
2022-01-25 16:15:18 -05:00
|
|
|
click_button('Cancel')
|
2020-12-17 07:09:57 -05:00
|
|
|
|
2022-01-25 16:15:18 -05:00
|
|
|
page.within('.modal') do
|
2022-05-12 14:08:38 -04:00
|
|
|
click_button('Discard changes', match: :first)
|
2020-12-17 07:09:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
end
|
2021-02-22 13:10:55 -05:00
|
|
|
|
2021-03-03 19:11:19 -05:00
|
|
|
def find_autocomplete_menu
|
|
|
|
find('.atwho-view ul', visible: true)
|
|
|
|
end
|
|
|
|
|
2021-02-22 13:10:55 -05:00
|
|
|
def find_highlighted_autocomplete_item
|
|
|
|
find('.atwho-view li.cur', visible: true)
|
|
|
|
end
|
2016-07-21 07:42:37 -04:00
|
|
|
end
|