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