##// END OF EJS Templates
Make sure that fields filled before tracker change are preserved....
Jean-Philippe Lang -
r11180:9dd8988638cf
parent child
Show More
@@ -1,186 +1,202
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../base', __FILE__)
18 require File.expand_path('../base', __FILE__)
19
19
20 class Redmine::UiTest::IssuesTest < Redmine::UiTest::Base
20 class Redmine::UiTest::IssuesTest < Redmine::UiTest::Base
21 fixtures :projects, :users, :roles, :members, :member_roles,
21 fixtures :projects, :users, :roles, :members, :member_roles,
22 :trackers, :projects_trackers, :enabled_modules, :issue_statuses, :issues,
22 :trackers, :projects_trackers, :enabled_modules, :issue_statuses, :issues,
23 :enumerations, :custom_fields, :custom_values, :custom_fields_trackers,
23 :enumerations, :custom_fields, :custom_values, :custom_fields_trackers,
24 :watchers
24 :watchers
25
25
26 def test_create_issue
26 def test_create_issue
27 log_user('jsmith', 'jsmith')
27 log_user('jsmith', 'jsmith')
28 visit '/projects/ecookbook/issues/new'
28 visit '/projects/ecookbook/issues/new'
29 within('form#issue-form') do
29 within('form#issue-form') do
30 select 'Bug', :from => 'Tracker'
30 select 'Bug', :from => 'Tracker'
31 select 'Low', :from => 'Priority'
31 select 'Low', :from => 'Priority'
32 fill_in 'Subject', :with => 'new test issue'
32 fill_in 'Subject', :with => 'new test issue'
33 fill_in 'Description', :with => 'new issue'
33 fill_in 'Description', :with => 'new issue'
34 select '0 %', :from => 'Done'
34 select '0 %', :from => 'Done'
35 fill_in 'Due date', :with => ''
35 fill_in 'Due date', :with => ''
36 select '', :from => 'Assignee'
36 select '', :from => 'Assignee'
37 fill_in 'Searchable field', :with => 'Value for field 2'
37 fill_in 'Searchable field', :with => 'Value for field 2'
38 # click_button 'Create' would match both 'Create' and 'Create and continue' buttons
38 # click_button 'Create' would match both 'Create' and 'Create and continue' buttons
39 find('input[name=commit]').click
39 find('input[name=commit]').click
40 end
40 end
41
41
42 # find created issue
42 # find created issue
43 issue = Issue.find_by_subject("new test issue")
43 issue = Issue.find_by_subject("new test issue")
44 assert_kind_of Issue, issue
44 assert_kind_of Issue, issue
45
45
46 # check redirection
46 # check redirection
47 find 'div#flash_notice', :visible => true, :text => "Issue \##{issue.id} created."
47 find 'div#flash_notice', :visible => true, :text => "Issue \##{issue.id} created."
48 assert_equal issue_path(:id => issue), current_path
48 assert_equal issue_path(:id => issue), current_path
49
49
50 # check issue attributes
50 # check issue attributes
51 assert_equal 'jsmith', issue.author.login
51 assert_equal 'jsmith', issue.author.login
52 assert_equal 1, issue.project.id
52 assert_equal 1, issue.project.id
53 assert_equal IssueStatus.find_by_name('New'), issue.status
53 assert_equal IssueStatus.find_by_name('New'), issue.status
54 assert_equal Tracker.find_by_name('Bug'), issue.tracker
54 assert_equal Tracker.find_by_name('Bug'), issue.tracker
55 assert_equal IssuePriority.find_by_name('Low'), issue.priority
55 assert_equal IssuePriority.find_by_name('Low'), issue.priority
56 assert_equal 'Value for field 2', issue.custom_field_value(CustomField.find_by_name('Searchable field'))
56 assert_equal 'Value for field 2', issue.custom_field_value(CustomField.find_by_name('Searchable field'))
57 end
57 end
58
58
59 def test_create_issue_with_form_update
59 def test_create_issue_with_form_update
60 field = IssueCustomField.create!(
60 field1 = IssueCustomField.create!(
61 :field_format => 'string',
61 :field_format => 'string',
62 :name => 'Form update CF',
62 :name => 'Field1',
63 :is_for_all => true,
63 :is_for_all => true,
64 :trackers => Tracker.find_all_by_name('Feature request')
64 :trackers => Tracker.find_all_by_id([1, 2])
65 )
66 field2 = IssueCustomField.create!(
67 :field_format => 'string',
68 :name => 'Field2',
69 :is_for_all => true,
70 :trackers => Tracker.find_all_by_id(2)
65 )
71 )
66
72
67 Role.non_member.add_permission! :add_issues
73 Role.non_member.add_permission! :add_issues
68 Role.non_member.remove_permission! :edit_issues, :add_issue_notes
74 Role.non_member.remove_permission! :edit_issues, :add_issue_notes
69
75
70 log_user('someone', 'foo')
76 log_user('someone', 'foo')
71 visit '/projects/ecookbook/issues/new'
77 visit '/projects/ecookbook/issues/new'
72 assert page.has_no_content?('Form update CF')
78 assert page.has_no_content?(field2.name)
79 assert page.has_content?(field1.name)
73
80
74 fill_in 'Subject', :with => 'new test issue'
81 fill_in 'Subject', :with => 'New test issue'
75 # the custom field should show up when changing tracker
82 fill_in 'Description', :with => 'New test issue description'
83 fill_in field1.name, :with => 'CF1 value'
84 select 'Low', :from => 'Priority'
85
86 # field2 should show up when changing tracker
76 select 'Feature request', :from => 'Tracker'
87 select 'Feature request', :from => 'Tracker'
77 assert page.has_content?('Form update CF')
88 assert page.has_content?(field2.name)
89 assert page.has_content?(field1.name)
78
90
79 fill_in 'Form update', :with => 'CF value'
91 fill_in field2.name, :with => 'CF2 value'
80 assert_difference 'Issue.count' do
92 assert_difference 'Issue.count' do
81 find('input[name=commit]').click
93 page.first(:button, 'Create').click
82 end
94 end
83
95
84 issue = Issue.order('id desc').first
96 issue = Issue.order('id desc').first
85 assert_equal 'CF value', issue.custom_field_value(field)
97 assert_equal 'New test issue', issue.subject
98 assert_equal 'New test issue description', issue.description
99 assert_equal 'Low', issue.priority.name
100 assert_equal 'CF1 value', issue.custom_field_value(field1)
101 assert_equal 'CF2 value', issue.custom_field_value(field2)
86 end
102 end
87
103
88 def test_create_issue_with_watchers
104 def test_create_issue_with_watchers
89 User.generate!(:firstname => 'Some', :lastname => 'Watcher')
105 User.generate!(:firstname => 'Some', :lastname => 'Watcher')
90
106
91 log_user('jsmith', 'jsmith')
107 log_user('jsmith', 'jsmith')
92 visit '/projects/ecookbook/issues/new'
108 visit '/projects/ecookbook/issues/new'
93 fill_in 'Subject', :with => 'Issue with watchers'
109 fill_in 'Subject', :with => 'Issue with watchers'
94 # Add a project member as watcher
110 # Add a project member as watcher
95 check 'Dave Lopper'
111 check 'Dave Lopper'
96 # Search for another user
112 # Search for another user
97 click_link 'Search for watchers to add'
113 click_link 'Search for watchers to add'
98 within('form#new-watcher-form') do
114 within('form#new-watcher-form') do
99 assert page.has_content?('Some One')
115 assert page.has_content?('Some One')
100 fill_in 'user_search', :with => 'watch'
116 fill_in 'user_search', :with => 'watch'
101 assert page.has_no_content?('Some One')
117 assert page.has_no_content?('Some One')
102 check 'Some Watcher'
118 check 'Some Watcher'
103 click_button 'Add'
119 click_button 'Add'
104 end
120 end
105 assert_difference 'Issue.count' do
121 assert_difference 'Issue.count' do
106 find('input[name=commit]').click
122 find('input[name=commit]').click
107 end
123 end
108
124
109 issue = Issue.order('id desc').first
125 issue = Issue.order('id desc').first
110 assert_equal ['Dave Lopper', 'Some Watcher'], issue.watcher_users.map(&:name).sort
126 assert_equal ['Dave Lopper', 'Some Watcher'], issue.watcher_users.map(&:name).sort
111 end
127 end
112
128
113 def test_preview_issue_description
129 def test_preview_issue_description
114 log_user('jsmith', 'jsmith')
130 log_user('jsmith', 'jsmith')
115 visit '/projects/ecookbook/issues/new'
131 visit '/projects/ecookbook/issues/new'
116 within('form#issue-form') do
132 within('form#issue-form') do
117 fill_in 'Subject', :with => 'new issue subject'
133 fill_in 'Subject', :with => 'new issue subject'
118 fill_in 'Description', :with => 'new issue description'
134 fill_in 'Description', :with => 'new issue description'
119 click_link 'Preview'
135 click_link 'Preview'
120 end
136 end
121 find 'div#preview fieldset', :visible => true, :text => 'new issue description'
137 find 'div#preview fieldset', :visible => true, :text => 'new issue description'
122 assert_difference 'Issue.count' do
138 assert_difference 'Issue.count' do
123 find('input[name=commit]').click
139 find('input[name=commit]').click
124 end
140 end
125
141
126 issue = Issue.order('id desc').first
142 issue = Issue.order('id desc').first
127 assert_equal 'new issue description', issue.description
143 assert_equal 'new issue description', issue.description
128 end
144 end
129
145
130 def test_update_issue_with_form_update
146 def test_update_issue_with_form_update
131 field = IssueCustomField.create!(
147 field = IssueCustomField.create!(
132 :field_format => 'string',
148 :field_format => 'string',
133 :name => 'Form update CF',
149 :name => 'Form update CF',
134 :is_for_all => true,
150 :is_for_all => true,
135 :trackers => Tracker.find_all_by_name('Feature request')
151 :trackers => Tracker.find_all_by_name('Feature request')
136 )
152 )
137
153
138 Role.non_member.add_permission! :edit_issues
154 Role.non_member.add_permission! :edit_issues
139 Role.non_member.remove_permission! :add_issues, :add_issue_notes
155 Role.non_member.remove_permission! :add_issues, :add_issue_notes
140
156
141 log_user('someone', 'foo')
157 log_user('someone', 'foo')
142 visit '/issues/1'
158 visit '/issues/1'
143 assert page.has_no_content?('Form update CF')
159 assert page.has_no_content?('Form update CF')
144
160
145 page.first(:link, 'Update').click
161 page.first(:link, 'Update').click
146 # the custom field should show up when changing tracker
162 # the custom field should show up when changing tracker
147 select 'Feature request', :from => 'Tracker'
163 select 'Feature request', :from => 'Tracker'
148 assert page.has_content?('Form update CF')
164 assert page.has_content?('Form update CF')
149
165
150 fill_in 'Form update', :with => 'CF value'
166 fill_in 'Form update', :with => 'CF value'
151 assert_no_difference 'Issue.count' do
167 assert_no_difference 'Issue.count' do
152 page.first(:button, 'Submit').click
168 page.first(:button, 'Submit').click
153 end
169 end
154
170
155 issue = Issue.find(1)
171 issue = Issue.find(1)
156 assert_equal 'CF value', issue.custom_field_value(field)
172 assert_equal 'CF value', issue.custom_field_value(field)
157 end
173 end
158
174
159 def test_watch_issue_via_context_menu
175 def test_watch_issue_via_context_menu
160 log_user('jsmith', 'jsmith')
176 log_user('jsmith', 'jsmith')
161 visit '/issues'
177 visit '/issues'
162 find('tr#issue-1 td.updated_on').click
178 find('tr#issue-1 td.updated_on').click
163 page.execute_script "$('tr#issue-1 td.updated_on').trigger('contextmenu');"
179 page.execute_script "$('tr#issue-1 td.updated_on').trigger('contextmenu');"
164 assert_difference 'Watcher.count' do
180 assert_difference 'Watcher.count' do
165 within('#context-menu') do
181 within('#context-menu') do
166 click_link 'Watch'
182 click_link 'Watch'
167 end
183 end
168 end
184 end
169 assert Issue.find(1).watched_by?(User.find_by_login('jsmith'))
185 assert Issue.find(1).watched_by?(User.find_by_login('jsmith'))
170 end
186 end
171
187
172 def test_bulk_watch_issues_via_context_menu
188 def test_bulk_watch_issues_via_context_menu
173 log_user('jsmith', 'jsmith')
189 log_user('jsmith', 'jsmith')
174 visit '/issues'
190 visit '/issues'
175 find('tr#issue-1 input[type=checkbox]').click
191 find('tr#issue-1 input[type=checkbox]').click
176 find('tr#issue-4 input[type=checkbox]').click
192 find('tr#issue-4 input[type=checkbox]').click
177 page.execute_script "$('tr#issue-1 td.updated_on').trigger('contextmenu');"
193 page.execute_script "$('tr#issue-1 td.updated_on').trigger('contextmenu');"
178 assert_difference 'Watcher.count', 2 do
194 assert_difference 'Watcher.count', 2 do
179 within('#context-menu') do
195 within('#context-menu') do
180 click_link 'Watch'
196 click_link 'Watch'
181 end
197 end
182 end
198 end
183 assert Issue.find(1).watched_by?(User.find_by_login('jsmith'))
199 assert Issue.find(1).watched_by?(User.find_by_login('jsmith'))
184 assert Issue.find(4).watched_by?(User.find_by_login('jsmith'))
200 assert Issue.find(4).watched_by?(User.find_by_login('jsmith'))
185 end
201 end
186 end
202 end
General Comments 0
You need to be logged in to leave comments. Login now