Skip to content

Commit

Permalink
Move nav title to helper and add check method
Browse files Browse the repository at this point in the history
  • Loading branch information
joemasilotti committed Jun 13, 2014
1 parent 61307b4 commit b90b3a7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 18 deletions.
20 changes: 2 additions & 18 deletions gem/lib/frank-cucumber/core_frank_steps.rb
Expand Up @@ -18,31 +18,15 @@
}
end

def navigation_title_exists_with_text(quoted_text)
navFrame = frankly_map('view:"UINavigationBar"', 'frame').first
navCenter = navFrame["size"]["width"] / 2.0

frame = frankly_map("view:'UINavigationBar' view:'UINavigationItemView' marked:#{quoted_text}", 'frame').first
return false unless frame && frame["origin"] && frame["size"]

left = frame["origin"]["x"]
right = frame["origin"]["x"] + frame["size"]["width"]
return false unless left && right && left < right

(left < navCenter) && (navCenter < right)
end

Then /^I should see a navigation bar titled "([^\"]*)"$/ do |expected_mark|
quote = get_selector_quote(expected_mark)
quoted_text = "#{quote}#{expected_mark}#{quote}"
navigation_title_exists_with_text("#{quoted_text}").should be_true, "expected to see a navigation bar titled #{quoted_text}"
end

Then /^I wait to see a navigation bar titled "([^\"]*)"$/ do |expected_mark|
quote = get_selector_quote(expected_mark)
quoted_text = "#{quote}#{expected_mark}#{quote}"
Then /^I wait to see a navigation bar titled "([^\"]*)"$/ do |expected_title|
wait_until(message: "waited to see a navigation bar titled #{quoted_text}") do
navigation_title_exists_with_text("#{quoted_text}")
navigation_title_with_text_exists(expected_title)
end
end

Expand Down
39 changes: 39 additions & 0 deletions gem/lib/frank-cucumber/frank_helper.rb
Expand Up @@ -155,6 +155,25 @@ def view_with_mark_exists(expected_mark)
element_exists( "view marked:#{quote}#{expected_mark}#{quote}" )
end

# Indicate whether the title of the navigation bar matches the expected title.
# @param [String] expected_title the expected title of the navigation bar
# @return [Boolean]
def navigation_title_with_text_exists(expected_title)
quoted_text = "#{quote}#{expected_title}#{quote}"

navFrame = frankly_map('view:"UINavigationBar"', 'frame').first
navCenter = navFrame["size"]["width"] / 2.0

frame = frankly_map("view:'UINavigationBar' view:'UINavigationItemView' marked:#{quoted_text}", 'frame').first
return false unless frame && frame["origin"] && frame["size"]

left = frame["origin"]["x"]
right = frame["origin"]["x"] + frame["size"]["width"]
return false unless left && right && left < right

(left < navCenter) && (navCenter < right)
end

# Assert whether there are any views in the current view heirarchy which contain the specified accessibility label.
# @param [String] expected_mark the expected accessibility label
# @raise an rspec exception if the assertion fails
Expand All @@ -173,6 +192,26 @@ def check_view_with_mark_does_not_exist(expected_mark)
check_element_does_not_exist( "view marked:#{quote}#{expected_mark}#{quote}" )
end

# Assert the title of the navigation bar.
# @param [String] expected_title the expected title of the navigation bar
# @raise an rspec exception if the assertion fails
# @raise an rspec exception if the navigation bar and its subview `UINavigationItemView` cannot be found
# @raise an rspec exception if the `UINavigationItemView` does not cover the center x of the navigation bar
def check_navigation_title_with_text_exists(expected_title)
quoted_text = "#{quote}#{expected_title}#{quote}"

navFrame = frankly_map('view:"UINavigationBar"', 'frame').first
navCenter = navFrame["size"]["width"] / 2.0

frame = frankly_map("view:'UINavigationBar' view:'UINavigationItemView' marked:#{quoted_text}", 'frame').first
raise "Could not find navigation bar with title (#{expected_title})" unless frame && frame["origin"] && frame["size"]

left = frame["origin"]["x"]
right = frame["origin"]["x"] + frame["size"]["width"]
raise "Expected title (#{expected_title}) not in center of navigation bar" unless left && right && left < right

((left < navCenter) && (navCenter < right)).should be_true, "Could not find navigation title in center of navigation bar matching text (#{expected_title})"
end

# Waits for any of the specified selectors to match a view.
#
Expand Down

0 comments on commit b90b3a7

Please sign in to comment.