migrate context and context_list features. Drag and drop is still WIP

This commit is contained in:
Reinier Balt 2012-01-31 12:09:00 +01:00
parent de309c8ee8
commit 4a8fdbabc2
12 changed files with 246 additions and 94 deletions

View file

@ -1,29 +1,27 @@
When /^I delete the context "([^\"]*)"$/ do |context_name|
context = @current_user.contexts.find_by_name(context_name)
context.should_not be_nil
click_link "delete_context_#{context.id}"
selenium.get_confirmation.should == "Are you sure that you want to delete the context '#{context_name}'? Be aware that this will also delete all (repeating) actions in this context!"
wait_for do
!selenium.is_element_present("delete_context_#{context.id}")
handle_js_confirm do
click_link "delete_context_#{context.id}"
end
get_confirm_text.should == "Are you sure that you want to delete the context '#{context_name}'? Be aware that this will also delete all (repeating) actions in this context!"
wait_for_animations_to_end
end
When /^I edit the context to rename it to "([^\"]*)"$/ do |new_name|
click_link "edit_context_#{@context.id}"
wait_for do
selenium.is_element_present("submit_context_#{@context.id}")
find("a#link_edit_context_#{@context.id}").click
wait_until do
page.has_css?("button#submit_context_#{@context.id}")
end
fill_in "context_name", :with => new_name
selenium.click "submit_context_#{@context.id}",
:wait_for => :text,
:text => "Context saved",
:timeout => 5
wait_for do
!selenium.is_element_present("submit_context_#{@context.id}")
click_button "submit_context_#{@context.id}"
wait_until do
!page.has_css?("button#submit_context_#{@context.id}", :visible=>true)
end
end
@ -42,57 +40,70 @@ When /^I add a new hidden context "([^"]*)"$/ do |context_name|
submit_new_context_form
end
When /^I drag context "([^"]*)" below context "([^"]*)"$/ do |context_drag, context_drop|
When /^I drag context "([^"]*)" above context "([^"]*)"$/ do |context_drag, context_drop|
drag_id = @current_user.contexts.find_by_name(context_drag).id
drop_id = @current_user.contexts.find_by_name(context_drop).id
container_height = selenium.get_element_height("//div[@id='container_context_#{drag_id}']").to_i
vertical_offset = container_height*2
coord_string = "10,#{vertical_offset}"
# container_height = page.driver.get_element_height("//div[@id='container_context_#{drag_id}']").to_i
# vertical_offset = container_height*2
# coord_string = "10,#{vertical_offset}"
drag_context_handle_xpath = "//div[@id='context_#{drag_id}']//span[@class='handle']"
drop_context_container_xpath = "//div[@id='container_context_#{drop_id}']"
drag_context_handle = find("div#context_#{drag_id} span.handle")
drag_context_handle.text.should == "DRAG"
drop_context_container = find("div#container_context_#{drop_id}")
selenium.mouse_down_at(drag_context_handle_xpath,"2,2")
selenium.mouse_move_at(drop_context_container_xpath,coord_string)
# no need to simulate mouse_over for this test
selenium.mouse_up_at(drop_context_container_xpath,coord_string)
drag_context_handle.drag_to(drop_context_container)
# TODO: omzetten naar volgende script
page.execute_script %Q{
$('.sortable-books li:last').simulateDragSortable({move: -4});
}
sleep(5)
# page.driver.mouse_down_at(drag_context_handle_xpath,"2,2")
# page.driver.mouse_move_at(drop_context_container_xpath,coord_string)
# # no need to simulate mouse_over for this test
# page.driver.mouse_up_at(drop_context_container_xpath,coord_string)
end
Then /^context "([^"]*)" should be above context "([^"]*)"$/ do |context_high, context_low|
high_id = @current_user.contexts.find_by_name(context_high).id
low_id = @current_user.contexts.find_by_name(context_low).id
high_pos = selenium.get_element_position_top("//div[@id='context_#{high_id}']").to_i
low_pos = selenium.get_element_position_top("//div[@id='context_#{low_id}']").to_i
(high_pos < low_pos).should be_true
high_id = "context_#{@current_user.contexts.find_by_name(context_high).id}"
low_id = "context_#{@current_user.contexts.find_by_name(context_low).id}"
contexts = page.all("div.context").map { |x| x[:id] }
contexts.find_index(high_id).should < contexts.find_index(low_id)
end
Then /^I should see that a context named "([^"]*)" is not present$/ do |context_name|
Then "I should not see \"#{context_name}\""
within "div#display_box" do
Then "I should not see \"#{context_name}\""
end
end
Then /^I should see that the context container for (.*) contexts is not present$/ do |state|
selenium.is_visible("list-#{state}-contexts-container").should_not be_true
page.has_css?("div#list-#{state}-contexts-container", :visible => true).should be_false
end
Then /^I should see that the context container for (.*) contexts is present$/ do |state|
selenium.is_visible("list-#{state}-contexts-container").should be_true
find("div#list-#{state}-contexts-container", :visible => true).should_not be_nil
end
Then /^I should see the context "([^"]*)" under "([^"]*)"$/ do |context_name, state|
context = Context.find_by_name(context_name)
context.should_not be_nil
response.should have_xpath("//div[@id='list-contexts-#{state}']//div[@id='context_#{context.id}']")
page.has_css?("div#list-contexts-#{state} div#context_#{context.id}").should be_true
end
Then /^the new context form should be visible$/ do
selenium.is_visible("context_new").should be_true
page.has_css?("div#context_new", :visible => true).should be_true
end
Then /^the new context form should not be visible$/ do
selenium.is_visible("context_new").should be_false
page.has_css?("div#context_new", :visible => true).should be_false
end
Then /^the context list badge for ([^"]*) contexts should show (\d+)$/ do |state_name, count|
selenium.get_text("xpath=//span[@id='#{state_name}-contexts-count']").should == count
find("span##{state_name}-contexts-count").text.should == count
end

View file

@ -54,7 +54,7 @@ Given /^I have a context "([^\"]*)" with (.*) actions$/ do |context_name, number
end
When /^I edit the context name in place to be "([^\"]*)"$/ do |new_context_name|
selenium.click "context_name"
page.find("span#context_name").click
fill_in "value", :with => new_context_name
click_button "Ok"
end

View file

@ -65,7 +65,9 @@ When /I change the (.*) field of "([^\"]*)" to "([^\"]*)"$/ do |field_name, todo
todo.should_not be_nil
open_edit_form_for(todo)
selenium.type("css=form.edit_todo_form input[name=#{field_name}]", new_value)
within "form.edit_todo_form" do
fill_in "#{field_name}", :with => new_value
end
submit_edit_todo_form(todo)
end