Skip to content
Browse files

Implement autocomplete steps.

  • Loading branch information...
1 parent e6df772 commit bf1a6e837f2952f600b33534f52360e9f5a5ab7a @jfirebaugh committed Oct 17, 2010
View
17 features/step_definitions.feature
@@ -17,6 +17,23 @@ Feature: Step definitions
And the "Section 2" accordion section should be active
And I should see "Sed non urna" within the "Section 2" accordion section
+ Scenario: Autocomplete steps
+ When I visit the autocomplete page
+ And I fill in "Tags" with "R"
+ Then I should see the following completions:
+ | ActionScript |
+ | AppleScript |
+ | Clojure |
+ | Erlang |
+ | Fortran |
+ | Groovy |
+ | JavaScript |
+ | Perl |
+ | Ruby |
+
+ When I select the "Ruby" completion
+ Then the "Tags" field should contain "Ruby"
+
Scenario: Dialog steps
When I visit the dialog page
Then I should see the "Basic dialog" dialog
View
8 features/step_definitions/web_steps.rb
@@ -24,3 +24,11 @@ def with_scope(locator)
Then /^I should see "([^"]+)"$/ do |text|
page.should have_content(text)
end
+
+When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
+ fill_in(field, :with => value)
+end
+
+Then /^the "([^"]*)" field should contain "([^"]*)"$/ do |field, value|
+ find_field(field).value.should == value
+end
View
7 lib/bermuda/cucumber.rb
@@ -22,11 +22,12 @@
# Autocomplete
Then /^I should see the following completions:$/ do |choices|
- pending
+ wait_until { page.has_xpath?(Bermuda::XPath.autocompletion) }
+ choices.diff!(all(:xpath, Bermuda::XPath.autocompletion).map {|node| [node.text]})
end
-When /^I select the "([^"]+)" completion$/ do |title|
- pending
+When /^I select the "([^"]+)" completion$/ do |text|
+ find(:xpath, Bermuda::XPath.autocompletion(text).child(:a)).click
end
# Dialog
View
7 lib/bermuda/xpath.rb
@@ -33,6 +33,13 @@ def accordion_header(title = nil, options = {})
xpath
end
+ def autocompletion(text = nil)
+ xpath = descendant[attr(:class).includes('ui-autocomplete')]
+ xpath = xpath.descendant[attr(:class).includes('ui-menu-item')]
+ xpath = xpath[descendant(:a).text.is text] if text
+ xpath
+ end
+
def accordion_content(title = nil, options = {})
accordion_header(title, options).next_sibling
end
View
46 public/autocomplete.html
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Autocomplete</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() {
+ var availableTags = [
+ "ActionScript",
+ "AppleScript",
+ "Asp",
+ "BASIC",
+ "C",
+ "C++",
+ "Clojure",
+ "COBOL",
+ "ColdFusion",
+ "Erlang",
+ "Fortran",
+ "Groovy",
+ "Haskell",
+ "Java",
+ "JavaScript",
+ "Lisp",
+ "Perl",
+ "PHP",
+ "Python",
+ "Ruby",
+ "Scala",
+ "Scheme"
+ ];
+ $( "#tags" ).autocomplete({
+ source: availableTags
+ });
+ });
+ </script>
+</head>
+<body>
+<div class="ui-widget">
+ <label for="tags">Tags: </label>
+ <input id="tags">
+</div>
+</body>
+</html>

0 comments on commit bf1a6e8

Please sign in to comment.
Something went wrong with that request. Please try again.