@@ -1,72 +1,72 | |||
|
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('../../test_helper', __FILE__) |
|
19 | 19 | require 'capybara/rails' |
|
20 | 20 | |
|
21 | 21 | Capybara.default_driver = :selenium |
|
22 | 22 | Capybara.register_driver :selenium do |app| |
|
23 | 23 | # Use the following driver definition to test locally using Chrome |
|
24 | 24 | # (also requires chromedriver to be in PATH) |
|
25 | 25 | # Capybara::Selenium::Driver.new(app, :browser => :chrome) |
|
26 | 26 | # Add :switches => %w[--lang=en] to force default browser locale to English |
|
27 | 27 | # Default for Selenium remote driver is to connect to local host on port 4444 |
|
28 | 28 | # This can be change using :url => 'http://localhost:9195' if necessary |
|
29 | 29 | # PhantomJS 1.8 now directly supports Webdriver Wire API, |
|
30 | 30 | # simply run it with `phantomjs --webdriver 4444` |
|
31 | 31 | # Add :desired_capabilities => Selenium::WebDriver::Remote::Capabilities.internet_explorer) |
|
32 | 32 | # to run on Selenium Grid Hub with IE |
|
33 | 33 | Capybara::Selenium::Driver.new(app, :browser => :remote) |
|
34 | 34 | end |
|
35 | 35 | |
|
36 | 36 | # default: 2 |
|
37 |
Capybara.default_wait_time = 2 |
|
|
37 | Capybara.default_wait_time = 2 | |
|
38 | 38 | |
|
39 | 39 | DatabaseCleaner.strategy = :truncation |
|
40 | 40 | |
|
41 | 41 | module Redmine |
|
42 | 42 | module UiTest |
|
43 | 43 | # Base class for UI tests |
|
44 | 44 | class Base < ActionDispatch::IntegrationTest |
|
45 | 45 | include Capybara::DSL |
|
46 | 46 | |
|
47 | 47 | # Stop ActiveRecord from wrapping tests in transactions |
|
48 | 48 | # Transactional fixtures do not work with Selenium tests, because Capybara |
|
49 | 49 | # uses a separate server thread, which the transactions would be hidden |
|
50 | 50 | self.use_transactional_fixtures = false |
|
51 | 51 | |
|
52 | 52 | # Should not depend on locale since Redmine displays login page |
|
53 | 53 | # using default browser locale which depend on system locale for "real" browsers drivers |
|
54 | 54 | def log_user(login, password) |
|
55 | 55 | visit '/my/page' |
|
56 | 56 | assert_equal '/login', current_path |
|
57 | 57 | within('#login-form form') do |
|
58 | 58 | fill_in 'username', :with => login |
|
59 | 59 | fill_in 'password', :with => password |
|
60 | 60 | find('input[name=login]').click |
|
61 | 61 | end |
|
62 | 62 | assert_equal '/my/page', current_path |
|
63 | 63 | end |
|
64 | 64 | |
|
65 | 65 | teardown do |
|
66 | 66 | Capybara.reset_sessions! # Forget the (simulated) browser state |
|
67 | 67 | Capybara.use_default_driver # Revert Capybara.current_driver to Capybara.default_driver |
|
68 | 68 | DatabaseCleaner.clean |
|
69 | 69 | end |
|
70 | 70 | end |
|
71 | 71 | end |
|
72 | 72 | end |
@@ -1,265 +1,264 | |||
|
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 | select '', :from => 'Assignee' | |
|
37 | 36 | fill_in 'Searchable field', :with => 'Value for field 2' |
|
38 | 37 | # click_button 'Create' would match both 'Create' and 'Create and continue' buttons |
|
39 | 38 | find('input[name=commit]').click |
|
40 | 39 | end |
|
41 | 40 | |
|
42 | 41 | # find created issue |
|
43 | 42 | issue = Issue.find_by_subject("new test issue") |
|
44 | 43 | assert_kind_of Issue, issue |
|
45 | 44 | |
|
46 | 45 | # check redirection |
|
47 | 46 | find 'div#flash_notice', :visible => true, :text => "Issue \##{issue.id} created." |
|
48 | 47 | assert_equal issue_path(:id => issue), current_path |
|
49 | 48 | |
|
50 | 49 | # check issue attributes |
|
51 | 50 | assert_equal 'jsmith', issue.author.login |
|
52 | 51 | assert_equal 1, issue.project.id |
|
53 | 52 | assert_equal IssueStatus.find_by_name('New'), issue.status |
|
54 | 53 | assert_equal Tracker.find_by_name('Bug'), issue.tracker |
|
55 | 54 | assert_equal IssuePriority.find_by_name('Low'), issue.priority |
|
56 | 55 | assert_equal 'Value for field 2', issue.custom_field_value(CustomField.find_by_name('Searchable field')) |
|
57 | 56 | end |
|
58 | 57 | |
|
59 | 58 | def test_create_issue_with_form_update |
|
60 | 59 | field1 = IssueCustomField.create!( |
|
61 | 60 | :field_format => 'string', |
|
62 | 61 | :name => 'Field1', |
|
63 | 62 | :is_for_all => true, |
|
64 | 63 | :trackers => Tracker.find_all_by_id([1, 2]) |
|
65 | 64 | ) |
|
66 | 65 | field2 = IssueCustomField.create!( |
|
67 | 66 | :field_format => 'string', |
|
68 | 67 | :name => 'Field2', |
|
69 | 68 | :is_for_all => true, |
|
70 | 69 | :trackers => Tracker.find_all_by_id(2) |
|
71 | 70 | ) |
|
72 | 71 | |
|
73 | 72 | Role.non_member.add_permission! :add_issues |
|
74 | 73 | Role.non_member.remove_permission! :edit_issues, :add_issue_notes |
|
75 | 74 | |
|
76 | 75 | log_user('someone', 'foo') |
|
77 | 76 | visit '/projects/ecookbook/issues/new' |
|
78 | 77 | assert page.has_no_content?(field2.name) |
|
79 | 78 | assert page.has_content?(field1.name) |
|
80 | 79 | |
|
81 | 80 | fill_in 'Subject', :with => 'New test issue' |
|
82 | 81 | fill_in 'Description', :with => 'New test issue description' |
|
83 | 82 | fill_in field1.name, :with => 'CF1 value' |
|
84 | 83 | select 'Low', :from => 'Priority' |
|
85 | 84 | |
|
86 | 85 | # field2 should show up when changing tracker |
|
87 | 86 | select 'Feature request', :from => 'Tracker' |
|
88 | 87 | assert page.has_content?(field2.name) |
|
89 | 88 | assert page.has_content?(field1.name) |
|
90 | 89 | |
|
91 | 90 | fill_in field2.name, :with => 'CF2 value' |
|
92 | 91 | assert_difference 'Issue.count' do |
|
93 | 92 | page.first(:button, 'Create').click |
|
94 | 93 | end |
|
95 | 94 | |
|
96 | 95 | issue = Issue.order('id desc').first |
|
97 | 96 | assert_equal 'New test issue', issue.subject |
|
98 | 97 | assert_equal 'New test issue description', issue.description |
|
99 | 98 | assert_equal 'Low', issue.priority.name |
|
100 | 99 | assert_equal 'CF1 value', issue.custom_field_value(field1) |
|
101 | 100 | assert_equal 'CF2 value', issue.custom_field_value(field2) |
|
102 | 101 | end |
|
103 | 102 | |
|
104 | 103 | def test_create_issue_with_watchers |
|
105 | 104 | user = User.generate!(:firstname => 'Some', :lastname => 'Watcher') |
|
106 | 105 | assert_equal 'Some Watcher', user.name |
|
107 | 106 | log_user('jsmith', 'jsmith') |
|
108 | 107 | visit '/projects/ecookbook/issues/new' |
|
109 | 108 | fill_in 'Subject', :with => 'Issue with watchers' |
|
110 | 109 | # Add a project member as watcher |
|
111 | 110 | check 'Dave Lopper' |
|
112 | 111 | # Search for another user |
|
113 | 112 | assert page.has_no_css?('form#new-watcher-form') |
|
114 | 113 | assert page.has_no_content?('Some Watcher') |
|
115 | 114 | click_link 'Search for watchers to add' |
|
116 | 115 | within('form#new-watcher-form') do |
|
117 | 116 | assert page.has_content?('Some One') |
|
118 | 117 | fill_in 'user_search', :with => 'watch' |
|
119 | 118 | assert page.has_no_content?('Some One') |
|
120 | 119 | check 'Some Watcher' |
|
121 | 120 | click_button 'Add' |
|
122 | 121 | end |
|
123 | 122 | assert page.has_css?('form#issue-form') |
|
124 | 123 | assert page.has_css?('p#watchers_form') |
|
125 | 124 | using_wait_time(30) do |
|
126 | 125 | within('span#watchers_inputs') do |
|
127 | 126 | within("label#issue_watcher_user_ids_#{user.id}") do |
|
128 | 127 | assert has_content?('Some Watcher'), "No watcher content" |
|
129 | 128 | end |
|
130 | 129 | end |
|
131 | 130 | end |
|
132 | 131 | assert_difference 'Issue.count' do |
|
133 | 132 | find('input[name=commit]').click |
|
134 | 133 | end |
|
135 | 134 | |
|
136 | 135 | issue = Issue.order('id desc').first |
|
137 | 136 | assert_equal ['Dave Lopper', 'Some Watcher'], issue.watcher_users.map(&:name).sort |
|
138 | 137 | end |
|
139 | 138 | |
|
140 | 139 | def test_create_issue_start_due_date |
|
141 | 140 | with_settings :default_issue_start_date_to_creation_date => 0 do |
|
142 | 141 | log_user('jsmith', 'jsmith') |
|
143 | 142 | visit '/projects/ecookbook/issues/new' |
|
144 | 143 | assert_equal "", page.find('input#issue_start_date').value |
|
145 | 144 | assert_equal "", page.find('input#issue_due_date').value |
|
146 | 145 | page.first('p#start_date_area img').click |
|
147 | 146 | page.first("td.ui-datepicker-days-cell-over a").click |
|
148 | 147 | assert_equal Date.today.to_s, page.find('input#issue_start_date').value |
|
149 | 148 | page.first('p#due_date_area img').click |
|
150 | 149 | page.first("td.ui-datepicker-days-cell-over a").click |
|
151 | 150 | assert_equal Date.today.to_s, page.find('input#issue_due_date').value |
|
152 | 151 | end |
|
153 | 152 | end |
|
154 | 153 | |
|
155 | 154 | def test_create_issue_start_due_date_default |
|
156 | 155 | log_user('jsmith', 'jsmith') |
|
157 | 156 | visit '/projects/ecookbook/issues/new' |
|
158 | 157 | fill_in 'Start date', :with => '2012-04-01' |
|
159 | 158 | fill_in 'Due date', :with => '' |
|
160 | 159 | page.first('p#due_date_area img').click |
|
161 | 160 | page.first("td.ui-datepicker-days-cell-over a").click |
|
162 | 161 | assert_equal '2012-04-01', page.find('input#issue_due_date').value |
|
163 | 162 | |
|
164 | 163 | fill_in 'Start date', :with => '' |
|
165 | 164 | fill_in 'Due date', :with => '2012-04-01' |
|
166 | 165 | page.first('p#start_date_area img').click |
|
167 | 166 | page.first("td.ui-datepicker-days-cell-over a").click |
|
168 | 167 | assert_equal '2012-04-01', page.find('input#issue_start_date').value |
|
169 | 168 | end |
|
170 | 169 | |
|
171 | 170 | def test_preview_issue_description |
|
172 | 171 | log_user('jsmith', 'jsmith') |
|
173 | 172 | visit '/projects/ecookbook/issues/new' |
|
174 | 173 | within('form#issue-form') do |
|
175 | 174 | fill_in 'Subject', :with => 'new issue subject' |
|
176 | 175 | fill_in 'Description', :with => 'new issue description' |
|
177 | 176 | click_link 'Preview' |
|
178 | 177 | end |
|
179 | 178 | find 'div#preview fieldset', :visible => true, :text => 'new issue description' |
|
180 | 179 | assert_difference 'Issue.count' do |
|
181 | 180 | find('input[name=commit]').click |
|
182 | 181 | end |
|
183 | 182 | |
|
184 | 183 | issue = Issue.order('id desc').first |
|
185 | 184 | assert_equal 'new issue description', issue.description |
|
186 | 185 | end |
|
187 | 186 | |
|
188 | 187 | def test_update_issue_with_form_update |
|
189 | 188 | field = IssueCustomField.create!( |
|
190 | 189 | :field_format => 'string', |
|
191 | 190 | :name => 'Form update CF', |
|
192 | 191 | :is_for_all => true, |
|
193 | 192 | :trackers => Tracker.find_all_by_name('Feature request') |
|
194 | 193 | ) |
|
195 | 194 | |
|
196 | 195 | Role.non_member.add_permission! :edit_issues |
|
197 | 196 | Role.non_member.remove_permission! :add_issues, :add_issue_notes |
|
198 | 197 | |
|
199 | 198 | log_user('someone', 'foo') |
|
200 | 199 | visit '/issues/1' |
|
201 | 200 | assert page.has_no_content?('Form update CF') |
|
202 | 201 | |
|
203 |
page.first(:link, ' |
|
|
202 | page.first(:link, 'Edit').click | |
|
204 | 203 | # the custom field should show up when changing tracker |
|
205 | 204 | select 'Feature request', :from => 'Tracker' |
|
206 | 205 | assert page.has_content?('Form update CF') |
|
207 | 206 | |
|
208 | 207 | fill_in 'Form update', :with => 'CF value' |
|
209 | 208 | assert_no_difference 'Issue.count' do |
|
210 | 209 | page.first(:button, 'Submit').click |
|
211 | 210 | end |
|
212 | 211 | |
|
213 | 212 | issue = Issue.find(1) |
|
214 | 213 | assert_equal 'CF value', issue.custom_field_value(field) |
|
215 | 214 | end |
|
216 | 215 | |
|
217 | 216 | def test_remove_issue_watcher_from_sidebar |
|
218 | 217 | user = User.find(3) |
|
219 | 218 | Watcher.create!(:watchable => Issue.find(1), :user => user) |
|
220 | 219 | |
|
221 | 220 | log_user('jsmith', 'jsmith') |
|
222 | 221 | visit '/issues/1' |
|
223 | 222 | assert page.first('#sidebar').has_content?('Watchers (1)') |
|
224 | 223 | assert page.first('#sidebar').has_content?(user.name) |
|
225 | 224 | assert_difference 'Watcher.count', -1 do |
|
226 | 225 | page.first('ul.watchers .user-3 a.delete').click |
|
227 | 226 | assert page.first('#sidebar').has_content?('Watchers (0)') |
|
228 | 227 | end |
|
229 | 228 | assert page.first('#sidebar').has_no_content?(user.name) |
|
230 | 229 | end |
|
231 | 230 | |
|
232 | 231 | def test_watch_issue_via_context_menu |
|
233 | 232 | log_user('jsmith', 'jsmith') |
|
234 | 233 | visit '/issues' |
|
235 | 234 | assert page.has_css?('tr#issue-1') |
|
236 | 235 | find('tr#issue-1 td.updated_on').click |
|
237 | 236 | page.execute_script "$('tr#issue-1 td.updated_on').trigger('contextmenu');" |
|
238 | 237 | assert_difference 'Watcher.count' do |
|
239 | 238 | within('#context-menu') do |
|
240 | 239 | click_link 'Watch' |
|
241 | 240 | end |
|
242 | 241 | assert page.has_css?('tr#issue-1') |
|
243 | 242 | end |
|
244 | 243 | assert Issue.find(1).watched_by?(User.find_by_login('jsmith')) |
|
245 | 244 | end |
|
246 | 245 | |
|
247 | 246 | def test_bulk_watch_issues_via_context_menu |
|
248 | 247 | log_user('jsmith', 'jsmith') |
|
249 | 248 | visit '/issues' |
|
250 | 249 | assert page.has_css?('tr#issue-1') |
|
251 | 250 | assert page.has_css?('tr#issue-4') |
|
252 | 251 | find('tr#issue-1 input[type=checkbox]').click |
|
253 | 252 | find('tr#issue-4 input[type=checkbox]').click |
|
254 | 253 | page.execute_script "$('tr#issue-1 td.updated_on').trigger('contextmenu');" |
|
255 | 254 | assert_difference 'Watcher.count', 2 do |
|
256 | 255 | within('#context-menu') do |
|
257 | 256 | click_link 'Watch' |
|
258 | 257 | end |
|
259 | 258 | assert page.has_css?('tr#issue-1') |
|
260 | 259 | assert page.has_css?('tr#issue-4') |
|
261 | 260 | end |
|
262 | 261 | assert Issue.find(1).watched_by?(User.find_by_login('jsmith')) |
|
263 | 262 | assert Issue.find(4).watched_by?(User.find_by_login('jsmith')) |
|
264 | 263 | end |
|
265 | 264 | end |
General Comments 0
You need to be logged in to leave comments.
Login now