da-js 1.2.1 → 1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,142 +0,0 @@
1
- RSpec::Matchers.define :be_marked_as_changed do
2
- match do |element|
3
- (element["class"] || "").split(" ").include?("changed")
4
- end
5
- end
6
-
7
- def find_element_and_label(element)
8
- id = "#{@form}_#{element}"
9
- [find("##{@form} ##{id}"), find("##{@form} label[for='#{id}']")]
10
- end
11
-
12
- def find_container(element)
13
- container = case @form
14
- when /^scaffold_form/ then "div[contains(@class, 'field')]"
15
- when /^formtastic/ then "li[contains(@class, 'input')]"
16
- else raise "I don't know about '#{@form}' forms ..."
17
- end
18
- within "##{@form}" do
19
- element_id = find_field(element)["id"]
20
- find :xpath, ".//#{container}[.//*[@id='#{element_id}']]"
21
- end
22
- end
23
-
24
- Given /^an? (empty|prefilled) (\w+)$/ do |type, form|
25
- visit "/form_change_tracker"
26
- @form = form.dup # Without #dup Cucumber prints the step incorrectly
27
- @form << "_prefilled" if type == "prefilled"
28
- end
29
-
30
-
31
- When /^I enter some text in the (\w+)$/ do |field|
32
- within "##{@form}" do
33
- fill_in field, :with => "foobar"
34
- end
35
- end
36
-
37
- When /^I change the (\w+)'s content$/ do |field|
38
- within "##{@form}" do
39
- fill_in field, :with => find_field(field).value + " plus some new text"
40
- end
41
- end
42
-
43
- When /^I clear the (\w+)$/ do |field|
44
- within "##{@form}" do
45
- fill_in field, :with => ""
46
- end
47
- end
48
-
49
- When /^I reset the (\w+) to its initial value$/ do |field|
50
- within "##{@form}" do
51
- fill_in field, :with => "text"
52
- end
53
- end
54
-
55
- When /^I (check|uncheck) the checkbox$/ do |action|
56
- within "##{@form}" do
57
- if action == "check"
58
- check "checkbox"
59
- else
60
- uncheck "checkbox"
61
- end
62
- end
63
- end
64
-
65
- When /^I choose the (first|second) radiobutton$/ do |which|
66
- button = (which == "first" ? "1" : (which == "second" ? "2" : "3"))
67
- within "##{@form}" do
68
- choose button
69
- end
70
- end
71
-
72
- When /^I select the (blank|first|second) option$/ do |which|
73
- option = (which == "blank" ? "" : (which == "first" ? "option 1" : "option 2"))
74
- within "##{@form}" do
75
- select option
76
- end
77
- end
78
-
79
- When /^I select the empty option$/ do
80
- within "##{@form}" do
81
- select ""
82
- end
83
- end
84
-
85
-
86
- Then /^no form element and label should be marked as changed$/ do
87
- within "##{@form}" do
88
- all("input,textarea,select,label").each do |element|
89
- element.should_not be_marked_as_changed
90
- end
91
- end
92
- end
93
-
94
- Then /^no field container should be marked as changed$/ do
95
- within "##{@form}" do
96
- all(".field").each do |element|
97
- element.should_not be_marked_as_changed
98
- end
99
- end
100
- end
101
-
102
- Then /^the (first|second|third) radiobutton's form element and label should( not| no longer)? be marked as changed$/ do |which, no_longer|
103
- button = (which == "first" ? "1" : (which == "second" ? "2" : "3"))
104
- element, label = find_element_and_label("radiobutton_#{button}")
105
- if no_longer
106
- element.should_not be_marked_as_changed
107
- label.should_not be_marked_as_changed
108
- else
109
- element.should be_marked_as_changed
110
- label.should be_marked_as_changed
111
- end
112
- end
113
-
114
- Then /^the (first|second|third) radiobutton's field container should( not| no longer)? be marked as changed$/ do |which, no_longer|
115
- button = (which == "first" ? "1" : (which == "second" ? "2" : "3"))
116
- container = find_container("radiobutton #{button}")
117
- if no_longer
118
- container.should_not be_marked_as_changed
119
- else
120
- container.should be_marked_as_changed
121
- end
122
- end
123
-
124
- Then /^the (\w+)'s form element and label should( no longer)? be marked as changed$/ do |element, no_longer|
125
- element, label = find_element_and_label(element)
126
- if no_longer
127
- element.should_not be_marked_as_changed
128
- label.should_not be_marked_as_changed
129
- else
130
- element.should be_marked_as_changed
131
- label.should be_marked_as_changed
132
- end
133
- end
134
-
135
- Then /^the (\w+)'s field container should( no longer)? be marked as changed$/ do |element, no_longer|
136
- container = find_container(element)
137
- if no_longer
138
- container.should_not be_marked_as_changed
139
- else
140
- container.should be_marked_as_changed
141
- end
142
- end
@@ -1,59 +0,0 @@
1
- Given %r{^I bind an event listener to "([^"]*)"$} do |event|
2
- page.execute_script %{
3
- if (!window.eventCounts) window.eventCounts = {};
4
- window.eventCounts['#{event}'] = 0;
5
- $('body').on('#{event}', function(){ window.eventCounts['#{event}']++ });
6
- }
7
- end
8
-
9
- Then %r{^the event listener for "([^"]*)" should have been called "([^"]*)" times?$} do |event, counter|
10
- actual = page.evaluate_script "window.eventCounts['#{event}']"
11
- actual.should eq counter.to_i
12
- end
13
-
14
- Then %r{^the "([^"]*)" input should be hidden$} do |input|
15
- find_field(input, visible: false).should_not be_visible
16
- end
17
-
18
- Then %r{^the "([^"]*)" input should be visible$} do |input|
19
- find_field(input).should be_visible
20
- end
21
-
22
- Then %r{^the "([^"]*)" element should be hidden$} do |selector|
23
- find(selector, visible: false).should_not be_visible
24
- end
25
-
26
- Then %r{^the "([^"]*)" element should be visible$} do |selector|
27
- find(selector).should be_visible
28
- end
29
-
30
- When %r{^I select "([^"]*)" from the "([^"]*)" select$} do |option, input|
31
- select option, :from => input
32
- end
33
-
34
- When %r{^I uncheck the "([^"]*)" checkbox$} do |input|
35
- uncheck input
36
- end
37
-
38
- When %r{^I check the "([^"]*)" checkbox$} do |input|
39
- check input
40
- end
41
-
42
- When %r{I enter "([^"]*)" in the "([^"]*)" field} do |value, input|
43
- fill_in input, with: value
44
- end
45
-
46
- When %r{I blur the "([^"]*)" field} do |input|
47
- find_field(input).trigger("blur")
48
- end
49
-
50
- When %r{^I set the "([^"]*)" checkbox to unchecked using JavaScript$} do |input|
51
- id = find_field(input)["id"]
52
- page.execute_script "$('##{id}')[0].checked = false"
53
- end
54
-
55
- When %r{^I trigger the "([^"]*)" event on the form$} do |event|
56
- page.execute_script "$('form').trigger('#{event}')"
57
- end
58
-
59
-
@@ -1,25 +0,0 @@
1
- Given %r{the HTML element has a lang attribute set to "([^"]*)"$} do |lang|
2
- page.execute_script("$('html').attr('lang', '#{lang}')")
3
- end
4
-
5
- Given %r{the element "([^"]*)" has a lang attribute set to "([^"]*)"$} do |id, lang|
6
- page.execute_script("$('##{id}').attr('lang', '#{lang}')")
7
- end
8
-
9
- Then %r{^the numeric value of "([^"]*)" should be "([^"]*)"$} do |input, value|
10
- page.evaluate_script("$('##{input}').numericValue()").should be_within(0.0001).of value.to_f
11
- end
12
-
13
- Then %r{^the numeric value \(ignoring currency sign\) of "([^"]*)" should be "([^"]*)"$} do |input, value|
14
- page.evaluate_script("$('##{input}').numericValue({ignoreCurrencySign: true})").should be_within(0.0001).of value.to_f
15
- end
16
-
17
- Then %r{^the numeric value \(using `nullOnError: true`\) of "([^"]*)" should be "([^"]*)"$} do |input, value|
18
- actual = page.evaluate_script("$('##{input}').numericValue({nullOnError: true})")
19
- if value == "null"
20
- actual.should eq("")
21
- else
22
- actual.should be_within(0.0001).of(value.to_f)
23
- end
24
- end
25
-
@@ -1,15 +0,0 @@
1
- require "active_support/inflector"
2
- require "active_support/core_ext/object/to_query"
3
-
4
- When %r{^I visit the test page for "([^"]*)"$} do |feature|
5
- visit "/#{feature.parameterize '_'}"
6
- end
7
-
8
- When %r{^I visit the test page for "([^"]*)" with options "([^"]*)"?$} do |feature, options|
9
- visit "/#{feature.parameterize '_'}?" + {options: options}.to_query
10
- end
11
-
12
- When %r{^I fill in "([^"]*)" with "([^"]*)"$} do |input, value|
13
- fill_in input, :with => value
14
- end
15
-
@@ -1,8 +0,0 @@
1
- require "rails/engine"
2
- require "capybara/cucumber"
3
- require "capybara-webkit"
4
- require "rack"
5
- require "rspec/expectations"
6
-
7
- Capybara.javascript_driver = :webkit
8
- Capybara.app, _ = Rack::Builder.parse_file(File.dirname(__FILE__) + "/testapp/config.ru")
@@ -1,12 +0,0 @@
1
- require 'sprockets'
2
- require File.dirname(__FILE__) + "/testapp"
3
-
4
- map '/assets' do
5
- environment = Sprockets::Environment.new
6
- environment.append_path File.dirname(__FILE__) + '/../../../lib/assets'
7
- run environment
8
- end
9
-
10
- map '/' do
11
- run Sinatra::Application
12
- end
@@ -1,23 +0,0 @@
1
- require "sinatra"
2
- require "sinatra/reloader" if development?
3
- require "coffee_script"
4
-
5
- set :app_file, __FILE__
6
- disable :logging
7
-
8
- before do
9
- @jquery_version = params[:jquery] || "1.11.1"
10
- end
11
-
12
- get "/vendor/:file" do |file|
13
- send_file settings.root + "/vendor/#{file}"
14
- end
15
-
16
- # Don't spam console/log with errors caused by a missing favicon
17
- get "/favicon.ico" do
18
- 404
19
- end
20
-
21
- get "/:view" do |view|
22
- erb view.to_sym
23
- end