capybara-react-datetime 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5199dec52f2272f1287a1e37db3886985b9f37f3c21d1e4f4d9eb5310870aeae
4
+ data.tar.gz: b858486d5610c7a9b645a7ade7d688d924373a9640a7f72b16566ec6375218a4
5
+ SHA512:
6
+ metadata.gz: 4c0495edc403fec78171c44eea9cf90199e84193f1bb6ef6cec3cde5f8a37b156496a6a78eeb97a718e78e4f30b30159bb1eebcfe3503670416aff7ea158b0d4
7
+ data.tar.gz: f6518c13fc395dccbc1eeca5efd8c28bcedbe23a2e8a57a6e9ebf998ccfdf9cf9557bb73b895c19b1fde7fcdaaa8828ac52694576ec668c5dbcb315af259d0b3
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ *.sassc
4
+ .sass-cache
5
+ capybara-*.html
6
+ /.bundle
7
+ /vendor/bundle
8
+ /log/*
9
+ /tmp/*
10
+ /db/*.sqlite3
11
+ /public/system/*
12
+ /coverage/
13
+ /screenshot_*
14
+ /spec/tmp/*
15
+ **.orig
16
+ rerun.txt
17
+ pickle-email-*.html
18
+ /.yardoc
19
+ /doc
20
+
21
+ # RubyMine stuff
22
+ .idea
@@ -0,0 +1 @@
1
+ capybara-react-datetime
@@ -0,0 +1 @@
1
+ 2.5.3
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capybara-react-datetime.gemspec
4
+ gemspec
5
+
6
+ gem 'nokogiri', '>= 1.6.7.2'
7
+ gem 'rack', '>= 1.6.11'
@@ -0,0 +1,73 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ capybara-react-datetime (1.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.5.2)
10
+ public_suffix (>= 2.0.2, < 4.0)
11
+ capybara (3.11.1)
12
+ addressable
13
+ mini_mime (>= 0.1.3)
14
+ nokogiri (~> 1.8)
15
+ rack (>= 1.6.0)
16
+ rack-test (>= 0.6.3)
17
+ regexp_parser (~> 1.2)
18
+ xpath (~> 3.2)
19
+ capybara-screenshot (1.0.22)
20
+ capybara (>= 1.0, < 4)
21
+ launchy
22
+ cliver (0.3.2)
23
+ diff-lcs (1.3)
24
+ launchy (2.4.3)
25
+ addressable (~> 2.3)
26
+ mini_mime (1.0.1)
27
+ mini_portile2 (2.3.0)
28
+ nokogiri (1.8.5)
29
+ mini_portile2 (~> 2.3.0)
30
+ phantomjs (2.1.1.0)
31
+ poltergeist (1.18.1)
32
+ capybara (>= 2.1, < 4)
33
+ cliver (~> 0.3.1)
34
+ websocket-driver (>= 0.2.0)
35
+ public_suffix (3.0.3)
36
+ rack (2.0.6)
37
+ rack-test (1.1.0)
38
+ rack (>= 1.0, < 3)
39
+ regexp_parser (1.3.0)
40
+ rspec (3.8.0)
41
+ rspec-core (~> 3.8.0)
42
+ rspec-expectations (~> 3.8.0)
43
+ rspec-mocks (~> 3.8.0)
44
+ rspec-core (3.8.0)
45
+ rspec-support (~> 3.8.0)
46
+ rspec-expectations (3.8.2)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.8.0)
49
+ rspec-mocks (3.8.0)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.8.0)
52
+ rspec-support (3.8.0)
53
+ websocket-driver (0.7.0)
54
+ websocket-extensions (>= 0.1.0)
55
+ websocket-extensions (0.1.3)
56
+ xpath (3.2.0)
57
+ nokogiri (~> 1.8)
58
+
59
+ PLATFORMS
60
+ ruby
61
+
62
+ DEPENDENCIES
63
+ capybara (~> 3.11, >= 3.11.1)
64
+ capybara-react-datetime!
65
+ capybara-screenshot (~> 1.0, >= 1.0.22)
66
+ nokogiri (>= 1.6.7.2)
67
+ phantomjs (~> 2.1, >= 2.1.1.0)
68
+ poltergeist (~> 1.18, >= 1.18.1)
69
+ rack (>= 1.6.11)
70
+ rspec (~> 3.8, >= 3.8.0)
71
+
72
+ BUNDLED WITH
73
+ 1.17.3
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 François Vantomme
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,58 @@
1
+ # Capybara::ReactDatetime
2
+
3
+ Helper for changing date input of react-datetime library.
4
+
5
+ All this gem does is something very simple : allow you to trigger react-datetime to select the date you want.
6
+
7
+ ## Installation
8
+
9
+ Add this line into your test group:
10
+
11
+ ```ruby
12
+ group :test do
13
+ gem 'capybara-react-datetime', git: 'https://github.com/oshopgiri/capybara-react-datetime.git'
14
+ ...
15
+ end
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install capybara-react-datetime
25
+
26
+ The gem automatically hook itself into rspec helper using Rspec.configure.
27
+
28
+ ## Usage
29
+
30
+ Just use this method inside your capybara test:
31
+
32
+ ```ruby
33
+ select_date(2.weeks.ago, from: 'Label of the date input')
34
+ ```
35
+
36
+ Or even:
37
+
38
+ ```ruby
39
+ select_date(2.weeks.ago, from: 'Date', match: :prefer_exact)
40
+ select_date(Date.tomorrow, from: 'Label of the date input', format: '%d/%m/%Y')
41
+ select_date('2013-05-24', xpath: '//path_to//your_date_input', datepicker: true)
42
+ ```
43
+
44
+ Available options are:
45
+ + **from:** the label of your date input
46
+ + **xpath:** the path to your date input
47
+ + **format:** the format used to fill your date input (required if datepicker: false)
48
+ + **datepicker:** the way to fill your date input
49
+ + **true:** by clicking the popover
50
+ + **false:** directly fill the input date (default)
51
+
52
+ ## Contributing
53
+
54
+ 1. Fork it
55
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
56
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
57
+ 4. Push to the branch (`git push origin my-new-feature`)
58
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capybara-react-datetime/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'capybara-react-datetime'
8
+ gem.version = Capybara::ReactDatetime::VERSION
9
+ gem.authors = ['Osho Giri']
10
+ gem.email = ['oshopgiri@hotmail.com']
11
+ gem.summary = %q{react-datetime helper for Capybara}
12
+ gem.description = %q{Helper for changing date input of react-datetime library}
13
+ gem.homepage = 'https://github.com/oshopgiri/capybara-react-datetime'
14
+ gem.license = 'MIT'
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ['lib']
20
+
21
+ gem.required_ruby_version = '>= 2.3.8'
22
+
23
+ gem.add_development_dependency 'capybara', '~> 3.11', '>= 3.11.1'
24
+ gem.add_development_dependency 'rspec', '~> 3.8', '>= 3.8.0'
25
+ gem.add_development_dependency 'capybara-screenshot', '~> 1.0', '>= 1.0.22'
26
+ gem.add_development_dependency 'phantomjs', '~> 2.1', '>= 2.1.1.0'
27
+ gem.add_development_dependency 'poltergeist', '~> 1.18', '>= 1.18.1'
28
+ end
@@ -0,0 +1,207 @@
1
+ require 'capybara-react-datetime/version'
2
+
3
+ module Capybara
4
+ # Adds datepicker interaction facilities to {Capybara}
5
+ module ReactDatetime
6
+ # Selects a date by simulating human interaction with the datepicker or filling the input field
7
+ # @param value [#to_date, String] any object that responds to `#to_date` or a parsable date string
8
+ # @param datepicker [:bootstrap, :simple] the datepicker to use (are supported: bootstrap or input field)
9
+ # @param format [String, nil] a valid date format used to format value
10
+ # @param from [String, nil] the path to input field (required if `xpath` is nil)
11
+ # @param xpath [String, nil] the xpath to input field (required if `from` is nil)
12
+ # @param args [Hash] extra args to find the input field
13
+ def select_date(value, datepicker: false, format: nil, from: nil, xpath: nil, **args)
14
+ fail "Must pass a hash containing 'from' or 'xpath'" if from.nil? && xpath.nil?
15
+
16
+ value = value.respond_to?(:to_date) ? value.to_date : Date.parse(value)
17
+ date_input = xpath ? find(:xpath, xpath, **args) : find_field(from, **args)
18
+
19
+ if datepicker
20
+ select_bootstrap_date date_input, value
21
+ else
22
+ select_simple_date date_input, value, format
23
+ end
24
+
25
+ first(:xpath, '//body').click
26
+ end
27
+
28
+ # Selects a date by filling the input field
29
+ # @param date_input the input field
30
+ # @param value [Date] the date to set
31
+ # @param format [String, nil] a valid date format used to format value
32
+ def select_simple_date(date_input, value, format = nil)
33
+ value = value.strftime format unless format.nil?
34
+
35
+ date_input.set "#{value}\e"
36
+ end
37
+
38
+ # Selects a date by simulating human interaction with the datepicker
39
+ # @param (see #select_simple_date)
40
+ def select_bootstrap_date(date_input, value)
41
+ date_input.click
42
+
43
+ picker = Picker.new
44
+
45
+ picker.goto_decade_panel
46
+ picker.navigate_through_decades value.year
47
+
48
+ picker.find_year(value.year).click
49
+ picker.find_month(value.month).click
50
+ picker.find_day(value.day).click
51
+
52
+ fail if Date.parse(date_input.value) != value
53
+ end
54
+
55
+ private
56
+
57
+ # The Picker class interacts with the datepicker
58
+ class Picker
59
+ # Initializes the picker
60
+ def initialize
61
+ @element = find_picker
62
+ end
63
+
64
+ # Reveals the decade panel
65
+ def goto_decade_panel
66
+ current_month.click if days.visible?
67
+ current_year.click if months.visible?
68
+ end
69
+
70
+ # Navigates through the decade panels until the correct one
71
+ # @param value [Fixnum] the year of the desired date
72
+ def navigate_through_decades(value)
73
+ decade_start, decade_end = current_decade_minmax
74
+ goto_prev_decade(value, decade_start) if value < decade_start
75
+ goto_next_decade(decade_end, value) if value > decade_end
76
+ end
77
+
78
+ # Get the year we want to click on
79
+ # @param value [Fixnum] the year of the desired date
80
+ # @return the DOM element to click on
81
+ def find_year(value)
82
+ years.find '.rdtYear', text: value
83
+ end
84
+
85
+ # Get the month we want to click on
86
+ # @param value [Fixnum] the month of the desired date
87
+ # @return the DOM element to click on
88
+ def find_month(value)
89
+ months.find ".rdtMonth[data-value='#{value - 1}']"
90
+ end
91
+
92
+ # Get the day we want to click on
93
+ # @param value [Fixnum] the day of the desired date
94
+ # @return the DOM element to click on
95
+ def find_day(value)
96
+ day_xpath = <<-eos
97
+ .//*[contains(concat(' ', @class, ' '), ' rdtDay ')
98
+ and not(contains(concat(' ', @class, ' '), ' rdtOld '))
99
+ and not(contains(concat(' ', @class, ' '), ' rdtNew '))
100
+ and normalize-space(text())='#{value}']
101
+ eos
102
+ days.find :xpath, day_xpath
103
+ end
104
+
105
+ private
106
+
107
+ # Get the datepicker
108
+ # @return the DOM element of the datepicker
109
+ def find_picker
110
+ Capybara.find(:xpath, '//body').find('.rdtPicker')
111
+ end
112
+
113
+ # Get the datepicker panel
114
+ # @param period [:years, :months, :days] the panel's period
115
+ # @return the DOM element of the panel
116
+ def find_period(period)
117
+ @element.find(".rdt#{period.to_s.titleize}", visible: false)
118
+ end
119
+
120
+ # Get the up level panel
121
+ # @param (see #find_period)
122
+ # @return the DOM element of the switch panel button
123
+ def find_switch(period)
124
+ send(period).find('th.rdtSwitch', visible: false)
125
+ end
126
+
127
+ # Get the years panel
128
+ # @param (see #find_period)
129
+ # @return (see #find_period)
130
+ def years
131
+ find_period :years
132
+ end
133
+
134
+ # Get the months panel
135
+ # @param (see #find_period)
136
+ # @return (see #find_period)
137
+ def months
138
+ find_period :months
139
+ end
140
+
141
+ # Get the days panel
142
+ # @param (see #find_period)
143
+ # @return (see #find_period)
144
+ def days
145
+ find_period :days
146
+ end
147
+
148
+ # Get the current decade panel
149
+ # @param (see #find_switch)
150
+ # @return (see #find_switch)
151
+ def current_decade
152
+ find_switch :years
153
+ end
154
+
155
+ # Get the current year panel
156
+ # @param (see #find_switch)
157
+ # @return (see #find_switch)
158
+ def current_year
159
+ find_switch :months
160
+ end
161
+
162
+ # Get the current month panel
163
+ # @param (see #find_switch)
164
+ # @return (see #find_switch)
165
+ def current_month
166
+ find_switch :days
167
+ end
168
+
169
+ # Get the current decade period
170
+ # @return [Array<Fixnum, Fixnum>] the min and max years of the decade
171
+ def current_decade_minmax
172
+ current_decade.text.split('-').map(&:to_i)
173
+ end
174
+
175
+ # Click and display previous decade
176
+ def click_prev_decade
177
+ years.find('th.rdtPrev').click
178
+ end
179
+
180
+ # Click and display next decade
181
+ def click_next_decade
182
+ years.find('th.rdtNext').click
183
+ end
184
+
185
+ # Calculates the distance in decades between min and max
186
+ # @return [Fixnum] the distance in decades between min and max
187
+ def gap(min, max)
188
+ return 0 if min >= max
189
+ (max - min) / 10
190
+ end
191
+
192
+ # Go backward to the wanted decade
193
+ # @param value [Fixnum] the year of the desired date
194
+ # @param decade_start [Fixnum] the first year of a decade
195
+ def goto_prev_decade(value, decade_start)
196
+ gap(value, decade_start).times { click_prev_decade }
197
+ end
198
+
199
+ # Go forward to the wanted decade
200
+ # @param decade_end [Fixnum] the last year of a decade
201
+ # @param value [Fixnum] the year of the desired date
202
+ def goto_next_decade(decade_end, value)
203
+ gap(decade_end, value).times { click_next_decade }
204
+ end
205
+ end
206
+ end
207
+ end
@@ -0,0 +1,5 @@
1
+ require 'capybara-react-datetime'
2
+
3
+ RSpec.configure do |c|
4
+ c.include Capybara::ReactDatetime
5
+ end
@@ -0,0 +1,7 @@
1
+ # The gem's version
2
+ module Capybara
3
+ module ReactDatetime
4
+ # the current version of the gem
5
+ VERSION = '1.0.1'
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ require '../capybara-react-datetime'
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capybara-react-datetime
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Osho Giri
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capybara
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.11'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 3.11.1
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '3.11'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 3.11.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 3.8.0
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '3.8'
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 3.8.0
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '3.8'
53
+ - !ruby/object:Gem::Dependency
54
+ name: capybara-screenshot
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.0'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 1.0.22
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.0'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 1.0.22
73
+ - !ruby/object:Gem::Dependency
74
+ name: phantomjs
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '2.1'
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 2.1.1.0
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.1'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 2.1.1.0
93
+ - !ruby/object:Gem::Dependency
94
+ name: poltergeist
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '1.18'
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 1.18.1
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '1.18'
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 1.18.1
113
+ description: Helper for changing date input of react-datetime library
114
+ email:
115
+ - oshopgiri@hotmail.com
116
+ executables: []
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - ".gitignore"
121
+ - ".ruby-gemset"
122
+ - ".ruby-version"
123
+ - Gemfile
124
+ - Gemfile.lock
125
+ - LICENSE.txt
126
+ - README.md
127
+ - Rakefile
128
+ - capybara-react-datetime.gemspec
129
+ - lib/capybara-react-datetime.rb
130
+ - lib/capybara-react-datetime/rspec.rb
131
+ - lib/capybara-react-datetime/version.rb
132
+ - lib/capybara/react-datetime.rb
133
+ homepage: https://github.com/oshopgiri/capybara-react-datetime
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: 2.3.8
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubygems_version: 3.0.3
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: react-datetime helper for Capybara
156
+ test_files: []