4 require "selenium-webdriver"
5 $: << File.expand_path('../../', __FILE__)
7 Dir[File.dirname(__FILE__) + '/pages/page.rb'].each {|file| require file }
8 Dir[File.dirname(__FILE__) + '/pages/*.rb'].each {|file| require file }
9 Dir[File.dirname(__FILE__) + '/helpers/*.rb'].each {|file| require file }
12 include RSpec::Expectations
14 describe "Edit core field" do
17 profile = Selenium::WebDriver::Firefox::Profile.new
18 @driver = Selenium::WebDriver.for :firefox, :profile => profile
19 @driver.manage.window.maximize
20 @base_url = "http://localhost:3000/"
21 @driver.manage.timeouts.implicit_wait = 10
22 @verification_errors = []
23 @default_project = "test"
24 @default_user = "admin"
25 @default_password = "dummy"
28 start_page = QuickEdit::Test::Pages::StartPage.new(@driver, @base_url, @default_project)
29 first_page = start_page.login @default_user, @default_password
30 @issues_page = first_page.open_issues
32 # create issue for test
33 issue_new_page = @issues_page.open_new_page()
34 issue_show_page = issue_new_page.create(:bug, 'first subject')
35 @issue_id = issue_show_page.id
40 @issues_page = @issues_page.open_issues
44 expect(@verification_errors).to match_array []
51 it "subject can edit" do
53 expect( edit(@issue_id, :subject, new_value) ).to eq new_value
55 new_value = 'subject: new_value'
56 expect( edit(@issue_id, :subject, new_value) ).to eq new_value
58 expect( edit_with_alert(@issue_id, :subject, "") ).to eq new_value
61 it "subject can edit with public notes" do
62 new_value = {:value => 'subject: with_notes',
63 :notes => {:text => "notes\ntime=" + (Time.now.to_s), :is_private => false}}
64 expect( edit(@issue_id, :subject, new_value) ).to eq new_value[:value]
65 expect( latest_note(@issue_id, @issues_page.session_cookie) ).to eq new_value
68 it "subject can edit with private notes" do
69 new_value = {:value => 'subject: with_notes',
70 :notes => {:text => "notes\ntime=" + (Time.now.to_s), :is_private => true}}
71 expect( edit(@issue_id, :subject, new_value) ).to eq new_value[:value]
72 expect( lastest_note(@issue_id, @issues_page.session_cookie) ).to eq new_value
75 it "start_date can edit" do
76 new_value = '1900-01-01'
77 expect( edit(@issue_id, :start_date, new_value) ).to eq new_value
79 new_value = '1900-01-02'
80 expect( edit(@issue_id, :start_date, new_value) ).to eq new_value
82 invalid_value = '1900-01-0a'
83 expect( edit_with_alert(@issue_id, :start_date, invalid_value) ).to eq new_value
86 expect( edit_with_alert(@issue_id, :start_date, invalid_value) ).to eq new_value
89 it "due_date can edit" do
90 new_value = '2000-01-01'
91 expect( edit(@issue_id, :due_date, new_value) ).to eq new_value
93 new_value = '2000-01-02'
94 expect( edit(@issue_id, :due_date, new_value) ).to eq new_value
96 invalid_value = '2000-01-0a'
97 expect( edit_with_alert(@issue_id, :due_date, invalid_value) ).to eq new_value
100 expect( edit_with_alert(@issue_id, :due_date, invalid_value) ).to eq new_value
103 it "description can edit" do
105 expect( edit(@issue_id, :description, new_value) ).to eq new_value
107 new_value = 'description: new_value'
108 expect( edit(@issue_id, :description, new_value) ).to eq new_value
110 expect( edit_with_alert(@issue_id, :description, "") ).to eq new_value
113 # unsigned float field
114 it "estimated_hours can edit" do
116 expect( edit(@issue_id, :estimated_hours, new_value).to_f ).to eq new_value.to_f
119 expect( edit(@issue_id, :estimated_hours, new_value).to_f ).to eq new_value.to_f
122 expect( edit(@issue_id, :estimated_hours, new_value).to_f ).to eq new_value.to_f
125 expect( edit(@issue_id, :estimated_hours, new_value).to_f ).to eq new_value.to_f
128 expect( edit_with_alert(@issue_id, :estimated_hours, invalid_value) ).to eq new_value.to_f
131 it "parent_issue_id can edit" do
132 issue_ids = @issues_page.issue_ids_on_page
133 issue_new_page = @issues_page.open_new_page()
134 issue_show_page = issue_new_page.create(:bug, 'first subject')
135 new_issue_id = issue_show_page.id
136 @issues_page = issue_show_page.open_issues
138 new_value = @issue_id.to_s
139 expect( edit(new_issue_id, :parent_issue_id, new_value) ).to eq new_value.to_i
142 expect( edit_with_alert(new_issue_id, :parent_issue_id, invalid_value) ).to eq new_value.to_i
144 new_value = @issue_id.to_s
145 expect( edit(new_issue_id, :parent_issue_id, new_value) ).to eq new_value.to_i
148 def edit(issue_id, attribute_name, new_value)
149 quick_edit = @issues_page.open_context(issue_id)
150 menu_selector = quick_edit.menu_selector(attribute_name)
151 @issues_page = quick_edit.update_field(issue_id, menu_selector, new_value)
153 attribute_name = :parent if attribute_name.to_sym == :parent_issue_id
154 field_value = get_core_field(issue_id, attribute_name)
156 if attribute_name == :parent
163 def edit_with_alert(issue_id, attribute_name, new_value)
164 quick_edit = @issues_page.open_context(issue_id)
165 menu_selector = quick_edit.menu_selector(attribute_name)
166 quick_edit.update_field(issue_id, menu_selector, new_value, true)
167 quick_edit.alert.accept
168 quick_edit.cancel_quick_edit
170 attribute_name = :parent if attribute_name.to_sym == :parent_issue_id
171 field_value = get_core_field(issue_id, attribute_name)
173 if attribute_name == :parent
180 def get_core_field(issue_id, attribute_name)
181 json = get_json("issues/#{issue_id}.json")
183 json["issue"][attribute_name.to_s]
187 uri = URI::parse "#{@base_url}#{path}"
188 res = Net::HTTP::get_response(uri)