capybara-bootstrap-datepicker 0.0.9 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 619fa46bebfc704db2c86b6d049078073dae8364
4
- data.tar.gz: c79c6e0342a20b5f774c4a7c718d4fe029fa00e8
2
+ SHA256:
3
+ metadata.gz: 474239354a4fa4484007acd25d0e8deeab89d1884b6be95becc964ad84af4c9c
4
+ data.tar.gz: 4a457207ec5c510526b7d61b7aa6ff3c37989dfed871b0e866545f9bce675d0b
5
5
  SHA512:
6
- metadata.gz: cb65bd9d7e6c99e02220bff0375f274b340e9878cda6523ffa66f705e2ff28f9efca5adf9b8b7c9ae2f41bcc4949d0333b56eb981ed21a4853956c52a8b47fb7
7
- data.tar.gz: 9f7e7167d4e9d9fd58832d3669ac844087953bcb89267686bfd7f9459e4003e4c8c12aa832d954ce7a197bd64f4c80678d57710b40a710e0def264082c080fe4
6
+ metadata.gz: 1b301917b94b001c16f4e7626ecbf86ae8773cd6d39247bd104f205163c342dc6ca20a5160f46837fdb3b7ea09a1a89b0a2d6c8d223f98acb802d6b7d3c83919
7
+ data.tar.gz: 0e88d4249bf4e5bd17e1aedb2629d0ab4e44699cbc265c537922bbb28c8a6dd0f7e1627918b4ab1eaabdc7f939eca383ce53defdec606b5add6bc0e9d2cd412b
data/.gitignore CHANGED
@@ -3,7 +3,6 @@
3
3
  *.sassc
4
4
  .sass-cache
5
5
  capybara-*.html
6
- .rspec
7
6
  /.bundle
8
7
  /vendor/bundle
9
8
  /log/*
@@ -11,8 +10,10 @@ capybara-*.html
11
10
  /db/*.sqlite3
12
11
  /public/system/*
13
12
  /coverage/
13
+ /screenshot_*
14
14
  /spec/tmp/*
15
15
  **.orig
16
16
  rerun.txt
17
17
  pickle-email-*.html
18
- /Gemfile.lock
18
+ /.yardoc
19
+ /doc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1 @@
1
+ 2.5.7
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.6.5"
4
+ - "2.5.7"
5
+ before_install:
6
+ - gem install bundler
7
+ script: bundle exec rspec spec
8
+ addons:
9
+ code_climate:
10
+ repo_token:
11
+ secure: SFpmOHwZ3HBMqMH0NKq0B6DqoQjeDtsr5V9YCRLM7D6LvkoMhbkFYPoNo4nz6EWQ0Ml9JzP7ORumUPv1ujhCcYV+yLQ5eIL/xg+g+3H0Xu1sx6CuzDY4C7mZJO5s84KoH7yu9pBrlIa+UJwezwrCOm7JWURsPhR94YvmKobyOZHEuAyvUbYb+eqAkYfXrl71dC6hywfdlSOP/OEncPpIDZ6EApfWRhqZYHHHoj9EqXuHasNzmr6c2cqAh++7XDIOlHJ8JUEjeZN9ofTrqN4oq4JkGvIVmUHOe62jaj92z4vi3ZH+4lv0GmM5KlxgwRZKcCts5WivaNTyQzUnInUbWlWcIHnBFQMPj17ggjhixb6O+w3uAKlbLUGDYkKRSc+MWEdURpFIhyNCMtesHA1GS9+aU6yuxgz3REJCu7K3s5XkenvqxWucWweCOhNVRYSHhwhXAFO4Atg8ZdgIvGA7gF50TMfvJvQ0UIUvOmCxpVi2dwXDfwCgeks5ghP4Hyf0qXbnkLn3/4CE6khYPjQhb3tDu5AnouzKC3SedVxg9QDKZZYD0XEr7TTB89/LelqDYOjDy1C7/+aLGIi24zgzE7A02W6G8SikX08Er5tUvRw1Fgohkr7Th6YFisIgYqNCyreUeV2co/dhI7lTGk6GrBDqltYPht78EIbto4PVu9s=
data/Gemfile CHANGED
@@ -1,4 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in capybara-bootstrap-datepicker.gemspec
4
6
  gemspec
7
+
8
+ gem 'nokogiri', '>= 1.6.7.2'
9
+ gem 'rack', '>= 1.6.11'
@@ -0,0 +1,73 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ capybara-bootstrap-datepicker (0.2.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.7.0)
10
+ public_suffix (>= 2.0.2, < 5.0)
11
+ capybara (3.29.0)
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.5)
18
+ xpath (~> 3.2)
19
+ capybara-screenshot (1.0.24)
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.2)
27
+ mini_portile2 (2.4.0)
28
+ nokogiri (1.10.8)
29
+ mini_portile2 (~> 2.4.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 (4.0.1)
36
+ rack (2.0.8)
37
+ rack-test (1.1.0)
38
+ rack (>= 1.0, < 3)
39
+ regexp_parser (1.6.0)
40
+ rspec (3.9.0)
41
+ rspec-core (~> 3.9.0)
42
+ rspec-expectations (~> 3.9.0)
43
+ rspec-mocks (~> 3.9.0)
44
+ rspec-core (3.9.0)
45
+ rspec-support (~> 3.9.0)
46
+ rspec-expectations (3.9.0)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.9.0)
49
+ rspec-mocks (3.9.0)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.9.0)
52
+ rspec-support (3.9.0)
53
+ websocket-driver (0.7.1)
54
+ websocket-extensions (>= 0.1.0)
55
+ websocket-extensions (0.1.5)
56
+ xpath (3.2.0)
57
+ nokogiri (~> 1.8)
58
+
59
+ PLATFORMS
60
+ ruby
61
+
62
+ DEPENDENCIES
63
+ capybara (~> 3.29, >= 3.29.0)
64
+ capybara-bootstrap-datepicker!
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.9, >= 3.9.0)
71
+
72
+ BUNDLED WITH
73
+ 2.1.0
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- [![Gem Version](https://badge.fury.io/rb/capybara-bootstrap-datepicker.png)](http://badge.fury.io/rb/capybara-bootstrap-datepicker)
1
+ [![Gem Version](https://badge.fury.io/rb/capybara-bootstrap-datepicker.svg)](http://badge.fury.io/rb/capybara-bootstrap-datepicker)
2
+ [![Travis CI](https://travis-ci.org/akarzim/capybara-bootstrap-datepicker.svg?branch=master)](https://travis-ci.org/akarzim/capybara-bootstrap-datepicker.svg?branch=master)
2
3
 
3
4
  # Capybara::BootstrapDatepicker
4
5
 
@@ -10,14 +11,18 @@ All this gem does is something very simple : allow you to trigger Bootstrap date
10
11
 
11
12
  Add this line to your application's Gemfile:
12
13
 
13
- gem 'capybara-bootstrap-datepicker', group: :test
14
+ ```ruby
15
+ gem 'capybara-bootstrap-datepicker', group: :test
16
+ ```
14
17
 
15
18
  Or, add it into your test group
16
19
 
17
- group :test do
18
- gem 'capybara-bootstrap-datepicker'
19
- ...
20
- end
20
+ ```ruby
21
+ group :test do
22
+ gem 'capybara-bootstrap-datepicker'
23
+ ...
24
+ end
25
+ ```
21
26
 
22
27
  And then execute:
23
28
 
@@ -33,13 +38,17 @@ The gem automatically hook itself into rspec helper using Rspec.configure.
33
38
 
34
39
  Just use this method inside your capybara test:
35
40
 
36
- select_date(2.weeks.ago, from: "Label of the date input")
41
+ ```ruby
42
+ select_date(2.weeks.ago, from: "Label of the date input")
43
+ ```
37
44
 
38
45
  Or even:
39
46
 
40
- select_date(2.weeks.ago, from: "Date", match: :prefer_exact)
41
- select_date(Date.tomorrow, from: "Label of the date input", format: "%d/%m/%Y")
42
- select_date("2013-05-24", xpath: "//path_to//your_date_input", datepicker: :bootstrap)
47
+ ```ruby
48
+ select_date(2.weeks.ago, from: "Date", match: :prefer_exact)
49
+ select_date(Date.tomorrow, from: "Label of the date input", format: "%d/%m/%Y")
50
+ select_date("2013-05-24", xpath: "//path_to//your_date_input", datepicker: :bootstrap)
51
+ ```
43
52
 
44
53
  Available options are:
45
54
  + **from:** the label of your date input
@@ -48,6 +57,17 @@ Available options are:
48
57
  + **datepicker:** the way to fill your date input (:bootstrap = by clicking the popover using [bootstrap-datepicker](https://github.com/eternicode/bootstrap-datepicker))
49
58
  ; by default it just fill the input date.
50
59
 
60
+ ## Test
61
+
62
+ Just run rspec in your terminal:
63
+
64
+ $ rspec
65
+
66
+ ## Upgrading from 0.0.x
67
+
68
+ RSpec support has been split into a separate file. You'll need to change
69
+ `spec_helper.rb` to `require 'capybara-bootstrap-datepicker/rspec'`.
70
+
51
71
  ## Contributing
52
72
 
53
73
  1. Fork it
@@ -1,26 +1,31 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'English'
4
7
  require 'capybara-bootstrap-datepicker/version'
5
8
 
6
9
  Gem::Specification.new do |gem|
7
10
  gem.name = 'capybara-bootstrap-datepicker'
8
11
  gem.version = Capybara::BootstrapDatepicker::VERSION
9
12
  gem.authors = ['François Vantomme']
10
- gem.email = ['akarzim@gmail.com']
11
- gem.description = %q{Helper for triggering date input for bootstrap-datepicker javascript library}
13
+ gem.email = ['akarzim@pm.me']
14
+ gem.summary = 'Bootstrap datepicker helper for Capybara'
15
+ gem.description = 'Helper for triggering date input for bootstrap-datepicker javascript library'
12
16
  gem.homepage = 'https://github.com/akarzim/capybara-bootstrap-datepicker'
13
- gem.summary = gem.description
14
17
  gem.license = 'MIT'
15
18
 
16
- gem.files = `git ls-files`.split($/)
17
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
+ gem.files = `git ls-files`.split($RS)
20
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
18
21
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
22
  gem.require_paths = ['lib']
20
23
 
21
- gem.add_dependency 'rspec', '~> 3.1', '>= 3.1.0'
22
- gem.add_dependency 'capybara', '~> 2.4', '>= 2.4.4'
23
- gem.add_development_dependency 'phantomjs', '~> 1.9', '>= 1.9.7.1'
24
- gem.add_development_dependency 'poltergeist', '~> 1.5', '>= 1.5.1'
25
- gem.add_development_dependency 'pry', '~> 0.9', '>= 0.9.12.6'
24
+ gem.required_ruby_version = '>= 2.5.7'
25
+
26
+ gem.add_development_dependency 'capybara', '~> 3.29', '>= 3.29.0'
27
+ gem.add_development_dependency 'capybara-screenshot', '~> 1.0', '>= 1.0.22'
28
+ gem.add_development_dependency 'phantomjs', '~> 2.1', '>= 2.1.1.0'
29
+ gem.add_development_dependency 'poltergeist', '~> 1.18', '>= 1.18.1'
30
+ gem.add_development_dependency 'rspec', '~> 3.9', '>= 3.9.0'
26
31
  end
@@ -1,71 +1,208 @@
1
1
  require 'capybara-bootstrap-datepicker/version'
2
- require 'rspec/core'
3
2
 
4
3
  module Capybara
4
+ # Adds datepicker interaction facilities to {Capybara}
5
5
  module BootstrapDatepicker
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
6
13
  def select_date(value, datepicker: :bootstrap, format: nil, from: nil, xpath: nil, **args)
7
14
  fail "Must pass a hash containing 'from' or 'xpath'" if from.nil? && xpath.nil?
8
15
 
9
- value = Date.parse(value) unless value.respond_to? :to_date
10
-
16
+ value = value.respond_to?(:to_date) ? value.to_date : Date.parse(value)
11
17
  date_input = xpath ? find(:xpath, xpath, **args) : find_field(from, **args)
12
18
 
13
19
  case datepicker
14
20
  when :bootstrap
15
21
  select_bootstrap_date date_input, value
16
22
  else
17
- select_simple_date date_input, value
23
+ select_simple_date date_input, value, format
18
24
  end
25
+
26
+ first(:xpath, '//body').click
19
27
  end
20
28
 
21
- def select_simple_date(date_input, value)
22
- value = value.strftime format if format.present?
29
+ # Selects a date by filling the input field
30
+ # @param date_input the input field
31
+ # @param value [Date] the date to set
32
+ # @param format [String, nil] a valid date format used to format value
33
+ def select_simple_date(date_input, value, format = nil)
34
+ value = value.strftime format unless format.nil?
23
35
 
24
36
  date_input.set "#{value}\e"
25
- first(:xpath, '//body').click
26
37
  end
27
38
 
39
+ # Selects a date by simulating human interaction with the datepicker
40
+ # @param (see #select_simple_date)
28
41
  def select_bootstrap_date(date_input, value)
29
42
  date_input.click
30
- picker = find(:xpath, '//body').find('.datepicker')
31
43
 
32
- picker_years = picker.find('.datepicker-years', visible: false)
33
- picker_months = picker.find('.datepicker-months', visible: false)
34
- picker_days = picker.find('.datepicker-days', visible: false)
44
+ picker = Picker.new
35
45
 
36
- picker_current_decade = picker_years.find('th.datepicker-switch', visible: false)
37
- picker_current_year = picker_months.find('th.datepicker-switch', visible: false)
38
- picker_current_month = picker_days.find('th.datepicker-switch', visible: false)
46
+ picker.goto_decade_panel
47
+ picker.navigate_through_decades value.year
39
48
 
40
- picker_current_month.click if picker_days.visible?
41
- picker_current_year.click if picker_months.visible?
49
+ picker.find_year(value.year).click
50
+ picker.find_month(value.month).click
51
+ picker.find_day(value.day).click
52
+
53
+ fail if Date.parse(date_input.value) != value
54
+ end
42
55
 
43
- decade_start, decade_end = picker_current_decade.text.split('-').map(&:to_i)
56
+ private
44
57
 
45
- if value.year < decade_start.to_i
46
- gap = decade_start / 10 - value.year / 10
47
- gap.times { picker_years.find('th.prev').click }
48
- elsif value.year > decade_end
49
- gap = value.year / 10 - decade_end / 10
50
- gap.times { picker_years.find('th.next').click }
58
+ # The Picker class interacts with the datepicker
59
+ class Picker
60
+ # Initializes the picker
61
+ def initialize
62
+ @element = find_picker
51
63
  end
52
64
 
53
- picker_years.find('.year', text: value.year).click
54
- picker_months.find('.month', text: value.strftime('%b')).click
55
- day_xpath = <<-eos
56
- .//*[contains(concat(' ', @class, ' '), ' day ')
57
- and not(contains(concat(' ', @class, ' '), ' old '))
58
- and not(contains(concat(' ', @class, ' '), ' new '))
59
- and normalize-space(text())='#{value.day}']
60
- eos
61
- picker_days.find(:xpath, day_xpath).click
65
+ # Reveals the decade panel
66
+ def goto_decade_panel
67
+ current_month.click if days.visible?
68
+ current_year.click if months.visible?
69
+ end
62
70
 
63
- fail if Date.parse(date_input.value) != value
64
- # fail unless page.has_no_css? '.datepicker'
71
+ # Navigates through the decade panels until the correct one
72
+ # @param value [Fixnum] the year of the desired date
73
+ def navigate_through_decades(value)
74
+ decade_start, decade_end = current_decade_minmax
75
+ goto_prev_decade(value, decade_start) if value < decade_start
76
+ goto_next_decade(decade_end, value) if value > decade_end
77
+ end
78
+
79
+ # Get the year we want to click on
80
+ # @param value [Fixnum] the year of the desired date
81
+ # @return the DOM element to click on
82
+ def find_year(value)
83
+ years.find '.year', text: value
84
+ end
85
+
86
+ # Get the month we want to click on
87
+ # @param value [Fixnum] the month of the desired date
88
+ # @return the DOM element to click on
89
+ def find_month(value)
90
+ months.find ".month:nth-child(#{value})"
91
+ end
92
+
93
+ # Get the day we want to click on
94
+ # @param value [Fixnum] the day of the desired date
95
+ # @return the DOM element to click on
96
+ def find_day(value)
97
+ day_xpath = <<-eos
98
+ .//*[contains(concat(' ', @class, ' '), ' day ')
99
+ and not(contains(concat(' ', @class, ' '), ' old '))
100
+ and not(contains(concat(' ', @class, ' '), ' new '))
101
+ and normalize-space(text())='#{value}']
102
+ eos
103
+ days.find :xpath, day_xpath
104
+ end
105
+
106
+ private
107
+
108
+ # Get the datepicker
109
+ # @return the DOM element of the datepicker
110
+ def find_picker
111
+ Capybara.find(:xpath, '//body').find('.datepicker')
112
+ end
113
+
114
+ # Get the datepicker panel
115
+ # @param period [:years, :months, :days] the panel's period
116
+ # @return the DOM element of the panel
117
+ def find_period(period)
118
+ @element.find(".datepicker-#{period}", visible: false)
119
+ end
120
+
121
+ # Get the up level panel
122
+ # @param (see #find_period)
123
+ # @return the DOM element of the switch panel button
124
+ def find_switch(period)
125
+ send(period).find('th.datepicker-switch', visible: false)
126
+ end
127
+
128
+ # Get the years panel
129
+ # @param (see #find_period)
130
+ # @return (see #find_period)
131
+ def years
132
+ find_period :years
133
+ end
134
+
135
+ # Get the months panel
136
+ # @param (see #find_period)
137
+ # @return (see #find_period)
138
+ def months
139
+ find_period :months
140
+ end
141
+
142
+ # Get the days panel
143
+ # @param (see #find_period)
144
+ # @return (see #find_period)
145
+ def days
146
+ find_period :days
147
+ end
148
+
149
+ # Get the current decade panel
150
+ # @param (see #find_switch)
151
+ # @return (see #find_switch)
152
+ def current_decade
153
+ find_switch :years
154
+ end
155
+
156
+ # Get the current year panel
157
+ # @param (see #find_switch)
158
+ # @return (see #find_switch)
159
+ def current_year
160
+ find_switch :months
161
+ end
162
+
163
+ # Get the current month panel
164
+ # @param (see #find_switch)
165
+ # @return (see #find_switch)
166
+ def current_month
167
+ find_switch :days
168
+ end
169
+
170
+ # Get the current decade period
171
+ # @return [Array<Fixnum, Fixnum>] the min and max years of the decade
172
+ def current_decade_minmax
173
+ current_decade.text.split('-').map(&:to_i)
174
+ end
175
+
176
+ # Click and display previous decade
177
+ def click_prev_decade
178
+ years.find('th.prev').click
179
+ end
180
+
181
+ # Click and display next decade
182
+ def click_next_decade
183
+ years.find('th.next').click
184
+ end
185
+
186
+ # Calculates the distance in decades between min and max
187
+ # @return [Fixnum] the distance in decades between min and max
188
+ def gap(min, max)
189
+ return 0 if min >= max
190
+ (max - min) / 10
191
+ end
192
+
193
+ # Go backward to the wanted decade
194
+ # @param value [Fixnum] the year of the desired date
195
+ # @param decade_start [Fixnum] the first year of a decade
196
+ def goto_prev_decade(value, decade_start)
197
+ gap(value, decade_start).times { click_prev_decade }
198
+ end
199
+
200
+ # Go forward to the wanted decade
201
+ # @param decade_end [Fixnum] the last year of a decade
202
+ # @param value [Fixnum] the year of the desired date
203
+ def goto_next_decade(decade_end, value)
204
+ gap(decade_end, value).times { click_next_decade }
205
+ end
65
206
  end
66
207
  end
67
208
  end
68
-
69
- RSpec.configure do |c|
70
- c.include Capybara::BootstrapDatepicker
71
- end
@@ -0,0 +1,5 @@
1
+ require 'capybara-bootstrap-datepicker'
2
+
3
+ RSpec.configure do |c|
4
+ c.include Capybara::BootstrapDatepicker
5
+ end
@@ -1,5 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The gem's version
1
4
  module Capybara
2
5
  module BootstrapDatepicker
3
- VERSION = "0.0.9"
6
+ # the current version of the gem
7
+ VERSION = '0.2.1'
4
8
  end
5
9
  end
@@ -0,0 +1,51 @@
1
+ <html>
2
+ <head>
3
+ <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css">
4
+ <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker3.min.css">
5
+ </head>
6
+ <body>
7
+ <div class="container">
8
+ <h1>Bootstrap 3.4 Datepicker</h1>
9
+
10
+ <form action=".">
11
+ <div class="form-group">
12
+ <label for="my-date-input">Label of my date input</label>
13
+ <div class="input-group date default-date">
14
+ <input type="text" class="form-control" id="my-date-input">
15
+ <span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
16
+ </div>
17
+ </div>
18
+
19
+ <div class="form-group">
20
+ <label for="my-localized-date-input">Label of my localized date input</label>
21
+ <div class="input-group date locale-date">
22
+ <input type="text" class="form-control" id="my-localized-date-input">
23
+ <span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
24
+ </div>
25
+ </div>
26
+
27
+ <div class="required form-group" id="cfp_start_date_input">
28
+ <span class="form-label">
29
+ <label for="registration-period-start-datapicker" class="control-label">
30
+ Start date&nbsp;
31
+ <span class="text-warning">
32
+ <abbr title="This field is required">*</abbr>
33
+ </span>
34
+ </label>
35
+ </span>
36
+ <span class="form-wrapper">
37
+ <input id="registration-period-start-datapicker" class="form-control" type="text" name="cfp[start_date]">
38
+ </span>
39
+ </div>
40
+ </form>
41
+ </div>
42
+ <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
43
+ <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script>
44
+ <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script>
45
+ <script type="text/javascript">
46
+ $('.input-group.default-date').datepicker({ format: 'yyyy-mm-dd' });
47
+ $('.input-group.locale-date').datepicker({ format: 'yyyy-mm-dd', language: 'ja' });
48
+ $('#registration-period-start-datapicker').datepicker({ format: 'yyyy-mm-dd', minDate : '2019-03-06', maxDate : '2019-03-12' });
49
+ </script>
50
+ </body>
51
+ </html>
@@ -0,0 +1,56 @@
1
+ <html>
2
+ <head>
3
+ <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css">
4
+ <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker3.min.css">
5
+ </head>
6
+ <body>
7
+ <div class="container">
8
+ <h1>Bootstrap 4.4 Datepicker</h1>
9
+
10
+ <form action=".">
11
+ <div class="form-group">
12
+ <label for="my-date-input">Label of my date input</label>
13
+ <div class="input-group date default-date">
14
+ <input type="text" class="form-control" id="my-date-input">
15
+ <span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
16
+ </div>
17
+ </div>
18
+
19
+ <div class="form-group">
20
+ <label for="my-localized-date-input">Label of my localized date input</label>
21
+ <div class="input-group date locale-date">
22
+ <input type="text" class="form-control" id="my-localized-date-input">
23
+ <span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
24
+ </div>
25
+ </div>
26
+
27
+ <div class="required form-group" id="cfp_start_date_input">
28
+ <span class="form-label">
29
+ <label for="registration-period-start-datapicker" class="control-label">
30
+ Start date&nbsp;
31
+ <span class="text-warning">
32
+ <abbr title="This field is required">*</abbr>
33
+ </span>
34
+ </label>
35
+ </span>
36
+ <span class="form-wrapper">
37
+ <input id="registration-period-start-datapicker" class="form-control" type="text" name="cfp[start_date]">
38
+ </span>
39
+ </div>
40
+ </form>
41
+ </div>
42
+ <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
43
+ <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/js/bootstrap.min.js"></script>
44
+ <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script>
45
+ <script type="text/javascript">
46
+ $('.input-group.default-date').datepicker({ format: 'yyyy-mm-dd' });
47
+ $('.input-group.locale-date').datepicker({ format: 'yyyy-mm-dd', language: 'ja' });
48
+
49
+ $('#registration-period-start-datapicker').datepicker({
50
+ format: 'yyyy-mm-dd',
51
+ minDate : '2019-03-06',
52
+ maxDate : '2019-03-12'
53
+ });
54
+ </script>
55
+ </body>
56
+ </html>
@@ -1,11 +1,71 @@
1
- # encoding: utf-8
2
- feature 'Bootstrap Datepicker' do
3
- scenario 'fill in datepicker based on Bootstrap 3.3', js: true do
4
- Capybara.current_session.driver.visit "#{Capybara.app_host}/bootstrap.html"
5
- expect(page).to have_content 'Bootstrap3 Datepicker'
1
+ # frozen_string_literal: true
6
2
 
7
- select_date Date.today, from: 'Label of my date input', datepicker: :bootstrap
8
- expect(Date.parse find_field('Label of my date input').value).to eq Date.today
3
+ RSpec.shared_examples 'a datepicker' do
4
+ context 'default date' do
5
+ subject { Date.parse(find_field('Label of my date input').value) }
6
+
7
+ it 'fills in an input without using the datepicker', js: true do
8
+ select_date Date.today, from: 'Label of my date input'
9
+ expect(subject).to eq Date.today
10
+ end
11
+
12
+ it 'fills in a standard datepicker', js: true do
13
+ select_date Date.today, from: 'Label of my date input', datepicker: :simple
14
+ expect(subject).to eq Date.today
15
+ end
16
+
17
+ it 'fills in a datepicker based on Bootstrap', js: true do
18
+ select_date Date.today, from: 'Label of my date input', datepicker: :bootstrap
19
+ expect(subject).to eq Date.today
20
+ end
21
+
22
+ it 'fills in an input with DateTime object', js: true do
23
+ select_date DateTime.now, from: 'Label of my date input'
24
+ expect(subject).to eq Date.today
25
+ end
26
+ end
27
+
28
+ context 'locale date' do
29
+ subject { Date.parse(find_field('Label of my localized date input').value) }
30
+
31
+ it 'fills in a localized datepicker based on Bootstrap', js: true do
32
+ select_date Date.today, from: 'Label of my localized date input', datepicker: :bootstrap
33
+ expect(subject).to eq Date.today
34
+ end
35
+ end
36
+
37
+ context 'required date' do
38
+ subject { Date.parse(find_field('Start date').value) }
39
+
40
+ it 'fills in a required datepicker based on Bootstrap', js: true do
41
+ select_date Date.today, from: 'Start date', datepicker: :bootstrap
42
+ expect(subject).to eq Date.today
43
+ end
9
44
  end
10
45
  end
11
46
 
47
+ RSpec.describe 'Bootstrap Datepicker', type: :feature do
48
+ describe 'Boostrap 3.4' do
49
+ before :each do
50
+ Capybara.current_session.driver.visit "#{Capybara.app_host}/bootstrap-3.4.html"
51
+ end
52
+
53
+ it 'loads the page correctly', js: true do
54
+ expect(page).to have_content 'Bootstrap 3.4 Datepicker'
55
+ end
56
+
57
+ it_behaves_like 'a datepicker'
58
+ end
59
+
60
+ describe 'Boostrap 4.4' do
61
+ before :each do
62
+ Capybara.current_session.driver.visit "#{Capybara.app_host}/bootstrap-4.4.html"
63
+ end
64
+
65
+ it 'loads the page correctly', js: true do
66
+ expect(page).to have_content 'Bootstrap 4.4 Datepicker'
67
+ end
68
+
69
+ it_behaves_like 'a datepicker'
70
+ end
71
+ end
@@ -1,36 +1,17 @@
1
- # This file was generated by the `rspec --init` command. Conventionally, all
2
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
- # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
- # file to always be loaded, without a need to explicitly require it in any files.
5
- #
6
- # Given that it is always loaded, you are encouraged to keep this file as
7
- # light-weight as possible. Requiring heavyweight dependencies from this file
8
- # will add to the boot time of your test suite on EVERY test run, even for an
9
- # individual file that may not need all of that loaded. Instead, consider making
10
- # a separate helper file that requires the additional dependencies and performs
11
- # the additional setup, and require it from the spec files that actually need it.
12
- #
13
- # The `.rspec` file also contains a few flags that are not defaults but that
14
- # users commonly want.
15
- #
16
1
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
-
18
2
  require 'bundler/setup'
19
3
  Bundler.setup
20
4
 
21
- require 'capybara-bootstrap-datepicker'
5
+ require 'capybara-bootstrap-datepicker/rspec'
22
6
  require 'capybara'
23
7
  require 'capybara/rspec'
8
+ require 'capybara-screenshot/rspec'
24
9
  require 'capybara/poltergeist'
25
10
  require 'phantomjs/poltergeist'
26
- require 'pry'
27
11
 
28
12
  Capybara.configure do |config|
29
13
  config.javascript_driver = :poltergeist
30
- config.app_host = 'file:///home/francois/git/capybara-bootstrap-datepicker/spec/features/'
31
- # config.app_host = 'http://localhost:3007'
32
- # config.server_host = 'localhost'
33
- # config.server_port = '3007'
14
+ config.app_host = "file://#{File.expand_path('features', __dir__)}"
34
15
  end
35
16
 
36
17
  Capybara.register_driver :poltergeist do |app|
@@ -38,32 +19,14 @@ Capybara.register_driver :poltergeist do |app|
38
19
  end
39
20
 
40
21
  RSpec.configure do |config|
41
- # rspec-expectations config goes here. You can use an alternate
42
- # assertion/expectation library such as wrong or the stdlib/minitest
43
- # assertions if you prefer.
44
22
  config.expect_with :rspec do |expectations|
45
- # This option will default to `true` in RSpec 4. It makes the `description`
46
- # and `failure_message` of custom matchers include text for helper methods
47
- # defined using `chain`, e.g.:
48
- # be_bigger_than(2).and_smaller_than(4).description
49
- # # => "be bigger than 2 and smaller than 4"
50
- # ...rather than:
51
- # # => "be bigger than 2"
52
23
  expectations.include_chain_clauses_in_custom_matcher_descriptions = true
53
24
  end
54
25
 
55
- # rspec-mocks config goes here. You can use an alternate test double
56
- # library (such as bogus or mocha) by changing the `mock_with` option here.
57
26
  config.mock_with :rspec do |mocks|
58
- # Prevents you from mocking or stubbing a method that does not exist on
59
- # a real object. This is generally recommended, and will default to
60
- # `true` in RSpec 4.
61
27
  mocks.verify_partial_doubles = true
62
28
  end
63
29
 
64
- # The settings below are suggested to provide a good initial experience
65
- # with RSpec, but feel free to customize to your heart's content.
66
- =begin
67
30
  # These two settings work together to allow you to limit a spec run
68
31
  # to individual examples or groups you care about by tagging them with
69
32
  # `:focus` metadata. When nothing is tagged with `:focus`, all examples
@@ -71,8 +34,8 @@ RSpec.configure do |config|
71
34
  config.filter_run :focus
72
35
  config.run_all_when_everything_filtered = true
73
36
 
74
- # Limits the available syntax to the non-monkey patched syntax that is recommended.
75
- # For more details, see:
37
+ # Limits the available syntax to the non-monkey patched syntax that is
38
+ # recommended. For more details, see:
76
39
  # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
77
40
  # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
78
41
  # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
@@ -80,7 +43,7 @@ RSpec.configure do |config|
80
43
 
81
44
  # This setting enables warnings. It's recommended, but in some cases may
82
45
  # be too noisy due to issues in dependencies.
83
- config.warnings = true
46
+ # config.warnings = true
84
47
 
85
48
  # Many RSpec users commonly either run the entire suite or an individual
86
49
  # file, and it's useful to allow more verbose output when running an
@@ -108,5 +71,4 @@ RSpec.configure do |config|
108
71
  # test failures related to randomization by passing the same `--seed` value
109
72
  # as the one that triggered the failure.
110
73
  Kernel.srand config.seed
111
- =end
112
74
  end
metadata CHANGED
@@ -1,140 +1,146 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-bootstrap-datepicker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - François Vantomme
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-07 00:00:00.000000000 Z
11
+ date: 2020-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rspec
14
+ name: capybara
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.1'
19
+ version: '3.29'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 3.1.0
23
- type: :runtime
22
+ version: 3.29.0
23
+ type: :development
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: '3.1'
29
+ version: '3.29'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 3.1.0
32
+ version: 3.29.0
33
33
  - !ruby/object:Gem::Dependency
34
- name: capybara
34
+ name: capybara-screenshot
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '2.4'
39
+ version: '1.0'
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: 2.4.4
43
- type: :runtime
42
+ version: 1.0.22
43
+ type: :development
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: '2.4'
49
+ version: '1.0'
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
- version: 2.4.4
52
+ version: 1.0.22
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: phantomjs
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
57
  - - "~>"
58
58
  - !ruby/object:Gem::Version
59
- version: '1.9'
59
+ version: '2.1'
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
- version: 1.9.7.1
62
+ version: 2.1.1.0
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '1.9'
69
+ version: '2.1'
70
70
  - - ">="
71
71
  - !ruby/object:Gem::Version
72
- version: 1.9.7.1
72
+ version: 2.1.1.0
73
73
  - !ruby/object:Gem::Dependency
74
74
  name: poltergeist
75
75
  requirement: !ruby/object:Gem::Requirement
76
76
  requirements:
77
77
  - - "~>"
78
78
  - !ruby/object:Gem::Version
79
- version: '1.5'
79
+ version: '1.18'
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 1.5.1
82
+ version: 1.18.1
83
83
  type: :development
84
84
  prerelease: false
85
85
  version_requirements: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '1.5'
89
+ version: '1.18'
90
90
  - - ">="
91
91
  - !ruby/object:Gem::Version
92
- version: 1.5.1
92
+ version: 1.18.1
93
93
  - !ruby/object:Gem::Dependency
94
- name: pry
94
+ name: rspec
95
95
  requirement: !ruby/object:Gem::Requirement
96
96
  requirements:
97
97
  - - "~>"
98
98
  - !ruby/object:Gem::Version
99
- version: '0.9'
99
+ version: '3.9'
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
- version: 0.9.12.6
102
+ version: 3.9.0
103
103
  type: :development
104
104
  prerelease: false
105
105
  version_requirements: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - "~>"
108
108
  - !ruby/object:Gem::Version
109
- version: '0.9'
109
+ version: '3.9'
110
110
  - - ">="
111
111
  - !ruby/object:Gem::Version
112
- version: 0.9.12.6
112
+ version: 3.9.0
113
113
  description: Helper for triggering date input for bootstrap-datepicker javascript
114
114
  library
115
115
  email:
116
- - akarzim@gmail.com
116
+ - akarzim@pm.me
117
117
  executables: []
118
118
  extensions: []
119
119
  extra_rdoc_files: []
120
120
  files:
121
121
  - ".gitignore"
122
+ - ".rspec"
123
+ - ".ruby-version"
124
+ - ".travis.yml"
122
125
  - Gemfile
126
+ - Gemfile.lock
123
127
  - LICENSE.txt
124
128
  - README.md
125
129
  - Rakefile
126
130
  - capybara-bootstrap-datepicker.gemspec
127
131
  - lib/capybara-bootstrap-datepicker.rb
132
+ - lib/capybara-bootstrap-datepicker/rspec.rb
128
133
  - lib/capybara-bootstrap-datepicker/version.rb
129
134
  - lib/capybara/bootstrap-datepicker.rb
130
- - spec/features/bootstrap.html
135
+ - spec/features/bootstrap-3.4.html
136
+ - spec/features/bootstrap-4.4.html
131
137
  - spec/features/bootstrap_datepicker_spec.rb
132
138
  - spec/spec_helper.rb
133
139
  homepage: https://github.com/akarzim/capybara-bootstrap-datepicker
134
140
  licenses:
135
141
  - MIT
136
142
  metadata: {}
137
- post_install_message:
143
+ post_install_message:
138
144
  rdoc_options: []
139
145
  require_paths:
140
146
  - lib
@@ -142,19 +148,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
148
  requirements:
143
149
  - - ">="
144
150
  - !ruby/object:Gem::Version
145
- version: '0'
151
+ version: 2.5.7
146
152
  required_rubygems_version: !ruby/object:Gem::Requirement
147
153
  requirements:
148
154
  - - ">="
149
155
  - !ruby/object:Gem::Version
150
156
  version: '0'
151
157
  requirements: []
152
- rubyforge_project:
153
- rubygems_version: 2.4.5
154
- signing_key:
158
+ rubyforge_project:
159
+ rubygems_version: 2.7.6.2
160
+ signing_key:
155
161
  specification_version: 4
156
- summary: Helper for triggering date input for bootstrap-datepicker javascript library
162
+ summary: Bootstrap datepicker helper for Capybara
157
163
  test_files:
158
- - spec/features/bootstrap.html
164
+ - spec/features/bootstrap-3.4.html
165
+ - spec/features/bootstrap-4.4.html
159
166
  - spec/features/bootstrap_datepicker_spec.rb
160
167
  - spec/spec_helper.rb
@@ -1,25 +0,0 @@
1
- <html>
2
- <head>
3
- <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css">
4
- <link rel="stylesheet" href="http://eternicode.github.io/bootstrap-datepicker/bootstrap-datepicker/css/datepicker3.css">
5
- </head>
6
- <body>
7
- <div class="container">
8
- <h1>Bootstrap3 Datepicker</h1>
9
-
10
- <form>
11
- <div class="form-group">
12
- <label for="my-date-input">Label of my date input</label>
13
- <div class="input-group date">
14
- <input type="text" class="form-control" id="my-date-input">
15
- <span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
16
- </div>
17
- </div>
18
- </form>
19
- </div>
20
- <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
21
- <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
22
- <script src="http://eternicode.github.io/bootstrap-datepicker/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
23
- <script type="text/javascript">$('.input-group.date').datepicker({});</script>
24
- </body>
25
- </html>