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 }
11 include RSpec::Expectations
13 describe "Replace core field" do
16 profile = Selenium::WebDriver::Firefox::Profile.new
17 @driver = Selenium::WebDriver.for :firefox, :profile => profile
18 @driver.manage.window.maximize
19 @base_url = "http://localhost:3000/"
20 @driver.manage.timeouts.implicit_wait = 10
21 @verification_errors = []
22 @default_project = "test"
23 @default_user = "admin"
24 @default_password = "dummy"
27 start_page = QuickEdit::Test::Pages::StartPage.new(@driver, @base_url, @default_project)
28 first_page = start_page.login @default_user, @default_password
29 @issues_page = first_page.open_issues
31 # create issue for test
32 issue_new_page = @issues_page.open_new_page()
33 issue_show_page = issue_new_page.create(:bug, 'initial text')
34 @issue_id = issue_show_page.id
39 @issues_page = @issues_page.open_mypage
43 expect(@verification_errors).to match_array []
50 it "subject can replace" do
51 new_value = 'new text'
54 expect( replace(@issue_id, :subject, find, replace) ).to eq new_value
56 new_value = "new<>\'\"&+% text"
58 replace = "<>\'\"&+% "
59 expect( replace(@issue_id, :subject, find, replace) ).to eq new_value
63 expect( replace_with_alert(@issue_id, :subject, find, replace) ).to eq new_value
66 def edit(issue_id, attribute_name, new_value)
67 quick_edit = @issues_page.open_context(issue_id)
68 menu_selector = quick_edit.menu_selector(attribute_name)
69 @issues_page = quick_edit.update_field(issue_id, menu_selector, new_value)
71 attribute_name = :parent if attribute_name.to_sym == :parent_issue_id
72 field_value = get_core_field(issue_id, attribute_name)
74 if attribute_name == :parent
81 def replace(issue_id, attribute_name, find, replace)
82 quick_edit = @issues_page.open_context(issue_id)
83 menu_selector = quick_edit.menu_selector(attribute_name)
84 @issues_page = quick_edit.replace(issue_id, menu_selector, find, replace, false)
86 attribute_name = :parent if attribute_name.to_sym == :parent_issue_id
87 field_value = get_core_field(issue_id, attribute_name)
89 if attribute_name == :parent
96 def replace_with_alert(issue_id, attribute_name, find, replace)
97 quick_edit = @issues_page.open_context(issue_id)
98 menu_selector = quick_edit.menu_selector(attribute_name)
99 quick_edit.replace(issue_id, menu_selector, find, replace, false, true)
100 quick_edit.alert.accept
101 quick_edit.cancel_quick_edit
103 attribute_name = :parent if attribute_name.to_sym == :parent_issue_id
104 field_value = get_core_field(issue_id, attribute_name)
106 if attribute_name == :parent
113 def get_core_field(issue_id, attribute_name)
114 json = get_json("issues/#{issue_id}.json")
116 json["issue"][attribute_name.to_s]
120 uri = URI::parse "#{@base_url}#{path}"
121 res = Net::HTTP::get_response(uri)