Chris@1295: # Redmine - project management software Chris@1295: # Copyright (C) 2006-2013 Jean-Philippe Lang Chris@1295: # Chris@1295: # This program is free software; you can redistribute it and/or Chris@1295: # modify it under the terms of the GNU General Public License Chris@1295: # as published by the Free Software Foundation; either version 2 Chris@1295: # of the License, or (at your option) any later version. Chris@1295: # Chris@1295: # This program is distributed in the hope that it will be useful, Chris@1295: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@1295: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@1295: # GNU General Public License for more details. Chris@1295: # Chris@1295: # You should have received a copy of the GNU General Public License Chris@1295: # along with this program; if not, write to the Free Software Chris@1295: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@1295: Chris@1295: require File.expand_path('../base', __FILE__) Chris@1295: Chris@1295: class Redmine::UiTest::IssuesTest < Redmine::UiTest::Base Chris@1295: fixtures :projects, :users, :roles, :members, :member_roles, Chris@1295: :trackers, :projects_trackers, :enabled_modules, :issue_statuses, :issues, Chris@1295: :enumerations, :custom_fields, :custom_values, :custom_fields_trackers, Chris@1295: :watchers Chris@1295: Chris@1295: def test_create_issue Chris@1295: log_user('jsmith', 'jsmith') Chris@1295: visit '/projects/ecookbook/issues/new' Chris@1295: within('form#issue-form') do Chris@1295: select 'Bug', :from => 'Tracker' Chris@1295: select 'Low', :from => 'Priority' Chris@1295: fill_in 'Subject', :with => 'new test issue' Chris@1295: fill_in 'Description', :with => 'new issue' Chris@1295: select '0 %', :from => 'Done' Chris@1295: fill_in 'Due date', :with => '' Chris@1295: select '', :from => 'Assignee' Chris@1295: fill_in 'Searchable field', :with => 'Value for field 2' Chris@1295: # click_button 'Create' would match both 'Create' and 'Create and continue' buttons Chris@1295: find('input[name=commit]').click Chris@1295: end Chris@1295: Chris@1295: # find created issue Chris@1295: issue = Issue.find_by_subject("new test issue") Chris@1295: assert_kind_of Issue, issue Chris@1295: Chris@1295: # check redirection Chris@1295: find 'div#flash_notice', :visible => true, :text => "Issue \##{issue.id} created." Chris@1295: assert_equal issue_path(:id => issue), current_path Chris@1295: Chris@1295: # check issue attributes Chris@1295: assert_equal 'jsmith', issue.author.login Chris@1295: assert_equal 1, issue.project.id Chris@1295: assert_equal IssueStatus.find_by_name('New'), issue.status Chris@1295: assert_equal Tracker.find_by_name('Bug'), issue.tracker Chris@1295: assert_equal IssuePriority.find_by_name('Low'), issue.priority Chris@1295: assert_equal 'Value for field 2', issue.custom_field_value(CustomField.find_by_name('Searchable field')) Chris@1295: end Chris@1295: Chris@1295: def test_create_issue_with_form_update Chris@1295: field1 = IssueCustomField.create!( Chris@1295: :field_format => 'string', Chris@1295: :name => 'Field1', Chris@1295: :is_for_all => true, Chris@1295: :trackers => Tracker.find_all_by_id([1, 2]) Chris@1295: ) Chris@1295: field2 = IssueCustomField.create!( Chris@1295: :field_format => 'string', Chris@1295: :name => 'Field2', Chris@1295: :is_for_all => true, Chris@1295: :trackers => Tracker.find_all_by_id(2) Chris@1295: ) Chris@1295: Chris@1295: Role.non_member.add_permission! :add_issues Chris@1295: Role.non_member.remove_permission! :edit_issues, :add_issue_notes Chris@1295: Chris@1295: log_user('someone', 'foo') Chris@1295: visit '/projects/ecookbook/issues/new' Chris@1295: assert page.has_no_content?(field2.name) Chris@1295: assert page.has_content?(field1.name) Chris@1295: Chris@1295: fill_in 'Subject', :with => 'New test issue' Chris@1295: fill_in 'Description', :with => 'New test issue description' Chris@1295: fill_in field1.name, :with => 'CF1 value' Chris@1295: select 'Low', :from => 'Priority' Chris@1295: Chris@1295: # field2 should show up when changing tracker Chris@1295: select 'Feature request', :from => 'Tracker' Chris@1295: assert page.has_content?(field2.name) Chris@1295: assert page.has_content?(field1.name) Chris@1295: Chris@1295: fill_in field2.name, :with => 'CF2 value' Chris@1295: assert_difference 'Issue.count' do Chris@1295: page.first(:button, 'Create').click Chris@1295: end Chris@1295: Chris@1295: issue = Issue.order('id desc').first Chris@1295: assert_equal 'New test issue', issue.subject Chris@1295: assert_equal 'New test issue description', issue.description Chris@1295: assert_equal 'Low', issue.priority.name Chris@1295: assert_equal 'CF1 value', issue.custom_field_value(field1) Chris@1295: assert_equal 'CF2 value', issue.custom_field_value(field2) Chris@1295: end Chris@1295: Chris@1295: def test_create_issue_with_watchers Chris@1295: User.generate!(:firstname => 'Some', :lastname => 'Watcher') Chris@1295: Chris@1295: log_user('jsmith', 'jsmith') Chris@1295: visit '/projects/ecookbook/issues/new' Chris@1295: fill_in 'Subject', :with => 'Issue with watchers' Chris@1295: # Add a project member as watcher Chris@1295: check 'Dave Lopper' Chris@1295: # Search for another user Chris@1295: click_link 'Search for watchers to add' Chris@1295: within('form#new-watcher-form') do Chris@1295: assert page.has_content?('Some One') Chris@1295: fill_in 'user_search', :with => 'watch' Chris@1295: assert page.has_no_content?('Some One') Chris@1295: check 'Some Watcher' Chris@1295: click_button 'Add' Chris@1295: end Chris@1295: assert_difference 'Issue.count' do Chris@1295: find('input[name=commit]').click Chris@1295: end Chris@1295: Chris@1295: issue = Issue.order('id desc').first Chris@1295: assert_equal ['Dave Lopper', 'Some Watcher'], issue.watcher_users.map(&:name).sort Chris@1295: end Chris@1295: Chris@1295: def test_preview_issue_description Chris@1295: log_user('jsmith', 'jsmith') Chris@1295: visit '/projects/ecookbook/issues/new' Chris@1295: within('form#issue-form') do Chris@1295: fill_in 'Subject', :with => 'new issue subject' Chris@1295: fill_in 'Description', :with => 'new issue description' Chris@1295: click_link 'Preview' Chris@1295: end Chris@1295: find 'div#preview fieldset', :visible => true, :text => 'new issue description' Chris@1295: assert_difference 'Issue.count' do Chris@1295: find('input[name=commit]').click Chris@1295: end Chris@1295: Chris@1295: issue = Issue.order('id desc').first Chris@1295: assert_equal 'new issue description', issue.description Chris@1295: end Chris@1295: Chris@1295: def test_update_issue_with_form_update Chris@1295: field = IssueCustomField.create!( Chris@1295: :field_format => 'string', Chris@1295: :name => 'Form update CF', Chris@1295: :is_for_all => true, Chris@1295: :trackers => Tracker.find_all_by_name('Feature request') Chris@1295: ) Chris@1295: Chris@1295: Role.non_member.add_permission! :edit_issues Chris@1295: Role.non_member.remove_permission! :add_issues, :add_issue_notes Chris@1295: Chris@1295: log_user('someone', 'foo') Chris@1295: visit '/issues/1' Chris@1295: assert page.has_no_content?('Form update CF') Chris@1295: Chris@1295: page.first(:link, 'Update').click Chris@1295: # the custom field should show up when changing tracker Chris@1295: select 'Feature request', :from => 'Tracker' Chris@1295: assert page.has_content?('Form update CF') Chris@1295: Chris@1295: fill_in 'Form update', :with => 'CF value' Chris@1295: assert_no_difference 'Issue.count' do Chris@1295: page.first(:button, 'Submit').click Chris@1295: end Chris@1295: Chris@1295: issue = Issue.find(1) Chris@1295: assert_equal 'CF value', issue.custom_field_value(field) Chris@1295: end Chris@1295: Chris@1295: def test_remove_issue_watcher_from_sidebar Chris@1295: user = User.find(3) Chris@1295: Watcher.create!(:watchable => Issue.find(1), :user => user) Chris@1295: Chris@1295: log_user('jsmith', 'jsmith') Chris@1295: visit '/issues/1' Chris@1295: assert page.first('#sidebar').has_content?('Watchers (1)') Chris@1295: assert page.first('#sidebar').has_content?(user.name) Chris@1295: assert_difference 'Watcher.count', -1 do Chris@1295: page.first('ul.watchers .user-3 a.delete').click Chris@1295: end Chris@1295: assert page.first('#sidebar').has_content?('Watchers (0)') Chris@1295: assert page.first('#sidebar').has_no_content?(user.name) Chris@1295: end Chris@1295: Chris@1295: def test_watch_issue_via_context_menu Chris@1295: log_user('jsmith', 'jsmith') Chris@1295: visit '/issues' Chris@1295: find('tr#issue-1 td.updated_on').click Chris@1295: page.execute_script "$('tr#issue-1 td.updated_on').trigger('contextmenu');" Chris@1295: assert_difference 'Watcher.count' do Chris@1295: within('#context-menu') do Chris@1295: click_link 'Watch' Chris@1295: end Chris@1295: end Chris@1295: assert Issue.find(1).watched_by?(User.find_by_login('jsmith')) Chris@1295: end Chris@1295: Chris@1295: def test_bulk_watch_issues_via_context_menu Chris@1295: log_user('jsmith', 'jsmith') Chris@1295: visit '/issues' Chris@1295: find('tr#issue-1 input[type=checkbox]').click Chris@1295: find('tr#issue-4 input[type=checkbox]').click Chris@1295: page.execute_script "$('tr#issue-1 td.updated_on').trigger('contextmenu');" Chris@1295: assert_difference 'Watcher.count', 2 do Chris@1295: within('#context-menu') do Chris@1295: click_link 'Watch' Chris@1295: end Chris@1295: end Chris@1295: assert Issue.find(1).watched_by?(User.find_by_login('jsmith')) Chris@1295: assert Issue.find(4).watched_by?(User.find_by_login('jsmith')) Chris@1295: end Chris@1295: end