mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-24 03:00:12 +01:00
Move over another ajax test from selenium to stories.
This commit is contained in:
parent
6f760c768e
commit
adde38eecb
3 changed files with 82 additions and 5 deletions
15
stories/context_detail/change_context_name.story
Normal file
15
stories/context_detail/change_context_name.story
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
Story: Change context name
|
||||
|
||||
As a Tracks user
|
||||
I want to change the name of a context
|
||||
So that it can best reflect my daily life
|
||||
|
||||
Scenario: In place edit of context name
|
||||
Given a logged in user Luis
|
||||
And Luis has a context Errands
|
||||
When Luis visits the Errands context page
|
||||
And he edits the Errands context name in place to be OutAndAbout
|
||||
Then he should see the context name is OutAndAbout
|
||||
When Luis visits the context listing page
|
||||
Then he should see that a context named Errands is not present
|
||||
And he should see that a context named OutAndAbout is present
|
||||
34
stories/steps/context_detail.rb
Normal file
34
stories/steps/context_detail.rb
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
steps_for :context_detail do
|
||||
include_steps_for :users
|
||||
|
||||
Given "Luis has a context Errands" do
|
||||
@errands = @luis.contexts.create!(:name => 'Errands')
|
||||
end
|
||||
|
||||
When "Luis visits the Errands context page" do
|
||||
visits "/contexts/#{@errands.to_param}"
|
||||
end
|
||||
|
||||
When "he edits the Errands context name in place to be OutAndAbout" do
|
||||
selenium.click 'context_name_in_place_editor'
|
||||
wait_for_ajax_and_effects
|
||||
selenium.type "css=#context_name_in_place_editor-inplaceeditor input.editor_field", "OutAndAbout"
|
||||
clicks_button "ok", :wait => :ajax
|
||||
end
|
||||
|
||||
When "Luis visits the context listing page" do
|
||||
visits "/contexts"
|
||||
end
|
||||
|
||||
Then "he should see the context name is OutAndAbout" do
|
||||
should_see 'OutAndAbout'
|
||||
end
|
||||
|
||||
Then "he should see that a context named Errands is not present" do
|
||||
should_not_see 'Errands'
|
||||
end
|
||||
|
||||
Then "he should see that a context named OutAndAbout is present" do
|
||||
should_see 'OutAndAbout'
|
||||
end
|
||||
end
|
||||
|
|
@ -10,8 +10,13 @@ module Webrat
|
|||
@selenium.open(url)
|
||||
end
|
||||
|
||||
def fills_in(label_text, options)
|
||||
@selenium.type("webrat=#{label_text}", "#{options[:with]}")
|
||||
def fills_in(field_identifier, options)
|
||||
locator = if field_identifier == :current
|
||||
"css=:focus"
|
||||
else
|
||||
"webrat=#{Regexp.escape(field_identifier)}"
|
||||
end
|
||||
@selenium.type(locator, "#{options[:with]}")
|
||||
end
|
||||
|
||||
def response_body
|
||||
|
|
@ -25,11 +30,16 @@ module Webrat
|
|||
wait_for_result(options[:wait])
|
||||
end
|
||||
|
||||
def clicks_link(link_text, options = {})
|
||||
def clicks_link(link_text, options = {})
|
||||
@selenium.click("webratlink=#{link_text}")
|
||||
wait_for_result(options[:wait])
|
||||
end
|
||||
|
||||
def clicks_link_within(selector, link_text, options = {})
|
||||
@selenium.click("webratlinkwithin=#{selector}|#{link_text}")
|
||||
wait_for_result(options[:wait])
|
||||
end
|
||||
|
||||
def wait_for_result(wait_type)
|
||||
if wait_type == :ajax
|
||||
wait_for_ajax
|
||||
|
|
@ -55,8 +65,8 @@ module Webrat
|
|||
def wait_for_ajax_and_effects
|
||||
wait_for_ajax
|
||||
wait_for_effects
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def selects(option_text, options = {})
|
||||
id_or_name_or_label = options[:from]
|
||||
|
||||
|
|
@ -130,6 +140,24 @@ module Webrat
|
|||
return candidateLinks.first();
|
||||
JS
|
||||
|
||||
@selenium.add_location_strategy('webratlinkwithin', <<-JS)
|
||||
var locatorParts = locator.split('|');
|
||||
var cssAncestor = locatorParts[0];
|
||||
var linkText = locatorParts[1];
|
||||
var matchingElements = cssQuery(cssAncestor, inDocument);
|
||||
var candidateLinks = matchingElements.collect(function(ancestor){
|
||||
var links = ancestor.getElementsByTagName('a');
|
||||
return $A(links).select(function(candidateLink) {
|
||||
return PatternMatcher.matches(linkText, getText(candidateLink));
|
||||
});
|
||||
}).flatten().compact();
|
||||
if (candidateLinks.length == 0) {
|
||||
return null;
|
||||
}
|
||||
candidateLinks = candidateLinks.sortBy(function(s) { return s.length * -1; }); //reverse length sort
|
||||
return candidateLinks.first();
|
||||
JS
|
||||
|
||||
@selenium.add_location_strategy('webratselectwithoption', <<-JS)
|
||||
var optionElements = inDocument.getElementsByTagName('option');
|
||||
var locatedOption = $A(optionElements).find(function(candidate){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue