2016-07-21 07:42:37 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
feature 'GFM autocomplete', feature: true, js: true do
|
2016-08-30 08:49:31 -04:00
|
|
|
include WaitForAjax
|
2016-12-03 05:44:18 -05:00
|
|
|
let(:user) { create(:user, username: 'someone.special') }
|
2016-07-21 07:42:37 -04:00
|
|
|
let(:project) { create(:project) }
|
2016-12-03 05:44:18 -05:00
|
|
|
let(:label) { create(:label, project: project, title: 'special+') }
|
2016-07-21 07:42:37 -04:00
|
|
|
let(:issue) { create(:issue, project: project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.team << [user, :master]
|
|
|
|
login_as(user)
|
|
|
|
visit namespace_project_issue_path(project.namespace, project, issue)
|
|
|
|
|
2016-08-30 08:49:31 -04:00
|
|
|
wait_for_ajax
|
2016-07-21 09:41:27 -04:00
|
|
|
end
|
2016-07-21 07:42:37 -04:00
|
|
|
|
2016-07-21 09:41:27 -04:00
|
|
|
it 'opens autocomplete menu when field starts with text' do
|
2016-07-21 07:42:37 -04:00
|
|
|
page.within '.timeline-content-form' do
|
2016-07-21 09:41:27 -04:00
|
|
|
find('#note_note').native.send_keys('')
|
2016-07-21 07:42:37 -04:00
|
|
|
find('#note_note').native.send_keys('@')
|
|
|
|
end
|
|
|
|
|
2016-11-14 05:34:10 -05:00
|
|
|
expect(page).to have_selector('.atwho-container')
|
2016-07-21 07:42:37 -04:00
|
|
|
end
|
2016-07-21 09:41:27 -04:00
|
|
|
|
2016-12-03 05:44:18 -05:00
|
|
|
it 'doesnt open autocomplete menu character is prefixed with text' do
|
2016-07-21 09:41:27 -04:00
|
|
|
page.within '.timeline-content-form' do
|
2016-12-03 05:44:18 -05:00
|
|
|
find('#note_note').native.send_keys('testing')
|
2016-07-21 09:41:27 -04:00
|
|
|
find('#note_note').native.send_keys('@')
|
|
|
|
end
|
|
|
|
|
2016-12-03 05:44:18 -05:00
|
|
|
expect(page).not_to have_selector('.atwho-view')
|
2016-07-21 09:41:27 -04:00
|
|
|
end
|
|
|
|
|
2016-12-03 05:44:18 -05:00
|
|
|
context 'if a selected value has special characters' do
|
|
|
|
it 'wraps the result in double quotes' do
|
|
|
|
note = find('#note_note')
|
|
|
|
page.within '.timeline-content-form' do
|
|
|
|
note.native.send_keys('')
|
|
|
|
note.native.send_keys("~#{label.title[0]}")
|
|
|
|
sleep 1
|
|
|
|
note.click
|
|
|
|
end
|
|
|
|
|
|
|
|
label_item = find('.atwho-view li', text: label.title)
|
|
|
|
|
|
|
|
expect_to_wrap(true, label_item, note, label.title)
|
2016-07-21 09:41:27 -04:00
|
|
|
end
|
|
|
|
|
2016-12-03 05:44:18 -05:00
|
|
|
it 'doesn\'t wrap for assignee values' do
|
|
|
|
note = find('#note_note')
|
|
|
|
page.within '.timeline-content-form' do
|
|
|
|
note.native.send_keys('')
|
|
|
|
note.native.send_keys("@#{user.username[0]}")
|
|
|
|
sleep 1
|
|
|
|
note.click
|
|
|
|
end
|
|
|
|
|
|
|
|
user_item = find('.atwho-view li', text: user.username)
|
|
|
|
|
|
|
|
expect_to_wrap(false, user_item, note, user.username)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'doesn\'t wrap for emoji values' do
|
|
|
|
note = find('#note_note')
|
|
|
|
page.within '.timeline-content-form' do
|
|
|
|
note.native.send_keys('')
|
|
|
|
note.native.send_keys(":cartwheel")
|
|
|
|
sleep 1
|
|
|
|
note.click
|
|
|
|
end
|
|
|
|
|
|
|
|
emoji_item = find('.atwho-view li', text: 'cartwheel_tone1')
|
|
|
|
|
|
|
|
expect_to_wrap(false, emoji_item, note, 'cartwheel_tone1')
|
|
|
|
end
|
|
|
|
|
|
|
|
def expect_to_wrap(should_wrap, item, note, value)
|
|
|
|
expect(item).to have_content(value)
|
|
|
|
expect(item).not_to have_content("\"#{value}\"")
|
|
|
|
|
|
|
|
item.click
|
|
|
|
|
|
|
|
if should_wrap
|
|
|
|
expect(note.value).to include("\"#{value}\"")
|
|
|
|
else
|
|
|
|
expect(note.value).not_to include("\"#{value}\"")
|
|
|
|
end
|
|
|
|
end
|
2016-07-21 09:41:27 -04:00
|
|
|
end
|
2016-12-12 09:32:03 -05:00
|
|
|
|
|
|
|
it 'doesnt open autocomplete after non-word character' do
|
|
|
|
page.within '.timeline-content-form' do
|
|
|
|
find('#note_note').native.send_keys("@#{user.username[0..2]}!")
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(page).not_to have_selector('.atwho-view')
|
|
|
|
end
|
2016-07-21 07:42:37 -04:00
|
|
|
end
|