workarea-storefront 3.4.45 → 3.5.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +52 -0
  3. data/app/assets/javascripts/workarea/storefront/application.js.erb +2 -12
  4. data/app/assets/javascripts/workarea/storefront/config.js.erb +0 -5
  5. data/app/assets/javascripts/workarea/storefront/modules/{analytics.js → analytics.js.erb} +17 -0
  6. data/app/assets/javascripts/workarea/storefront/modules/dialog_buttons.js +1 -1
  7. data/app/assets/javascripts/workarea/storefront/modules/workarea_analytics.js +4 -0
  8. data/app/assets/stylesheets/workarea/storefront/application.scss.erb +0 -2
  9. data/app/assets/stylesheets/workarea/storefront/email/_base.scss +9 -1
  10. data/app/assets/stylesheets/workarea/storefront/email/_components.scss +1 -1
  11. data/app/assets/stylesheets/workarea/storefront/email/_helpers.scss +16 -0
  12. data/app/assets/stylesheets/workarea/storefront/email/{_settings.scss → _settings.scss.erb} +1 -1
  13. data/app/controllers/workarea/storefront/analytics_controller.rb +36 -21
  14. data/app/controllers/workarea/storefront/application_controller.rb +2 -4
  15. data/app/controllers/workarea/storefront/cart_items_controller.rb +1 -2
  16. data/app/controllers/workarea/storefront/checkout/addresses_controller.rb +0 -2
  17. data/app/controllers/workarea/storefront/checkouts_controller.rb +6 -4
  18. data/app/controllers/workarea/storefront/content_areas_controller.rb +1 -0
  19. data/app/controllers/workarea/storefront/content_blocks_controller.rb +1 -0
  20. data/app/controllers/workarea/storefront/current_checkout.rb +20 -14
  21. data/app/controllers/workarea/storefront/downloads_controller.rb +18 -0
  22. data/app/controllers/workarea/storefront/email_signups_controller.rb +1 -0
  23. data/app/controllers/workarea/storefront/errors_controller.rb +6 -0
  24. data/app/controllers/workarea/storefront/recent_views_controller.rb +2 -35
  25. data/app/controllers/workarea/storefront/recommendations_controller.rb +2 -2
  26. data/app/controllers/workarea/storefront/searches_controller.rb +0 -11
  27. data/app/controllers/workarea/storefront/users/accounts_controller.rb +2 -7
  28. data/app/controllers/workarea/storefront/users/credit_cards_controller.rb +5 -2
  29. data/app/controllers/workarea/storefront/users/passwords_controller.rb +1 -5
  30. data/app/helpers/workarea/storefront/application_helper.rb +19 -3
  31. data/app/helpers/workarea/storefront/content_helper.rb +1 -1
  32. data/app/helpers/workarea/storefront/favicons_helper.rb +6 -7
  33. data/app/helpers/workarea/storefront/navigation_helper.rb +10 -0
  34. data/app/helpers/workarea/storefront/schema_org_helper.rb +156 -0
  35. data/app/mailers/workarea/storefront/application_mailer.rb +1 -0
  36. data/app/view_models/workarea/storefront/category_view_model.rb +2 -2
  37. data/app/view_models/workarea/storefront/content_block_view_model.rb +41 -10
  38. data/app/view_models/workarea/storefront/content_blocks/product_insights_view_model.rb +1 -1
  39. data/app/view_models/workarea/storefront/display_content.rb +3 -1
  40. data/app/view_models/workarea/storefront/inquiry_view_model.rb +1 -7
  41. data/app/view_models/workarea/storefront/inventory_status_view_model.rb +10 -6
  42. data/app/view_models/workarea/storefront/order_item_view_model.rb +14 -0
  43. data/app/view_models/workarea/storefront/product_view_model.rb +22 -4
  44. data/app/view_models/workarea/storefront/recommendations_view_model.rb +8 -4
  45. data/app/view_models/workarea/storefront/search_view_model.rb +1 -1
  46. data/app/view_models/workarea/storefront/user_activity_view_model.rb +6 -17
  47. data/app/views/layouts/workarea/storefront/application.html.haml +13 -17
  48. data/app/views/layouts/workarea/storefront/checkout.html.haml +1 -1
  49. data/app/views/layouts/workarea/storefront/content_preview.html.haml +1 -0
  50. data/app/views/layouts/workarea/storefront/email.html.haml +33 -26
  51. data/app/views/layouts/workarea/storefront/empty.html.haml +1 -0
  52. data/app/views/layouts/workarea/storefront/navigation.html.haml +1 -1
  53. data/app/views/workarea/storefront/account_mailer/creation.html.haml +2 -0
  54. data/app/views/workarea/storefront/account_mailer/password_reset.html.haml +2 -0
  55. data/app/views/workarea/storefront/cart_items/create.html.haml +1 -1
  56. data/app/views/workarea/storefront/carts/show.html.haml +1 -1
  57. data/app/views/workarea/storefront/categories/show.html.haml +3 -2
  58. data/app/views/workarea/storefront/checkouts/confirmation.html.haml +1 -1
  59. data/app/views/workarea/storefront/contacts/show.html.haml +4 -2
  60. data/app/views/workarea/storefront/content_areas/show.html.haml +1 -0
  61. data/app/views/workarea/storefront/content_blocks/_category_summary.html.haml +2 -1
  62. data/app/views/workarea/storefront/content_blocks/_product_insights.html.haml +2 -1
  63. data/app/views/workarea/storefront/content_blocks/_product_list.html.haml +2 -1
  64. data/app/views/workarea/storefront/errors/show.html.haml +1 -0
  65. data/app/views/workarea/storefront/fulfillment_mailer/shipped.html.haml +3 -1
  66. data/app/views/workarea/storefront/order_mailer/_summary.html.haml +6 -0
  67. data/app/views/workarea/storefront/order_mailer/confirmation.html.haml +3 -0
  68. data/app/views/workarea/storefront/order_mailer/reminder.html.haml +3 -0
  69. data/app/views/workarea/storefront/orders/_summary.html.haml +3 -1
  70. data/app/views/workarea/storefront/orders/show.html.haml +3 -3
  71. data/app/views/workarea/storefront/pages/home_page.html.haml +4 -0
  72. data/app/views/workarea/storefront/pages/robots.text.erb +0 -1
  73. data/app/views/workarea/storefront/pages/show.html.haml +1 -0
  74. data/app/views/workarea/storefront/products/_price.html.haml +1 -2
  75. data/app/views/workarea/storefront/products/_pricing.html.haml +12 -6
  76. data/app/views/workarea/storefront/products/_summary.html.haml +3 -3
  77. data/app/views/workarea/storefront/products/show.html.haml +6 -4
  78. data/app/views/workarea/storefront/products/templates/_generic.html.haml +5 -5
  79. data/app/views/workarea/storefront/products/templates/_option_selects.html.haml +5 -7
  80. data/app/views/workarea/storefront/products/templates/_option_thumbnails.html.haml +5 -7
  81. data/app/views/workarea/storefront/recent_views/aside.html.haml +3 -10
  82. data/app/views/workarea/storefront/recent_views/narrow.html.haml +3 -10
  83. data/app/views/workarea/storefront/recent_views/show.html.haml +3 -10
  84. data/app/views/workarea/storefront/recommendations/show.html.haml +1 -1
  85. data/app/views/workarea/storefront/searches/show.html.haml +4 -5
  86. data/app/views/workarea/storefront/users/accounts/edit.html.haml +3 -3
  87. data/app/views/workarea/storefront/users/accounts/show.html.haml +3 -3
  88. data/app/views/workarea/storefront/users/addresses/edit.html.haml +3 -3
  89. data/app/views/workarea/storefront/users/addresses/new.html.haml +3 -3
  90. data/app/views/workarea/storefront/users/credit_cards/edit.html.haml +3 -3
  91. data/app/views/workarea/storefront/users/credit_cards/new.html.haml +3 -3
  92. data/app/views/workarea/storefront/users/orders/index.html.haml +3 -3
  93. data/app/views/workarea/storefront/users/orders/show.html.haml +4 -4
  94. data/app/views/workarea/storefront/users/passwords/new.html.haml +3 -3
  95. data/config/locales/en.yml +16 -3
  96. data/config/routes.rb +4 -2
  97. data/test/dummy/config/initializers/session_store.rb +1 -1
  98. data/test/helpers/workarea/storefront/content_helper_test.rb +1 -0
  99. data/test/helpers/workarea/storefront/navigation_helper_test.rb +4 -0
  100. data/test/helpers/workarea/storefront/schema_org_helper_test.rb +27 -0
  101. data/test/integration/workarea/storefront/analytics_integration_test.rb +44 -4
  102. data/test/integration/workarea/storefront/cart_items_integration_test.rb +0 -12
  103. data/test/integration/workarea/storefront/categories_integration_test.rb +0 -10
  104. data/test/integration/workarea/storefront/checkout_side_effects_integration_test.rb +15 -1
  105. data/test/integration/workarea/storefront/checkouts_integration_test.rb +68 -11
  106. data/test/integration/workarea/storefront/contact_form_integration_test.rb +18 -20
  107. data/test/integration/workarea/storefront/content_blocks_integration_test.rb +1 -4
  108. data/test/integration/workarea/storefront/current_checkout_integration_test.rb +53 -2
  109. data/test/integration/workarea/storefront/downloads_integration_test.rb +38 -0
  110. data/test/integration/workarea/storefront/email_signups_integration_test.rb +2 -0
  111. data/test/integration/workarea/storefront/guest_browsing_integration_test.rb +2 -2
  112. data/test/integration/workarea/storefront/impersonations_integration_test.rb +2 -2
  113. data/test/integration/workarea/storefront/login_integration_test.rb +3 -9
  114. data/test/integration/workarea/storefront/order_data_integration_test.rb +1 -9
  115. data/test/integration/workarea/storefront/place_order_integration_test.rb +5 -7
  116. data/test/integration/workarea/storefront/placing_order_integration_test.rb +1 -1
  117. data/test/integration/workarea/storefront/recent_views_integration_test.rb +29 -0
  118. data/test/integration/workarea/storefront/releases_integration_test.rb +132 -0
  119. data/test/integration/workarea/storefront/search_integration_test.rb +0 -46
  120. data/test/integration/workarea/storefront/segment_overrides_integration_test.rb +48 -0
  121. data/test/integration/workarea/storefront/segments_integration_test.rb +250 -0
  122. data/test/integration/workarea/storefront/store_credit_integration_test.rb +1 -1
  123. data/test/integration/workarea/storefront/users/credit_cards_integration_test.rb +2 -2
  124. data/test/integration/workarea/storefront/users/passwords_integration_test.rb +0 -19
  125. data/test/javascripts/traffic_referrer_spec.js +1 -1
  126. data/test/mailers/workarea/storefront/transactional_mailer_test.rb +9 -13
  127. data/test/system/workarea/storefront/analytics_system_test.rb +54 -40
  128. data/test/system/workarea/storefront/content_system_test.rb +10 -1
  129. data/test/system/workarea/storefront/digital_products_system_test.rb +2 -0
  130. data/test/system/workarea/storefront/download_system_test.rb +145 -0
  131. data/test/system/workarea/storefront/guest_checkout_system_test.rb +20 -0
  132. data/test/system/workarea/storefront/logged_in_checkout_system_test.rb +31 -32
  133. data/test/system/workarea/storefront/passwords_system_test.rb +35 -37
  134. data/test/system/workarea/storefront/pricing_overrides_system_test.rb +13 -2
  135. data/test/system/workarea/storefront/segment_overrides_system_test.rb +69 -0
  136. data/test/view_models/workarea/storefront/category_view_model_test.rb +20 -0
  137. data/test/view_models/workarea/storefront/content_block_view_model_test.rb +135 -3
  138. data/test/view_models/workarea/storefront/display_content_test.rb +4 -0
  139. data/test/view_models/workarea/storefront/product_view_model/option_set_test.rb +7 -8
  140. data/test/view_models/workarea/storefront/product_view_model_test.rb +17 -10
  141. data/test/view_models/workarea/storefront/search_view_model_test.rb +0 -6
  142. data/test/view_models/workarea/storefront/user_activity_view_model_test.rb +18 -20
  143. metadata +20 -22
  144. data/app/assets/javascripts/workarea/storefront/modules/recent_views.js +0 -25
  145. data/app/assets/javascripts/workarea/storefront/modules/search_fields.js +0 -59
  146. data/app/assets/javascripts/workarea/storefront/templates/ui_menu_heading.jst.ejs +0 -1
  147. data/app/assets/javascripts/workarea/storefront/templates/ui_menu_item.jst.ejs +0 -8
  148. data/app/assets/stylesheets/jquery_ui/storefront/_ui_autocomplete.scss +0 -17
  149. data/app/assets/stylesheets/jquery_ui/storefront/_ui_menu.scss +0 -40
  150. data/app/controllers/workarea/storefront/http_caching.rb +0 -33
  151. data/app/controllers/workarea/storefront/user_activity.rb +0 -19
  152. data/app/view_models/workarea/storefront/search_suggestion_view_model.rb +0 -87
  153. data/app/views/workarea/storefront/searches/index.json.jbuilder +0 -1
  154. data/app/views/workarea/storefront/style_guides/components/_ui_autocomplete.html.haml +0 -11
  155. data/test/dummy/tmp/screenshots/.keep +0 -0
  156. data/test/view_models/workarea/storefront/search_suggestion_view_model_test.rb +0 -42
@@ -184,6 +184,26 @@ module Workarea
184
184
  assert(page.has_content?('Error'))
185
185
  end
186
186
 
187
+ def test_fraud_payment_failure
188
+ assert_current_path(storefront.checkout_addresses_path)
189
+ fill_in 'email', with: 'decline@workarea.com'
190
+ fill_in_shipping_address
191
+ uncheck 'same_as_shipping'
192
+ fill_in_billing_address
193
+ click_button t('workarea.storefront.checkouts.continue_to_shipping')
194
+
195
+ assert_current_path(storefront.checkout_shipping_path)
196
+ click_button t('workarea.storefront.checkouts.continue_to_payment')
197
+
198
+ assert_current_path(storefront.checkout_payment_path)
199
+ fill_in_credit_card
200
+ fill_in 'credit_card[number]', with: '1'
201
+ click_button t('workarea.storefront.checkouts.place_order')
202
+
203
+ assert_current_path(storefront.checkout_place_order_path)
204
+ assert(page.has_content?('Error'))
205
+ end
206
+
187
207
  def test_unavailable_inventory
188
208
  assert_current_path(storefront.checkout_addresses_path)
189
209
  fill_in_email
@@ -32,8 +32,9 @@ module Workarea
32
32
 
33
33
  def test_starting_checkout_as_guest
34
34
  travel(30.minutes) do
35
- # Simulates the browser expiring the cookie
36
- page.driver.browser.manage.delete_cookie('user_id')
35
+ # Simulates the browser expiring the session cookie
36
+ session_cookie = Rails.application.config.session_options[:key]
37
+ page.driver.browser.manage.delete_cookie(session_cookie)
37
38
 
38
39
  visit storefront.checkout_path
39
40
 
@@ -57,42 +58,40 @@ module Workarea
57
58
  end
58
59
 
59
60
  def test_preselecting_addresses_from_saved_addresses
60
- Workarea.with_config do |config|
61
- config.countries = [Country['US'], Country['CA']]
62
-
63
- add_user_data
64
-
65
- user = User.find_by_email('bcrouse@workarea.com')
66
- user.auto_save_shipping_address(
67
- first_name: 'Ben',
68
- last_name: 'Crouse',
69
- street: '1525 Robson St.',
70
- city: 'Vancouver',
71
- region: 'BC',
72
- postal_code: 'V6G 1C3',
73
- country: 'CA',
74
- phone_number: '18444710783'
75
- )
61
+ Workarea.config.countries = [Country['US'], Country['CA']]
62
+
63
+ add_user_data
64
+
65
+ user = User.find_by_email('bcrouse@workarea.com')
66
+ user.auto_save_shipping_address(
67
+ first_name: 'Ben',
68
+ last_name: 'Crouse',
69
+ street: '1525 Robson St.',
70
+ city: 'Vancouver',
71
+ region: 'BC',
72
+ postal_code: 'V6G 1C3',
73
+ country: 'CA',
74
+ phone_number: '18444710783'
75
+ )
76
76
 
77
- visit storefront.checkout_addresses_path
77
+ visit storefront.checkout_addresses_path
78
78
 
79
- select 'Ben Crouse 1019 S. 47th St. Philadelphia PA 19143', from: 'saved_addresses_0'
80
- assert_equal(find('select[name="shipping_address[country]"]').value, 'US')
81
- assert_equal(find('#shipping_address_region_select').value, 'PA')
79
+ select 'Ben Crouse 1019 S. 47th St. Philadelphia PA 19143', from: 'saved_addresses_0'
80
+ assert_equal(find('select[name="shipping_address[country]"]').value, 'US')
81
+ assert_equal(find('#shipping_address_region_select').value, 'PA')
82
82
 
83
- select 'Ben Crouse 1525 Robson St. Vancouver BC V6G 1C3', from: 'saved_addresses_0'
84
- assert_equal(find('select[name="shipping_address[country]"]').value, 'CA')
85
- assert_equal(find('#shipping_address_region_select').value, 'BC')
83
+ select 'Ben Crouse 1525 Robson St. Vancouver BC V6G 1C3', from: 'saved_addresses_0'
84
+ assert_equal(find('select[name="shipping_address[country]"]').value, 'CA')
85
+ assert_equal(find('#shipping_address_region_select').value, 'BC')
86
86
 
87
- select 'Ben Crouse 1019 S. 47th St. Philadelphia PA 19143', from: 'saved_addresses_1'
88
- assert_equal(find('select[name="billing_address[country]"]').value, 'US')
89
- assert_equal(find('#billing_address_region_select').value, 'PA')
87
+ select 'Ben Crouse 1019 S. 47th St. Philadelphia PA 19143', from: 'saved_addresses_1'
88
+ assert_equal(find('select[name="billing_address[country]"]').value, 'US')
89
+ assert_equal(find('#billing_address_region_select').value, 'PA')
90
90
 
91
- click_button t('workarea.storefront.checkouts.continue_to_shipping')
91
+ click_button t('workarea.storefront.checkouts.continue_to_shipping')
92
92
 
93
- assert(page.has_content?('1019 S. 47th St.'))
94
- assert(page.has_no_content?('22 S. 3rd St.'))
95
- end
93
+ assert(page.has_content?('1019 S. 47th St.'))
94
+ assert(page.has_no_content?('22 S. 3rd St.'))
96
95
  end
97
96
 
98
97
  def test_express_checkout
@@ -102,56 +102,54 @@ module Workarea
102
102
  end
103
103
 
104
104
  def test_admin_forcing_password_resets
105
- Workarea.with_config do |config|
106
- config.password_lifetime = 1.second
107
- sleep(1)
105
+ Workarea.config.password_lifetime = 1.second
106
+ sleep(1)
108
107
 
109
- # sign in for the first time
110
- visit storefront.login_path
108
+ # sign in for the first time
109
+ visit storefront.login_path
111
110
 
112
- within '#login_form' do
113
- fill_in 'email', with: @admin_email
114
- fill_in 'password', with: 'W3bl1nc!'
115
- click_button t('workarea.storefront.users.login')
116
- end
111
+ within '#login_form' do
112
+ fill_in 'email', with: @admin_email
113
+ fill_in 'password', with: 'W3bl1nc!'
114
+ click_button t('workarea.storefront.users.login')
115
+ end
117
116
 
118
- assert_current_path(storefront.change_password_path)
117
+ assert_current_path(storefront.change_password_path)
119
118
 
120
- # sign out
121
- reset_session!
119
+ # sign out
120
+ reset_session!
122
121
 
123
- visit storefront.login_path
122
+ visit storefront.login_path
124
123
 
125
- # sign in again
126
- within '#login_form' do
127
- fill_in 'email', with: @admin_email
128
- fill_in 'password', with: 'W3bl1nc!'
129
- click_button t('workarea.storefront.users.login')
130
- end
124
+ # sign in again
125
+ within '#login_form' do
126
+ fill_in 'email', with: @admin_email
127
+ fill_in 'password', with: 'W3bl1nc!'
128
+ click_button t('workarea.storefront.users.login')
129
+ end
131
130
 
132
- assert_current_path(storefront.change_password_path)
131
+ assert_current_path(storefront.change_password_path)
133
132
 
134
- # disallow all other page movement
135
- visit storefront.root_path
136
- assert_current_path(storefront.change_password_path)
133
+ # disallow all other page movement
134
+ visit storefront.root_path
135
+ assert_current_path(storefront.change_password_path)
137
136
 
138
- config.password_lifetime = 1.hour
139
- fill_in 'old_password', with: 'W3bl1nc!'
140
- fill_in 'password', with: @password
141
- click_button t('workarea.storefront.users.change_password')
137
+ Workarea.config.password_lifetime = 1.hour
138
+ fill_in 'old_password', with: 'W3bl1nc!'
139
+ fill_in 'password', with: @password
140
+ click_button t('workarea.storefront.users.change_password')
142
141
 
143
- assert_current_path(storefront.users_account_path)
142
+ assert_current_path(storefront.users_account_path)
144
143
 
145
- click_link t('workarea.storefront.users.logout')
146
- visit storefront.login_path
144
+ click_link t('workarea.storefront.users.logout')
145
+ visit storefront.login_path
147
146
 
148
- within '#login_form' do
149
- fill_in 'email', with: @admin_email
150
- fill_in 'password', with: @password
151
- click_button t('workarea.storefront.users.login')
152
- end
153
- assert_current_path(admin.root_path)
147
+ within '#login_form' do
148
+ fill_in 'email', with: @admin_email
149
+ fill_in 'password', with: @password
150
+ click_button t('workarea.storefront.users.login')
154
151
  end
152
+ assert_current_path(admin.root_path)
155
153
  end
156
154
  end
157
155
  end
@@ -1,8 +1,8 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Workarea
4
- module Admin
5
- class PricingOverridesSystemTest < SystemTest
4
+ module Storefront
5
+ class PricingOverridesSystemTest < Workarea::SystemTest
6
6
  include Admin::IntegrationTest
7
7
  include Storefront::SystemTest
8
8
 
@@ -40,6 +40,17 @@ module Workarea
40
40
  assert(page.has_content?('Success'))
41
41
  assert(page.has_content?('$10.70')) # total w/ shipping
42
42
  end
43
+
44
+ def test_not_having_permission_to_override
45
+ admin_user.update!(super_admin: false, admin: true, orders_manager: false)
46
+
47
+ visit storefront.cart_path
48
+
49
+ wait_for_xhr
50
+ within_frame find('.admin-toolbar') do
51
+ assert(page.has_no_content?(t('workarea.admin.toolbar.adjust_order_pricing')))
52
+ end
53
+ end
43
54
  end
44
55
  end
45
56
  end
@@ -0,0 +1,69 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ class SegmentOverridesSystemTest < Workarea::SystemTest
6
+ def test_previewing_a_segment
7
+ admin = create_user(super_admin: true)
8
+ segment_one = create_segment(name: 'Test One', rules: [])
9
+ segment_two = create_segment(name: 'Test Two', rules: [])
10
+
11
+ content = Content.for('home_page')
12
+ content.blocks.create!(
13
+ type: 'html',
14
+ data: { 'html' => '<p>Foo</p>' },
15
+ active_segment_ids: [segment_one.id]
16
+ )
17
+ content.blocks.create!(
18
+ type: 'html',
19
+ data: { 'html' => '<p>Bar</p>' },
20
+ active_segment_ids: [segment_two.id]
21
+ )
22
+
23
+ # Don't use `set_current_user` because we need to test middleware stack
24
+ visit storefront.login_path
25
+
26
+ within '#login_form' do
27
+ fill_in 'email', with: admin.email
28
+ fill_in 'password', with: admin.password
29
+ click_button t('workarea.storefront.users.login')
30
+ end
31
+
32
+ assert(page.has_content?('Success'))
33
+
34
+ visit storefront.root_path
35
+ within_frame find('.admin-toolbar') do
36
+ wait_for_iframe
37
+ click_link 'select_segments'
38
+ end
39
+
40
+ assert_content(t('workarea.admin.segment_overrides.show.title'))
41
+ find("#segment_ids_#{segment_one.id}_#{segment_one.id}_true_label").click
42
+ click_button 'set_overrides'
43
+
44
+ assert_current_path(storefront.root_path)
45
+ assert_content('Foo')
46
+ assert_no_content('Bar')
47
+ within_frame find('.admin-toolbar') do
48
+ wait_for_iframe
49
+ assert_content('Test One')
50
+ click_link 'select_segments'
51
+ end
52
+
53
+ assert_content(t('workarea.admin.segment_overrides.show.title'))
54
+ find("#segment_ids_#{segment_one.id}_#{segment_one.id}_false_label").click
55
+ find("#segment_ids_#{segment_two.id}_#{segment_two.id}_true_label").click
56
+ click_button 'set_overrides'
57
+
58
+ assert_current_path(storefront.root_path)
59
+ assert_no_content('Foo')
60
+ assert_content('Bar')
61
+ within_frame find('.admin-toolbar') do
62
+ wait_for_iframe
63
+ refute_content('Test One')
64
+ assert_content('Test Two')
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -46,6 +46,26 @@ module Workarea
46
46
  )
47
47
  end
48
48
 
49
+ def test_rules
50
+ @category.product_rules.create!(
51
+ name: 'search',
52
+ operator: 'equals',
53
+ value: 'foo'
54
+ )
55
+ @category.product_rules.create!(
56
+ name: 'search',
57
+ operator: 'equals',
58
+ value: 'bar',
59
+ active: false
60
+ )
61
+
62
+ view_model = CategoryViewModel.new(@category)
63
+ assert_equal(
64
+ @category.product_rules.take(1),
65
+ view_model.search_query.params[:rules]
66
+ )
67
+ end
68
+
49
69
  def test_sorts
50
70
  view_model = CategoryViewModel.new(@category)
51
71
  refute_includes(view_model.sorts.map(&:last), :featured)
@@ -19,7 +19,7 @@ module Workarea
19
19
  end
20
20
 
21
21
  def test_wrap
22
- Content.define_block_types do
22
+ Content::BlockTypeDefinition.define do
23
23
  block_type 'Bar' do
24
24
  view_model FooBarViewModel.name
25
25
  field 'Display', :string
@@ -36,7 +36,16 @@ module Workarea
36
36
  end
37
37
 
38
38
  def test_find_asset
39
- view_model = ContentBlockViewModel.new
39
+ Content::BlockTypeDefinition.define do
40
+ block_type 'Bar' do
41
+ view_model FooBarViewModel.name
42
+ field 'Image', :asset
43
+ end
44
+ end
45
+
46
+ block = Content::Block.new(type_id: 'bar')
47
+
48
+ view_model = ContentBlockViewModel.new(block)
40
49
  assert_equal(Content::Asset.image_placeholder, view_model.find_asset('asdf'))
41
50
 
42
51
  asset = create_asset
@@ -44,7 +53,7 @@ module Workarea
44
53
  end
45
54
 
46
55
  def test_series
47
- Content.define_block_types do
56
+ Content::BlockTypeDefinition.define do
48
57
  block_type 'Bar' do
49
58
  view_model FooBarViewModel.name
50
59
 
@@ -81,6 +90,129 @@ module Workarea
81
90
  assert_equal('Hey', view_model.series.second.data[:display])
82
91
  assert_equal('Sup', view_model.series.third.data[:display])
83
92
  end
93
+
94
+ def test_assets
95
+ asset_1 = create_asset
96
+ asset_2 = create_asset
97
+
98
+ Content::BlockTypeDefinition.define do
99
+ block_type 'Foo' do
100
+ view_model FooBarViewModel.name
101
+
102
+ field 'Gralph', :asset
103
+ field 'Corge', :asset
104
+ end
105
+ end
106
+
107
+ Content::BlockTypeDefinition.define do
108
+ block_type 'Bar' do
109
+ view_model FooBarViewModel.name
110
+
111
+ field 'Gralph', :asset, default: asset_1.id
112
+ field 'Corge', :asset
113
+ end
114
+ end
115
+
116
+ Content::BlockTypeDefinition.define do
117
+ block_type 'Baz' do
118
+ view_model FooBarViewModel.name
119
+
120
+ field 'Gralph', :asset, default: asset_1.id
121
+ field 'Corge', :asset, default: asset_2.id
122
+ end
123
+ end
124
+
125
+ Content::BlockTypeDefinition.define do
126
+ block_type 'Qux' do
127
+ view_model FooBarViewModel.name
128
+
129
+ field 'Gralph', :asset, default: asset_1.id
130
+ field 'Corge', :asset, default: 'foobar'
131
+ end
132
+ end
133
+
134
+ block_type = Content::BlockType.find(:foo)
135
+ block = Content::Block.new(type: 'foo', data: block_type.defaults)
136
+ view_model = ContentBlockViewModel.wrap(block)
137
+
138
+ assert_empty(view_model.assets)
139
+
140
+ block_type = Content::BlockType.find(:bar)
141
+ block = Content::Block.new(type: 'bar', data: block_type.defaults)
142
+ view_model = ContentBlockViewModel.wrap(block)
143
+
144
+ assert_equal(1, view_model.assets.size)
145
+ assert_equal(asset_1.id.to_s, view_model.assets.keys.first)
146
+ assert_equal(asset_1, view_model.assets.values.first)
147
+
148
+ block_type = Content::BlockType.find(:baz)
149
+ block = Content::Block.new(type: 'baz', data: block_type.defaults)
150
+ view_model = ContentBlockViewModel.wrap(block)
151
+
152
+ assert_equal(2, view_model.assets.size)
153
+ assert_equal(asset_1, view_model.assets.values.first)
154
+ assert_equal(asset_2, view_model.assets.values.last)
155
+
156
+ block_type = Content::BlockType.find(:qux)
157
+ block = Content::Block.new(type: 'qux', data: block_type.defaults)
158
+ view_model = ContentBlockViewModel.wrap(block)
159
+
160
+ assert_equal(2, view_model.assets.size)
161
+ assert_equal(asset_1, view_model.assets.values.first)
162
+ assert_equal(Content::Asset.image_placeholder, view_model.assets.values.last)
163
+ end
164
+
165
+ def test_asset_alt_text
166
+ asset = create_asset(alt_text: 'Foo Bar')
167
+
168
+ Content::BlockTypeDefinition.define do
169
+ block_type 'Foo' do
170
+ view_model FooBarViewModel.name
171
+
172
+ field 'Image', :asset, default: asset.id, alt_field: 'Alt text field'
173
+ field 'Alt Text Field', :string, default: 'Bar Baz'
174
+ end
175
+ end
176
+
177
+ block_type = Content::BlockType.find(:foo)
178
+ block = Content::Block.new(type: 'foo', data: block_type.defaults)
179
+ view_model = ContentBlockViewModel.wrap(block)
180
+
181
+ assert_equal(1, view_model.asset_alt_text.size)
182
+ assert_equal(:alt_text_field, view_model.asset_alt_text.keys.first)
183
+ assert_equal('Foo Bar', view_model.asset_alt_text[:alt_text_field])
184
+ end
185
+
186
+ def test_locals_contain_alt_text
187
+ asset = create_asset
188
+ asset_with_alt = create_asset(alt_text: 'Foo Bar')
189
+
190
+ Content::BlockTypeDefinition.define do
191
+ block_type 'Foo' do
192
+ view_model FooBarViewModel.name
193
+
194
+ # Image without alt text
195
+ field 'Image 1', :asset, default: asset.id, alt_field: 'Alt text 1'
196
+ field 'Alt text 1', :string
197
+
198
+ # Image with alt text from asset
199
+ field 'Image 2', :asset, default: asset_with_alt.id, alt_field: 'Alt text 2'
200
+ field 'Alt text 2', :string
201
+
202
+ # Image with alt text overridden by field
203
+ field 'Image 3', :asset, default: asset_with_alt.id, alt_field: 'Alt text 3'
204
+ field 'Alt text 3', :string, default: 'Bar Baz'
205
+ end
206
+ end
207
+
208
+ block_type = Content::BlockType.find(:foo)
209
+ block = Content::Block.new(type: 'foo', data: block_type.defaults)
210
+ view_model = ContentBlockViewModel.wrap(block)
211
+
212
+ assert_nil(view_model.locals[:alt_text_1])
213
+ assert_equal('Foo Bar', view_model.locals[:alt_text_2])
214
+ assert_equal('Bar Baz', view_model.locals[:alt_text_3])
215
+ end
84
216
  end
85
217
  end
86
218
  end