spree_core 4.2.0.rc5 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/spree.js +16 -0
  3. data/app/finders/spree/products/find.rb +3 -3
  4. data/app/helpers/spree/base_helper.rb +2 -1
  5. data/app/helpers/spree/currency_helper.rb +24 -0
  6. data/app/helpers/spree/locale_helper.rb +15 -3
  7. data/app/models/concerns/spree/product_scopes.rb +1 -1
  8. data/app/models/spree/app_configuration.rb +1 -1
  9. data/app/models/spree/app_dependencies.rb +3 -1
  10. data/app/models/spree/credit_card.rb +4 -0
  11. data/app/models/spree/price.rb +1 -1
  12. data/app/models/spree/product.rb +17 -0
  13. data/app/models/spree/store.rb +19 -2
  14. data/app/models/spree/variant.rb +1 -1
  15. data/app/paginators/spree/shared/paginate.rb +8 -1
  16. data/app/services/spree/build_localized_redirect_url.rb +101 -0
  17. data/app/views/spree/shared/_base_mailer_stylesheets.html.erb +13 -0
  18. data/app/views/spree/shared/_purchased_items_table.html.erb +15 -6
  19. data/app/views/spree/shared/purchased_items_table/_adjustment.html.erb +2 -2
  20. data/app/views/spree/shared/purchased_items_table/_line_item.html.erb +1 -1
  21. data/config/locales/en.yml +7 -6
  22. data/db/migrate/20191017121054_add_supported_currencies_to_store.rb +1 -0
  23. data/db/migrate/20201012091259_add_filterable_column_to_spree_option_types.rb +6 -2
  24. data/db/migrate/20210205211040_add_supported_locales_to_spree_stores.rb +11 -0
  25. data/db/migrate/20210215202602_migrate_spree_i18n_globalize_config.rb +22 -0
  26. data/lib/generators/spree/install/install_generator.rb +9 -6
  27. data/lib/spree/core/controller_helpers/currency.rb +8 -6
  28. data/lib/spree/core/controller_helpers/locale.rb +13 -12
  29. data/lib/spree/core/controller_helpers/search.rb +1 -1
  30. data/lib/spree/core/version.rb +1 -1
  31. data/lib/spree/i18n.rb +12 -0
  32. data/lib/spree/permitted_attributes.rb +1 -1
  33. data/lib/spree/service_module.rb +2 -2
  34. data/lib/spree/testing_support/common_rake.rb +1 -1
  35. data/lib/spree/testing_support/controller_requests.rb +10 -10
  36. data/lib/spree/testing_support/factories/store_factory.rb +1 -0
  37. data/lib/spree/testing_support/flatpickr_capybara.rb +101 -0
  38. data/lib/spree/testing_support/locale_helpers.rb +71 -0
  39. data/lib/spree/testing_support/next_instance_of.rb +38 -0
  40. metadata +11 -6
  41. data/lib/generators/spree/install/templates/config/initializers/spree_storefront.rb +0 -1
  42. data/lib/generators/spree/install/templates/config/spree_storefront.yml +0 -67
@@ -5,9 +5,9 @@
5
5
  <%= raw(adjustment.label) %>:
6
6
  </p>
7
7
  </td>
8
- <td>
8
+ <td class="purchase_total-col">
9
9
  <p class="f-fallback purchase_total">
10
10
  <%= Spree::Money.new(adjustment.amount, currency: order.currency) %>
11
11
  </p>
12
12
  </td>
13
- </tr>
13
+ </tr>
@@ -18,7 +18,7 @@
18
18
  </strong>
19
19
  <p class="purchase_item--additional"><%= raw(line_item.variant.options_text) -%></p>
20
20
  </td>
21
- <td class="align-right">
21
+ <td class="align-right" width="30%">
22
22
  <span class="f-fallback purchase_item_price">
23
23
  <%= line_item.quantity %> x <%= line_item.single_money %><br>
24
24
  <%= line_item.display_amount %>
@@ -755,14 +755,14 @@ en:
755
755
  new_order_notifications_email: New Order Notifications Email
756
756
  cut: Cut
757
757
  cvv: CVV
758
+ no_cc_type: N/A
758
759
  cvv_response: CVV Response
759
760
  date: Date
760
761
  date_completed: Date Completed
761
762
  date_picker:
762
- first_day: 0
763
- format: ! '%Y/%m/%d'
764
- js_format: Y/m/d
765
- js_date_time: Y/m/d - H:i
763
+ # FlatPickr human friendly formatting
764
+ fpr_human_friendly_date_format: M j, Y
765
+ fpr_human_friendly_date_time_format: M j, Y at H:i
766
766
  date_range: Date Range
767
767
  default: Default
768
768
  default_country_cannot_be_deleted: Default country cannot be deleted
@@ -1613,9 +1613,9 @@ en:
1613
1613
  unable_to_delete: Unable to delete store.
1614
1614
  store_form:
1615
1615
  code_help: "Store unique identifier, which is an abbreviated version of the store’s name (used as the layout directory name, and also helpful for separating templates by store)"
1616
- checkout_zone_help: "Selecting a Zone will limit customers on Checkout to Addresses in Countries or States in that Zone.
1616
+ checkout_zone_help: "Selecting zone will limit to which Countries or States products are shipped.
1617
1617
  For more information <a href='https://guides.spreecommerce.org/user/configuration/configuring_geography.html#zones' target='_blank' class='alert-link'>please see documentation</a>"
1618
- languages_help: "Install <a href='https://github.com/spree-contrib/spree_i18n target='_blank' class='alert-link'>Spree I18n extension</a> to add more languages"
1618
+ locales_help: "Install <a href='https://github.com/spree-contrib/spree_i18n target='_blank' class='alert-link'>Spree I18n extension</a> to add more locales"
1619
1619
  social_help: "If you want to link to your social accounts in the footer part of your website please fill below fields"
1620
1620
  default_country_help: "This is the Country that will be pre-selected on the Checkout Address form"
1621
1621
  footer_help: "This content is visible in the footer section of your Store"
@@ -1672,6 +1672,7 @@ en:
1672
1672
  summary: Summary
1673
1673
  supported_currencies: Supported Currencies
1674
1674
  supported_currencies_long: A comma separated list of supported currencies
1675
+ supported_locales: Supported Locales
1675
1676
  tax: Tax
1676
1677
  tax_included: "Tax (incl.)"
1677
1678
  tax_categories: Tax Categories
@@ -2,6 +2,7 @@ class AddSupportedCurrenciesToStore < ActiveRecord::Migration[6.0]
2
2
  def change
3
3
  unless column_exists?(:spree_stores, :supported_currencies)
4
4
  add_column :spree_stores, :supported_currencies, :string
5
+ Spree::Store.reset_column_information
5
6
  Spree::Store.all.each do |store|
6
7
  store.update_attribute(:supported_currencies, store.default_currency)
7
8
  end
@@ -1,6 +1,10 @@
1
1
  class AddFilterableColumnToSpreeOptionTypes < ActiveRecord::Migration[6.0]
2
2
  def change
3
- add_column :spree_option_types, :filterable, :boolean, default: true, null: false
4
- add_index :spree_option_types, :filterable
3
+ unless column_exists?(:spree_option_types, :filterable)
4
+ add_column :spree_option_types, :filterable, :boolean, default: true, null: false
5
+ end
6
+ unless index_exists?(:spree_option_types, :filterable)
7
+ add_index :spree_option_types, :filterable
8
+ end
5
9
  end
6
10
  end
@@ -0,0 +1,11 @@
1
+ class AddSupportedLocalesToSpreeStores < ActiveRecord::Migration[6.0]
2
+ def change
3
+ unless column_exists?(:spree_stores, :supported_locales)
4
+ add_column :spree_stores, :supported_locales, :string
5
+ Spree::Store.reset_column_information
6
+ Spree::Store.all.each do |store|
7
+ store.update_attribute(:supported_locales, store.default_locale)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ class MigrateSpreeI18nGlobalizeConfig < ActiveRecord::Migration[6.0]
2
+ def up
3
+ locales = []
4
+
5
+ if defined?(SpreeI18n) && defined?(SpreeI18n::Config)
6
+ locales = (locales << SpreeI18n::Config[:available_locales]).flatten.uniq.compact
7
+ end
8
+
9
+ if defined?(SpreeGlobalize) && defined?(SpreeGlobalize::Config)
10
+ locales = (locales << SpreeGlobalize::Config[:supported_locales]).flatten.uniq.compact
11
+ end
12
+
13
+ default_store = Spree::Store.default
14
+ if default_store.supported_locales.blank? || default_store.supported_locales == default_store.default_locale
15
+ locales = (locales << default_store.default_locale).uniq.compact.join(',')
16
+ default_store.update(supported_locales: locales)
17
+ end
18
+ end
19
+
20
+ def down
21
+ end
22
+ end
@@ -10,7 +10,8 @@ module Spree
10
10
  class_option :migrate, type: :boolean, default: true, banner: 'Run Spree migrations'
11
11
  class_option :seed, type: :boolean, default: true, banner: 'load seed data (migrations must be run)'
12
12
  class_option :sample, type: :boolean, default: true, banner: 'load sample data (migrations must be run)'
13
- class_option :copy_storefront, type: :boolean, default: true, banner: 'copy storefront from spree frontend to your application for easy customization'
13
+ class_option :install_storefront, type: :boolean, default: true, banner: 'installs storefront configuration files'
14
+ class_option :copy_storefront, type: :boolean, default: false, banner: 'copy all storefront views and stylesheets'
14
15
  class_option :auto_accept, type: :boolean
15
16
  class_option :user_class, type: :string
16
17
  class_option :admin_email, type: :string
@@ -30,6 +31,7 @@ module Spree
30
31
  @run_migrations = options[:migrate]
31
32
  @load_seed_data = options[:seed]
32
33
  @load_sample_data = options[:sample]
34
+ @install_storefront = options[:install_storefront]
33
35
  @copy_storefront = options[:copy_storefront]
34
36
 
35
37
  unless @run_migrations
@@ -40,11 +42,6 @@ module Spree
40
42
 
41
43
  def add_files
42
44
  template 'config/initializers/spree.rb', 'config/initializers/spree.rb'
43
-
44
- if Spree::Core::Engine.frontend_available? || Rails.env.test?
45
- template 'config/initializers/spree_storefront.rb', 'config/initializers/spree_storefront.rb'
46
- template 'config/spree_storefront.yml', 'config/spree_storefront.yml'
47
- end
48
45
  end
49
46
 
50
47
  def additional_tweaks
@@ -91,6 +88,12 @@ module Spree
91
88
  empty_directory 'app/overrides'
92
89
  end
93
90
 
91
+ def install_storefront
92
+ if @install_storefront && Spree::Core::Engine.frontend_available?
93
+ generate 'spree:frontend:install'
94
+ end
95
+ end
96
+
94
97
  def copy_storefront
95
98
  if @copy_storefront && Spree::Core::Engine.frontend_available?
96
99
  generate 'spree:frontend:copy_storefront'
@@ -12,19 +12,19 @@ module Spree
12
12
  end
13
13
 
14
14
  def current_currency
15
- # session support was previously in SpreeMultiCurrency so we would like
16
- # to keep it for now
17
15
  @current_currency ||= if defined?(session) && session.key?(:currency) && supported_currency?(session[:currency])
18
16
  session[:currency]
19
17
  elsif params[:currency].present? && supported_currency?(params[:currency])
20
18
  params[:currency]
21
- else
19
+ elsif current_store.present?
22
20
  current_store.default_currency
23
- end
21
+ else
22
+ Spree::Config[:currency]
23
+ end&.upcase
24
24
  end
25
25
 
26
26
  def supported_currencies
27
- @supported_currencies ||= current_store.supported_currencies_list
27
+ @supported_currencies ||= current_store&.supported_currencies_list
28
28
  end
29
29
 
30
30
  def supported_currencies_for_all_stores
@@ -37,7 +37,9 @@ module Spree
37
37
  end
38
38
 
39
39
  def supported_currency?(currency_iso_code)
40
- supported_currencies.map(&:iso_code).include?(currency_iso_code)
40
+ return false if supported_currencies.nil?
41
+
42
+ supported_currencies.map(&:iso_code).include?(currency_iso_code.upcase)
41
43
  end
42
44
  end
43
45
  end
@@ -12,6 +12,7 @@ module Spree
12
12
  helper_method :current_locale
13
13
  helper_method :supported_locale?
14
14
  helper_method :available_locales
15
+ helper_method :locale_param
15
16
  end
16
17
 
17
18
  def set_locale
@@ -19,38 +20,38 @@ module Spree
19
20
  end
20
21
 
21
22
  def current_locale
22
- # session support was previously in SpreeI18n so we would like to keep it for now
23
- # for easer upgrade
24
- @current_locale ||= if defined?(session) && session.key?(:locale) && supported_locale?(session[:locale])
25
- session[:locale]
26
- elsif params[:locale].present? && supported_locale?(params[:locale])
23
+ @current_locale ||= if params[:locale].present? && supported_locale?(params[:locale])
27
24
  params[:locale]
28
25
  elsif respond_to?(:config_locale, true) && config_locale.present?
29
26
  config_locale
30
27
  else
31
- current_store.default_locale || Rails.application.config.i18n.default_locale || I18n.default_locale
28
+ current_store&.default_locale || Rails.application.config.i18n.default_locale || I18n.default_locale
32
29
  end
33
30
  end
34
31
 
35
32
  def supported_locales
36
- @supported_locales ||= current_store.supported_locales_list
33
+ @supported_locales ||= current_store&.supported_locales_list
37
34
  end
38
35
 
39
36
  def supported_locale?(locale_code)
37
+ return false if supported_locales.nil?
38
+
40
39
  supported_locales.include?(locale_code&.to_s)
41
40
  end
42
41
 
43
42
  def supported_locales_for_all_stores
44
- @supported_locales_for_all_stores ||= (if defined?(SpreeI18n)
45
- (SpreeI18n::Locale.all << :en).map(&:to_s)
46
- else
47
- [Rails.application.config.i18n.default_locale, I18n.locale, :en]
48
- end).uniq.compact
43
+ @supported_locales_for_all_stores ||= Spree.available_locales
49
44
  end
50
45
 
51
46
  def available_locales
52
47
  Spree::Store.available_locales
53
48
  end
49
+
50
+ def locale_param
51
+ return if I18n.locale.to_s == current_store.default_locale || current_store.default_locale.nil?
52
+
53
+ I18n.locale.to_s
54
+ end
54
55
  end
55
56
  end
56
57
  end
@@ -5,7 +5,7 @@ module Spree
5
5
  def build_searcher(params)
6
6
  Spree::Config.searcher_class.new(params).tap do |searcher|
7
7
  searcher.current_user = try_spree_current_user
8
- searcher.current_currency = current_currency
8
+ searcher.current_currency = current_currency&.upcase
9
9
  end
10
10
  end
11
11
  end
@@ -1,5 +1,5 @@
1
1
  module Spree
2
2
  def self.version
3
- '4.2.0.rc5'
3
+ '4.2.0'
4
4
  end
5
5
  end
data/lib/spree/i18n.rb CHANGED
@@ -16,6 +16,18 @@ module Spree
16
16
  TranslationHelperWrapper.new.translate(key, **options)
17
17
  end
18
18
 
19
+ def available_locales
20
+ locales_from_i18n = I18n.available_locales
21
+ locales =
22
+ if defined?(SpreeI18n)
23
+ (SpreeI18n::Locale.all << :en).map(&:to_s)
24
+ else
25
+ [Rails.application.config.i18n.default_locale, I18n.locale, :en]
26
+ end
27
+
28
+ (locales + locales_from_i18n).uniq.compact
29
+ end
30
+
19
31
  alias t translate
20
32
  end
21
33
  end
@@ -99,7 +99,7 @@ module Spree
99
99
  @@store_attributes = [:name, :url, :seo_title, :code, :meta_keywords, :logo,
100
100
  :meta_description, :default_currency, :mail_from_address,
101
101
  :customer_support_email, :facebook, :twitter, :instagram,
102
- :description, :address, :contact_phone,
102
+ :description, :address, :contact_phone, :supported_locales,
103
103
  :default_locale, :default_country_id, :supported_currencies,
104
104
  :new_order_notifications_email, :mailer_logo, :checkout_zone_id, :seo_robots]
105
105
 
@@ -1,8 +1,8 @@
1
1
  module Spree
2
2
  module ServiceModule
3
3
  module Callable
4
- def call(*args)
5
- new.call(*args).tap do |result|
4
+ def call(*args, **kwargs)
5
+ new.call(*args, **kwargs).tap do |result|
6
6
  return yield(result) if block_given?
7
7
  end
8
8
  end
@@ -15,7 +15,7 @@ namespace :common do
15
15
  Rails.env = 'test'
16
16
 
17
17
  Spree::DummyGenerator.start ["--lib_name=#{ENV['LIB_NAME']}", '--quiet']
18
- Spree::InstallGenerator.start ["--lib_name=#{ENV['LIB_NAME']}", '--auto-accept', '--migrate=false', '--seed=false', '--sample=false', '--quiet', '--copy_storefront=false', "--user_class=#{args[:user_class]}"]
18
+ Spree::InstallGenerator.start ["--lib_name=#{ENV['LIB_NAME']}", '--auto-accept', '--migrate=false', '--seed=false', '--sample=false', '--quiet', '--copy_storefront=false', '--install_storefront=false', "--user_class=#{args[:user_class]}"]
19
19
 
20
20
  puts 'Setting up dummy database...'
21
21
  system("bundle exec rake db:drop db:create > #{File::NULL}")
@@ -9,7 +9,7 @@ module Spree
9
9
 
10
10
  def spree_get(action, parameters = nil, session = nil, flash = nil)
11
11
  ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
12
- ControllerRequests#spree_get is deprecated and will be removed in Spree 4.1.
12
+ ControllerRequests#spree_get is deprecated and will be removed in Spree 5.0.
13
13
  Please use get, params: {}
14
14
  DEPRECATION
15
15
  process_spree_action(action, parameters, session, flash, 'GET')
@@ -18,7 +18,7 @@ module Spree
18
18
  # Executes a request simulating POST HTTP method and set/volley the response
19
19
  def spree_post(action, parameters = nil, session = nil, flash = nil)
20
20
  ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
21
- ControllerRequests#spree_post is deprecated and will be removed in Spree 4.1.
21
+ ControllerRequests#spree_post is deprecated and will be removed in Spree 5.0.
22
22
  Please use post, params: {}
23
23
  DEPRECATION
24
24
  process_spree_action(action, parameters, session, flash, 'POST')
@@ -27,7 +27,7 @@ module Spree
27
27
  # Executes a request simulating PUT HTTP method and set/volley the response
28
28
  def spree_put(action, parameters = nil, session = nil, flash = nil)
29
29
  ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
30
- ControllerRequests#spree_put is deprecated and will be removed in Spree 4.1.
30
+ ControllerRequests#spree_put is deprecated and will be removed in Spree 5.0.
31
31
  Please use put, params: {}
32
32
  DEPRECATION
33
33
  process_spree_action(action, parameters, session, flash, 'PUT')
@@ -36,7 +36,7 @@ module Spree
36
36
  # # Executes a request simulating PATCH HTTP method and set/volley the response
37
37
  def spree_patch(action, parameters = nil, session = nil, flash = nil)
38
38
  ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
39
- ControllerRequests#spree_patch is deprecated and will be removed in Spree 4.1.
39
+ ControllerRequests#spree_patch is deprecated and will be removed in Spree 5.0.
40
40
  Please use patch, params: {}
41
41
  DEPRECATION
42
42
  process_spree_action(action, parameters, session, flash, 'PATCH')
@@ -45,7 +45,7 @@ module Spree
45
45
  # Executes a request simulating DELETE HTTP method and set/volley the response
46
46
  def spree_delete(action, parameters = nil, session = nil, flash = nil)
47
47
  ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
48
- ControllerRequests#spree_delete is deprecated and will be removed in Spree 4.1.
48
+ ControllerRequests#spree_delete is deprecated and will be removed in Spree 5.0.
49
49
  Please use delete, params: {}
50
50
  DEPRECATION
51
51
  process_spree_action(action, parameters, session, flash, 'DELETE')
@@ -53,35 +53,35 @@ module Spree
53
53
 
54
54
  def spree_xhr_get(action, parameters = nil, session = nil, flash = nil)
55
55
  ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
56
- ControllerRequests#spree_xhr_get is deprecated and will be removed in Spree 4.1.
56
+ ControllerRequests#spree_xhr_get is deprecated and will be removed in Spree 5.0.
57
57
  DEPRECATION
58
58
  process_spree_xhr_action(action, parameters, session, flash, :get)
59
59
  end
60
60
 
61
61
  def spree_xhr_post(action, parameters = nil, session = nil, flash = nil)
62
62
  ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
63
- ControllerRequests#spree_xhr_post is deprecated and will be removed in Spree 4.1.
63
+ ControllerRequests#spree_xhr_post is deprecated and will be removed in Spree 5.0.
64
64
  DEPRECATION
65
65
  process_spree_xhr_action(action, parameters, session, flash, :post)
66
66
  end
67
67
 
68
68
  def spree_xhr_put(action, parameters = nil, session = nil, flash = nil)
69
69
  ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
70
- ControllerRequests#spree_xhr_put is deprecated and will be removed in Spree 4.1.
70
+ ControllerRequests#spree_xhr_put is deprecated and will be removed in Spree 5.0.
71
71
  DEPRECATION
72
72
  process_spree_xhr_action(action, parameters, session, flash, :put)
73
73
  end
74
74
 
75
75
  def spree_xhr_patch(action, parameters = nil, session = nil, flash = nil)
76
76
  ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
77
- ControllerRequests#spree_xhr_patch is deprecated and will be removed in Spree 4.1.
77
+ ControllerRequests#spree_xhr_patch is deprecated and will be removed in Spree 5.0.
78
78
  DEPRECATION
79
79
  process_spree_xhr_action(action, parameters, session, flash, :patch)
80
80
  end
81
81
 
82
82
  def spree_xhr_delete(action, parameters = nil, session = nil, flash = nil)
83
83
  ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
84
- ControllerRequests#spree_xhr_delete is deprecated and will be removed in Spree 4.1.
84
+ ControllerRequests#spree_xhr_delete is deprecated and will be removed in Spree 5.0.
85
85
  DEPRECATION
86
86
  process_spree_xhr_action(action, parameters, session, flash, :delete)
87
87
  end
@@ -8,6 +8,7 @@ FactoryBot.define do
8
8
  new_order_notifications_email { 'store-owner@example.com' }
9
9
  default_currency { 'USD' }
10
10
  supported_currencies { 'USD,EUR,GBP' }
11
+ default_locale { 'en' }
11
12
  facebook { 'spreecommerce' }
12
13
  twitter { 'spreecommerce' }
13
14
  instagram { 'spreecommerce' }
@@ -0,0 +1,101 @@
1
+ module Spree
2
+ module TestingSupport
3
+ module FlatpickrCapybara
4
+ def fill_in_date_manually(label_text, with:)
5
+ with_open_flatpickr(label_text) do |field|
6
+ fill_in field[:id], with: with
7
+ end
8
+ end
9
+
10
+ def fill_in_date_picker(label_text, with:)
11
+ within_open_flatpickr(label_text) do
12
+ within_flatpickr_months do
13
+ fill_in_flatpickr_year(with.split('-')[0])
14
+
15
+ select_flatpickr_month(with.split('-')[1])
16
+
17
+ click_on_flatpickr_day(with.split('-')[2])
18
+ end
19
+ end
20
+ end
21
+
22
+ def fill_in_date_time_picker(label_text, with:)
23
+ within_open_flatpickr(label_text) do
24
+ within_flatpickr_months do
25
+ fill_in_flatpickr_year(with.split('-')[0])
26
+
27
+ select_flatpickr_month(with.split('-')[1])
28
+
29
+ click_on_flatpickr_day(with.split('-')[2])
30
+ end
31
+
32
+ within_flatpickr_time do
33
+ select_flatpickr_hour(with.split('-')[3])
34
+
35
+ select_flatpickr_min(with.split('-')[4])
36
+ end
37
+ end
38
+ end
39
+
40
+ def fill_in_date_with_js(label_text, with:)
41
+ date_field = find("input[id='#{label_text}']")
42
+ script = "document.querySelector('#{date_field}').flatpickr().setDate('#{with}');"
43
+
44
+ page.execute_script(script)
45
+ end
46
+
47
+ private
48
+
49
+ def with_open_flatpickr(label_text)
50
+ field_label = find_field(id: label_text, type: :hidden)
51
+
52
+ date_field = field_label.sibling('.flatpickr-alt-input')
53
+ date_field.click # Open the widget
54
+
55
+ yield(date_field)
56
+
57
+ date_field.send_keys :tab # Close the date picker widget
58
+ end
59
+
60
+ def within_open_flatpickr(label_text)
61
+ with_open_flatpickr(label_text) do
62
+ within find(:xpath, "/html/body/div[contains(@class, 'flatpickr-calendar')]") { yield }
63
+ end
64
+ end
65
+
66
+ def within_flatpickr_months
67
+ within find('.flatpickr-months .flatpickr-month .flatpickr-current-month') { yield }
68
+ end
69
+
70
+ def within_flatpickr_time
71
+ within find('.flatpickr-time') { yield }
72
+ end
73
+
74
+ def select_flatpickr_month(month)
75
+ find("select.flatpickr-monthDropdown-months > option:nth-child(#{month.to_i})").select_option
76
+ end
77
+
78
+ def fill_in_flatpickr_year(year)
79
+ find('input.cur-year').set(year)
80
+ end
81
+
82
+ def click_on_flatpickr_day(day)
83
+ within_flatpickr_days do
84
+ find('span', text: day).click
85
+ end
86
+ end
87
+
88
+ def within_flatpickr_days
89
+ within find('.flatpickr-innerContainer > .flatpickr-rContainer > .flatpickr-days') { yield }
90
+ end
91
+
92
+ def select_flatpickr_hour(hour)
93
+ find('input.flatpickr-hour').set(hour)
94
+ end
95
+
96
+ def select_flatpickr_min(min)
97
+ find('input.flatpickr-minute').set(min)
98
+ end
99
+ end
100
+ end
101
+ end