Permalink
Browse files

Implement tabs steps.

  • Loading branch information...
jfirebaugh committed Oct 18, 2010
1 parent e3fda15 commit 13ab6a392397f3211f18d097cd8adc79e0eaeb19
Showing with 69 additions and 5 deletions.
  1. +14 −0 features/step_definitions.feature
  2. +2 −0 features/support/selectors.rb
  3. +5 −5 lib/bermuda/cucumber.rb
  4. +17 −0 lib/bermuda/xpath.rb
  5. +31 −0 public/tabs.html
@@ -16,3 +16,17 @@ Feature: Step definitions
And the "Section 1" accordion section should not be active
And the "Section 2" accordion section should be active
And I should see "Sed non urna" within the "Section 2" accordion section
+
+ Scenario: Tabs steps
+ When I visit the tabs page
+ Then I should see the following tabs:
+ | Nunc tincidunt |
+ | Proin dolor |
+ | Aenean lacinia |
+ And the "Nunc tincidunt" tab should be active
+ And the "Proin dolor" tab should not be active
+
+ When I activate the "Proin dolor" tab
+ And the "Nunc tincidunt" tab should not be active
+ And the "Proin dolor" tab should be active
+ And I should see "Morbi tincidunt" within the "Proin dolor" tab
@@ -10,6 +10,8 @@ def selector_for(locator)
when /the "([^"]+)" accordion section/
[:xpath, Bermuda::XPath.accordion_content($1)]
+ when /the "([^"]+)" tab/
+ [:xpath, Bermuda::XPath.tab_content($1)]
else
raise "Can't find mapping from \"#{locator}\" to a selector.\n" +
View
@@ -59,20 +59,20 @@
pending
end
-# Tab
+# Tabs
Then /^I should see the following tabs:$/ do |titles|
- pending
+ titles.diff!(all(:xpath, Bermuda::XPath.tab_header).map {|node| [node.text]})
end
Then /^the "([^"]+)" tab should be active$/ do |title|
- pending
+ page.should have_xpath(Bermuda::XPath.tab_header(title, :active => true))
end
Then /^the "([^"]+)" tab should not be active$/ do |title|
- pending
+ page.should have_xpath(Bermuda::XPath.tab_header(title, :active => false))
end
When /^I activate the "([^"]+)" tab$/ do |title|
- pending
+ find(:xpath, Bermuda::XPath.tab_header(title).child(:a)).click
end
View
@@ -36,5 +36,22 @@ def accordion_header(title = nil, options = {})
def accordion_content(title = nil, options = {})
accordion_header(title, options).next_sibling
end
+
+ def tab_header(title = nil, options = {})
+ xpath = descendant[attr(:class).includes('ui-tabs-nav')].child
+
+ if options.key?(:active)
+ state = attr(:class).includes('ui-state-active')
+ state = ~state unless options[:active]
+ xpath = xpath[state]
+ end
+
+ xpath = xpath[descendant(:a).text.is title] if title
+ xpath
+ end
+
+ def tab_content(title = nil, options = {})
+ descendant[Expression::Literal.new("concat('#', @id)") == anywhere(tab_header(title, options)).descendant(:a).attr(:href)]
+ end
end
end
View
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Tabs</title>
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
+ <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js"></script>
+ <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/themes/base/jquery-ui.css">
+ <script>
+ $(function() { $( "#tabs" ).tabs(); });
+ </script>
+</head>
+<body>
+<div id="tabs">
+ <ul>
+ <li><a href="#tabs-1">Nunc tincidunt</a></li>
+ <li><a href="#tabs-2">Proin dolor</a></li>
+ <li><a href="#tabs-3">Aenean lacinia</a></li>
+ </ul>
+ <div id="tabs-1">
+ <p>Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. Donec sollicitudin mi sit amet mauris. Nam elementum quam ullamcorper ante. Etiam aliquet massa et lorem. Mauris dapibus lacus auctor risus. Aenean tempor ullamcorper leo. Vivamus sed magna quis ligula eleifend adipiscing. Duis orci. Aliquam sodales tortor vitae ipsum. Aliquam nulla. Duis aliquam molestie erat. Ut et mauris vel pede varius sollicitudin. Sed ut dolor nec orci tincidunt interdum. Phasellus ipsum. Nunc tristique tempus lectus.</p>
+ </div>
+ <div id="tabs-2">
+ <p>Morbi tincidunt, dui sit amet facilisis feugiat, odio metus gravida ante, ut pharetra massa metus id nunc. Duis scelerisque molestie turpis. Sed fringilla, massa eget luctus malesuada, metus eros molestie lectus, ut tempus eros massa ut dolor. Aenean aliquet fringilla sem. Suspendisse sed ligula in ligula suscipit aliquam. Praesent in eros vestibulum mi adipiscing adipiscing. Morbi facilisis. Curabitur ornare consequat nunc. Aenean vel metus. Ut posuere viverra nulla. Aliquam erat volutpat. Pellentesque convallis. Maecenas feugiat, tellus pellentesque pretium posuere, felis lorem euismod felis, eu ornare leo nisi vel felis. Mauris consectetur tortor et purus.</p>
+ </div>
+ <div id="tabs-3">
+ <p>Mauris eleifend est et turpis. Duis id erat. Suspendisse potenti. Aliquam vulputate, pede vel vehicula accumsan, mi neque rutrum erat, eu congue orci lorem eget lorem. Vestibulum non ante. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce sodales. Quisque eu urna vel enim commodo pellentesque. Praesent eu risus hendrerit ligula tempus pretium. Curabitur lorem enim, pretium nec, feugiat nec, luctus a, lacus.</p>
+ <p>Duis cursus. Maecenas ligula eros, blandit nec, pharetra at, semper at, magna. Nullam ac lacus. Nulla facilisi. Praesent viverra justo vitae neque. Praesent blandit adipiscing velit. Suspendisse potenti. Donec mattis, pede vel pharetra blandit, magna ligula faucibus eros, id euismod lacus dolor eget odio. Nam scelerisque. Donec non libero sed nulla mattis commodo. Ut sagittis. Donec nisi lectus, feugiat porttitor, tempor ac, tempor vitae, pede. Aenean vehicula velit eu tellus interdum rutrum. Maecenas commodo. Pellentesque nec elit. Fusce in lacus. Vivamus a libero vitae lectus hendrerit hendrerit.</p>
+ </div>
+</div>
+</body>
+</html>

0 comments on commit 13ab6a3

Please sign in to comment.