2016-07-18 12:23:45 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2017-06-29 04:13:10 +00:00
|
|
|
describe 'New/edit issue', :js do
|
2017-04-18 18:01:15 +00:00
|
|
|
include ActionView::Helpers::JavaScriptHelper
|
2017-05-26 21:27:30 +00:00
|
|
|
include FormHelper
|
2017-03-09 00:14:16 +00:00
|
|
|
|
2017-08-02 19:55:11 +00:00
|
|
|
let!(:project) { create(:project) }
|
2016-07-18 12:23:45 +00:00
|
|
|
let!(:user) { create(:user)}
|
2017-02-22 07:26:32 +00:00
|
|
|
let!(:user2) { create(:user)}
|
2016-07-18 12:23:45 +00:00
|
|
|
let!(:milestone) { create(:milestone, project: project) }
|
|
|
|
let!(:label) { create(:label, project: project) }
|
|
|
|
let!(:label2) { create(:label, project: project) }
|
2017-05-04 12:11:15 +00:00
|
|
|
let!(:issue) { create(:issue, project: project, assignees: [user], milestone: milestone) }
|
2016-07-18 12:23:45 +00:00
|
|
|
|
|
|
|
before do
|
2018-07-11 14:36:08 +00:00
|
|
|
project.add_maintainer(user)
|
|
|
|
project.add_maintainer(user2)
|
2017-06-21 23:44:10 +00:00
|
|
|
sign_in(user)
|
2016-07-18 12:23:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'new issue' do
|
|
|
|
before do
|
2017-07-06 16:20:50 +00:00
|
|
|
visit new_project_issue_path(project)
|
2016-07-18 12:23:45 +00:00
|
|
|
end
|
|
|
|
|
2017-07-05 20:09:15 +00:00
|
|
|
describe 'shorten users API pagination limit' do
|
2017-05-26 21:27:30 +00:00
|
|
|
before do
|
2017-06-02 16:19:33 +00:00
|
|
|
# Using `allow_any_instance_of`/`and_wrap_original`, `original` would
|
|
|
|
# somehow refer to the very block we defined to _wrap_ that method, instead of
|
2018-11-15 10:13:50 +00:00
|
|
|
# the original method, resulting in infinite recursion when called.
|
2017-06-02 16:19:33 +00:00
|
|
|
# This is likely a bug with helper modules included into dynamically generated view classes.
|
|
|
|
# To work around this, we have to hold on to and call to the original implementation manually.
|
2017-05-31 13:59:01 +00:00
|
|
|
original_issue_dropdown_options = FormHelper.instance_method(:issue_assignees_dropdown_options)
|
|
|
|
allow_any_instance_of(FormHelper).to receive(:issue_assignees_dropdown_options).and_wrap_original do |original, *args|
|
2017-06-02 16:19:33 +00:00
|
|
|
options = original_issue_dropdown_options.bind(original.receiver).call(*args)
|
|
|
|
options[:data][:per_page] = 2
|
2017-05-26 21:27:30 +00:00
|
|
|
|
|
|
|
options
|
|
|
|
end
|
|
|
|
|
2017-07-06 16:20:50 +00:00
|
|
|
visit new_project_issue_path(project)
|
2017-05-26 21:27:30 +00:00
|
|
|
|
|
|
|
click_button 'Unassigned'
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should display selected users even if they are not part of the original API call' do
|
|
|
|
find('.dropdown-input-field').native.send_keys user2.name
|
|
|
|
|
|
|
|
page.within '.dropdown-menu-user' do
|
|
|
|
expect(page).to have_content user2.name
|
|
|
|
click_link user2.name
|
|
|
|
end
|
|
|
|
|
2017-06-02 16:19:33 +00:00
|
|
|
find('.js-assignee-search').click
|
2017-05-26 21:27:30 +00:00
|
|
|
find('.js-dropdown-input-clear').click
|
|
|
|
|
|
|
|
page.within '.dropdown-menu-user' do
|
|
|
|
expect(page).to have_content user.name
|
|
|
|
expect(find('.dropdown-menu-user a.is-active').first(:xpath, '..')['data-user-id']).to eq(user2.id.to_s)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-05 20:09:15 +00:00
|
|
|
describe 'single assignee' do
|
2017-05-16 19:51:15 +00:00
|
|
|
before do
|
2017-05-08 22:13:11 +00:00
|
|
|
click_button 'Unassigned'
|
2017-05-16 18:55:59 +00:00
|
|
|
|
2017-05-17 18:25:13 +00:00
|
|
|
wait_for_requests
|
2017-05-04 12:11:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'unselects other assignees when unassigned is selected' do
|
|
|
|
page.within '.dropdown-menu-user' do
|
|
|
|
click_link user2.name
|
|
|
|
end
|
|
|
|
|
2017-05-16 19:51:15 +00:00
|
|
|
click_button user2.name
|
|
|
|
|
2017-05-04 12:11:15 +00:00
|
|
|
page.within '.dropdown-menu-user' do
|
|
|
|
click_link 'Unassigned'
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(find('input[name="issue[assignee_ids][]"]', visible: false).value).to match('0')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'toggles assign to me when current user is selected and unselected' do
|
|
|
|
page.within '.dropdown-menu-user' do
|
|
|
|
click_link user.name
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(find('a', text: 'Assign to me', visible: false)).not_to be_visible
|
2017-05-08 22:13:11 +00:00
|
|
|
|
2017-05-16 19:51:15 +00:00
|
|
|
click_button user.name
|
|
|
|
|
2017-05-08 22:13:11 +00:00
|
|
|
page.within('.dropdown-menu-user') do
|
|
|
|
click_link user.name
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(page.find('.dropdown-menu-user', visible: false)).not_to be_visible
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-21 07:52:37 +00:00
|
|
|
it 'allows user to create new issue' do
|
2016-07-18 12:23:45 +00:00
|
|
|
fill_in 'issue_title', with: 'title'
|
|
|
|
fill_in 'issue_description', with: 'title'
|
|
|
|
|
2017-02-22 07:26:32 +00:00
|
|
|
expect(find('a', text: 'Assign to me')).to be_visible
|
2017-05-04 12:11:15 +00:00
|
|
|
click_button 'Unassigned'
|
2017-05-12 11:53:27 +00:00
|
|
|
|
2017-05-17 18:25:13 +00:00
|
|
|
wait_for_requests
|
2017-05-12 11:53:27 +00:00
|
|
|
|
2016-07-19 09:05:38 +00:00
|
|
|
page.within '.dropdown-menu-user' do
|
2017-02-22 07:26:32 +00:00
|
|
|
click_link user2.name
|
2016-07-19 09:05:38 +00:00
|
|
|
end
|
2017-05-04 12:11:15 +00:00
|
|
|
expect(find('input[name="issue[assignee_ids][]"]', visible: false).value).to match(user2.id.to_s)
|
2017-02-22 07:26:32 +00:00
|
|
|
page.within '.js-assignee-search' do
|
|
|
|
expect(page).to have_content user2.name
|
|
|
|
end
|
|
|
|
expect(find('a', text: 'Assign to me')).to be_visible
|
|
|
|
|
|
|
|
click_link 'Assign to me'
|
2017-05-04 12:11:15 +00:00
|
|
|
assignee_ids = page.all('input[name="issue[assignee_ids][]"]', visible: false)
|
|
|
|
|
2017-05-04 20:55:36 +00:00
|
|
|
expect(assignee_ids[0].value).to match(user.id.to_s)
|
2017-05-04 12:11:15 +00:00
|
|
|
|
2016-07-19 09:05:38 +00:00
|
|
|
page.within '.js-assignee-search' do
|
2017-05-04 20:55:36 +00:00
|
|
|
expect(page).to have_content user.name
|
2016-07-18 12:23:45 +00:00
|
|
|
end
|
2017-02-22 07:26:32 +00:00
|
|
|
expect(find('a', text: 'Assign to me', visible: false)).not_to be_visible
|
2016-07-18 12:23:45 +00:00
|
|
|
|
|
|
|
click_button 'Milestone'
|
2016-07-19 09:05:38 +00:00
|
|
|
page.within '.issue-milestone' do
|
|
|
|
click_link milestone.title
|
|
|
|
end
|
|
|
|
expect(find('input[name="issue[milestone_id]"]', visible: false).value).to match(milestone.id.to_s)
|
|
|
|
page.within '.js-milestone-select' do
|
2016-07-18 12:23:45 +00:00
|
|
|
expect(page).to have_content milestone.title
|
|
|
|
end
|
|
|
|
|
|
|
|
click_button 'Labels'
|
2016-07-19 09:05:38 +00:00
|
|
|
page.within '.dropdown-menu-labels' do
|
|
|
|
click_link label.title
|
|
|
|
click_link label2.title
|
|
|
|
end
|
2018-06-07 20:54:24 +00:00
|
|
|
|
|
|
|
find('.js-issuable-form-dropdown.js-label-select').click
|
|
|
|
|
2016-07-19 09:05:38 +00:00
|
|
|
page.within '.js-label-select' do
|
|
|
|
expect(page).to have_content label.title
|
2016-07-18 12:23:45 +00:00
|
|
|
end
|
2016-07-19 09:05:38 +00:00
|
|
|
expect(page.all('input[name="issue[label_ids][]"]', visible: false)[1].value).to match(label.id.to_s)
|
|
|
|
expect(page.all('input[name="issue[label_ids][]"]', visible: false)[2].value).to match(label2.id.to_s)
|
2016-07-18 12:23:45 +00:00
|
|
|
|
|
|
|
click_button 'Submit issue'
|
|
|
|
|
2016-07-19 09:05:38 +00:00
|
|
|
page.within '.issuable-sidebar' do
|
|
|
|
page.within '.assignee' do
|
2017-05-04 20:55:36 +00:00
|
|
|
expect(page).to have_content "Assignee"
|
2016-07-19 09:05:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
page.within '.milestone' do
|
|
|
|
expect(page).to have_content milestone.title
|
|
|
|
end
|
|
|
|
|
|
|
|
page.within '.labels' do
|
|
|
|
expect(page).to have_content label.title
|
|
|
|
expect(page).to have_content label2.title
|
|
|
|
end
|
2016-07-18 12:23:45 +00:00
|
|
|
end
|
2017-03-09 00:14:16 +00:00
|
|
|
|
2017-09-04 18:23:57 +00:00
|
|
|
page.within '.breadcrumbs' do
|
2017-03-09 00:14:16 +00:00
|
|
|
issue = Issue.find_by(title: 'title')
|
|
|
|
|
2017-09-04 18:23:57 +00:00
|
|
|
expect(page).to have_text("Issues #{issue.to_reference}")
|
2017-03-09 00:14:16 +00:00
|
|
|
end
|
2016-07-18 12:23:45 +00:00
|
|
|
end
|
2017-01-16 21:56:53 +00:00
|
|
|
|
|
|
|
it 'correctly updates the dropdown toggle when removing a label' do
|
|
|
|
click_button 'Labels'
|
|
|
|
|
|
|
|
page.within '.dropdown-menu-labels' do
|
|
|
|
click_link label.title
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(find('.js-label-select')).to have_content(label.title)
|
|
|
|
|
|
|
|
page.within '.dropdown-menu-labels' do
|
|
|
|
click_link label.title
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(find('.js-label-select')).to have_content('Labels')
|
|
|
|
end
|
2017-04-18 18:01:15 +00:00
|
|
|
|
2018-02-27 15:07:41 +00:00
|
|
|
it 'clears label search input field when a label is selected' do
|
|
|
|
click_button 'Labels'
|
|
|
|
|
|
|
|
page.within '.dropdown-menu-labels' do
|
|
|
|
search_field = find('input[type="search"]')
|
|
|
|
|
|
|
|
search_field.set(label2.title)
|
|
|
|
click_link label2.title
|
|
|
|
expect(search_field.value).to eq ''
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-18 18:01:15 +00:00
|
|
|
it 'correctly updates the selected user when changing assignee' do
|
2017-05-04 20:55:36 +00:00
|
|
|
click_button 'Unassigned'
|
2017-05-16 18:55:59 +00:00
|
|
|
|
2017-05-17 18:25:13 +00:00
|
|
|
wait_for_requests
|
2017-05-12 11:53:27 +00:00
|
|
|
|
2017-04-18 18:01:15 +00:00
|
|
|
page.within '.dropdown-menu-user' do
|
|
|
|
click_link user.name
|
|
|
|
end
|
|
|
|
|
2017-05-16 19:51:15 +00:00
|
|
|
expect(find('.js-assignee-search')).to have_content(user.name)
|
|
|
|
click_button user.name
|
2017-04-18 18:01:15 +00:00
|
|
|
|
|
|
|
page.within '.dropdown-menu-user' do
|
|
|
|
click_link user2.name
|
|
|
|
end
|
|
|
|
|
2017-05-16 19:51:15 +00:00
|
|
|
expect(find('.js-assignee-search')).to have_content(user2.name)
|
2017-04-18 18:01:15 +00:00
|
|
|
end
|
2017-06-12 20:46:51 +00:00
|
|
|
|
|
|
|
it 'description has autocomplete' do
|
|
|
|
find('#issue_description').native.send_keys('')
|
|
|
|
fill_in 'issue_description', with: '@'
|
|
|
|
|
|
|
|
expect(page).to have_selector('.atwho-view')
|
|
|
|
end
|
2018-03-20 10:09:38 +00:00
|
|
|
|
|
|
|
describe 'milestone' do
|
|
|
|
let!(:milestone) { create(:milestone, title: '"><img src=x onerror=alert(document.domain)>', project: project) }
|
|
|
|
|
|
|
|
it 'escapes milestone' do
|
|
|
|
click_button 'Milestone'
|
|
|
|
|
|
|
|
page.within '.issue-milestone' do
|
|
|
|
click_link milestone.title
|
|
|
|
end
|
|
|
|
|
|
|
|
page.within '.js-milestone-select' do
|
|
|
|
expect(page).to have_content milestone.title
|
|
|
|
expect(page).not_to have_selector 'img'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-07-18 12:23:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'edit issue' do
|
|
|
|
before do
|
2017-10-26 11:04:07 +00:00
|
|
|
visit edit_project_issue_path(project, issue)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows user to update issue' do
|
|
|
|
expect(find('input[name="issue[assignee_ids][]"]', visible: false).value).to match(user.id.to_s)
|
|
|
|
expect(find('input[name="issue[milestone_id]"]', visible: false).value).to match(milestone.id.to_s)
|
|
|
|
expect(find('a', text: 'Assign to me', visible: false)).not_to be_visible
|
|
|
|
|
|
|
|
page.within '.js-user-search' do
|
|
|
|
expect(page).to have_content user.name
|
|
|
|
end
|
|
|
|
|
|
|
|
page.within '.js-milestone-select' do
|
|
|
|
expect(page).to have_content milestone.title
|
|
|
|
end
|
|
|
|
|
|
|
|
click_button 'Labels'
|
|
|
|
page.within '.dropdown-menu-labels' do
|
|
|
|
click_link label.title
|
|
|
|
click_link label2.title
|
|
|
|
end
|
|
|
|
page.within '.js-label-select' do
|
|
|
|
expect(page).to have_content label.title
|
|
|
|
end
|
|
|
|
expect(page.all('input[name="issue[label_ids][]"]', visible: false)[1].value).to match(label.id.to_s)
|
|
|
|
expect(page.all('input[name="issue[label_ids][]"]', visible: false)[2].value).to match(label2.id.to_s)
|
|
|
|
|
|
|
|
click_button 'Save changes'
|
|
|
|
|
|
|
|
page.within '.issuable-sidebar' do
|
|
|
|
page.within '.assignee' do
|
|
|
|
expect(page).to have_content user.name
|
|
|
|
end
|
|
|
|
|
|
|
|
page.within '.milestone' do
|
|
|
|
expect(page).to have_content milestone.title
|
|
|
|
end
|
|
|
|
|
|
|
|
page.within '.labels' do
|
|
|
|
expect(page).to have_content label.title
|
|
|
|
expect(page).to have_content label2.title
|
|
|
|
end
|
2016-07-18 12:23:45 +00:00
|
|
|
end
|
|
|
|
end
|
2017-06-12 20:46:51 +00:00
|
|
|
|
|
|
|
it 'description has autocomplete' do
|
2017-10-26 11:04:07 +00:00
|
|
|
find('#issue_description').native.send_keys('')
|
|
|
|
fill_in 'issue_description', with: '@'
|
2017-06-12 20:46:51 +00:00
|
|
|
|
|
|
|
expect(page).to have_selector('.atwho-view')
|
|
|
|
end
|
2016-07-18 12:23:45 +00:00
|
|
|
end
|
2017-04-18 18:01:15 +00:00
|
|
|
|
2018-02-26 14:12:38 +00:00
|
|
|
context 'inline edit' do
|
|
|
|
before do
|
|
|
|
visit project_issue_path(project, issue)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'opens inline edit form with shortcut' do
|
|
|
|
find('body').send_keys('e')
|
|
|
|
|
|
|
|
expect(page).to have_selector('.detail-page-description form')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-25 09:09:16 +00:00
|
|
|
describe 'sub-group project' do
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:nested_group_1) { create(:group, parent: group) }
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:sub_group_project) { create(:project, group: nested_group_1) }
|
2017-05-25 09:09:16 +00:00
|
|
|
|
|
|
|
before do
|
2018-07-11 14:36:08 +00:00
|
|
|
sub_group_project.add_maintainer(user)
|
2017-05-25 09:09:16 +00:00
|
|
|
|
2017-07-06 16:20:50 +00:00
|
|
|
visit new_project_issue_path(sub_group_project)
|
2017-05-25 09:09:16 +00:00
|
|
|
end
|
|
|
|
|
2018-03-12 06:12:30 +00:00
|
|
|
it 'creates project label from dropdown' do
|
2017-05-25 09:09:16 +00:00
|
|
|
click_button 'Labels'
|
|
|
|
|
2018-03-12 06:12:30 +00:00
|
|
|
click_link 'Create project label'
|
2017-05-25 09:09:16 +00:00
|
|
|
|
|
|
|
page.within '.dropdown-new-label' do
|
|
|
|
fill_in 'new_label_name', with: 'test label'
|
|
|
|
first('.suggest-colors-dropdown a').click
|
|
|
|
|
|
|
|
click_button 'Create'
|
|
|
|
|
|
|
|
wait_for_requests
|
|
|
|
end
|
|
|
|
|
|
|
|
page.within '.dropdown-menu-labels' do
|
|
|
|
expect(page).to have_link 'test label'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-18 18:01:15 +00:00
|
|
|
def before_for_selector(selector)
|
|
|
|
js = <<-JS.strip_heredoc
|
|
|
|
(function(selector) {
|
|
|
|
var el = document.querySelector(selector);
|
|
|
|
return window.getComputedStyle(el, '::before').getPropertyValue('content');
|
|
|
|
})("#{escape_javascript(selector)}")
|
|
|
|
JS
|
|
|
|
page.evaluate_script(js)
|
|
|
|
end
|
2017-05-16 18:55:59 +00:00
|
|
|
end
|