workarea-package_products 3.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.editorconfig +20 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
- data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.gitignore +15 -0
- data/CHANGELOG.md +343 -0
- data/CODE_OF_CONDUCT.md +3 -0
- data/CONTRIBUTING.md +3 -0
- data/Gemfile +16 -0
- data/LICENSE +52 -0
- data/README.md +40 -0
- data/Rakefile +52 -0
- data/app/assets/javascripts/workarea/storefront/package_products/modules/family_product_add_to_cart.js +83 -0
- data/app/assets/javascripts/workarea/storefront/package_products/templates/family_add_to_cart_checkbox.jst.ejs +1 -0
- data/app/assets/stylesheets/workarea/admin/package_products/components/_product_cards.scss +7 -0
- data/app/assets/stylesheets/workarea/storefront/package_products/components/_product_detail_packaged_products.scss +11 -0
- data/app/controllers/workarea/admin/create_catalog_package_products_controller.rb +150 -0
- data/app/controllers/workarea/admin/create_catalog_products_controller.decorator +25 -0
- data/app/controllers/workarea/storefront/cart_items_controller.decorator +29 -0
- data/app/controllers/workarea/storefront/products_controller.decorator +8 -0
- data/app/models/workarea/catalog/product.decorator +44 -0
- data/app/models/workarea/search/admin/catalog_product.decorator +20 -0
- data/app/models/workarea/search/storefront/package_product.rb +40 -0
- data/app/queries/workarea/search/product_entries.decorator +8 -0
- data/app/seeds/workarea/package_product_seeds.rb +41 -0
- data/app/services/workarea/add_package_to_cart.rb +79 -0
- data/app/view_models/workarea/admin/product_view_model.decorator +35 -0
- data/app/view_models/workarea/storefront/product_templates/family_view_model.rb +6 -0
- data/app/view_models/workarea/storefront/product_templates/package_view_model.rb +33 -0
- data/app/view_models/workarea/storefront/product_view_model.decorator +13 -0
- data/app/views/workarea/admin/catalog_products/_create_package_button.html.haml +1 -0
- data/app/views/workarea/admin/catalog_products/_packaged_products_card.html.haml +26 -0
- data/app/views/workarea/admin/create_catalog_package_products/categorization.html.haml +64 -0
- data/app/views/workarea/admin/create_catalog_package_products/content.html.haml +54 -0
- data/app/views/workarea/admin/create_catalog_package_products/details.html.haml +87 -0
- data/app/views/workarea/admin/create_catalog_package_products/images.html.haml +57 -0
- data/app/views/workarea/admin/create_catalog_package_products/packaged_products.html.haml +79 -0
- data/app/views/workarea/admin/create_catalog_package_products/publish.html.haml +61 -0
- data/app/views/workarea/admin/create_catalog_package_products/setup.html.haml +68 -0
- data/app/views/workarea/admin/create_catalog_products/select.html.haml +34 -0
- data/app/views/workarea/storefront/cart_items/package.html.haml +59 -0
- data/app/views/workarea/storefront/products/package_show.html.haml +49 -0
- data/app/views/workarea/storefront/products/templates/_family.html.haml +42 -0
- data/app/views/workarea/storefront/products/templates/_package.html.haml +36 -0
- data/app/workers/workarea/update_package_products.rb +21 -0
- data/bin/rails +16 -0
- data/config/initializers/appends.rb +31 -0
- data/config/initializers/configuration.rb +6 -0
- data/config/initializers/seeds.rb +1 -0
- data/config/locales/en.yml +45 -0
- data/config/routes.rb +30 -0
- data/lib/tasks/sample_data.rake +16 -0
- data/lib/workarea/package_products.rb +10 -0
- data/lib/workarea/package_products/engine.rb +8 -0
- data/lib/workarea/package_products/version.rb +5 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/config/manifest.js +4 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/jobs/application_job.rb +2 -0
- data/test/dummy/app/mailers/application_mailer.rb +4 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +34 -0
- data/test/dummy/bin/update +29 -0
- data/test/dummy/config.ru +5 -0
- data/test/dummy/config/application.rb +18 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/cable.yml +9 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +54 -0
- data/test/dummy/config/environments/production.rb +83 -0
- data/test/dummy/config/environments/test.rb +43 -0
- data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/workarea.rb +5 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/puma.rb +47 -0
- data/test/dummy/config/routes.rb +5 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/db/seeds.rb +2 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/test/dummy/public/apple-touch-icon.png +0 -0
- data/test/dummy/public/favicon.ico +1 -0
- data/test/integration/workarea/admin/create_catalog_package_products_integration_test.rb +139 -0
- data/test/integration/workarea/storefront/package_cart_items_integration_test.rb +47 -0
- data/test/integration/workarea/storefront/products_integration_test.decorator +19 -0
- data/test/models/workarea/catalog/package_product_test.rb +68 -0
- data/test/models/workarea/search/storefront/package_product_test.rb +44 -0
- data/test/queries/workarea/search/product_entries_test.decorator +15 -0
- data/test/services/workarea/add_package_to_cart_test.rb +46 -0
- data/test/system/workarea/admin/activity_system_test.decorator +53 -0
- data/test/system/workarea/admin/package_product_copy_system_test.rb +27 -0
- data/test/system/workarea/admin/package_products_system_test.rb +101 -0
- data/test/system/workarea/admin/product_copy_system_test.decorator +28 -0
- data/test/system/workarea/admin/products_system_test.decorator +69 -0
- data/test/system/workarea/storefront/categories_with_packages_system_test.rb +172 -0
- data/test/system/workarea/storefront/family_product_system_test.rb +58 -0
- data/test/system/workarea/storefront/package_product_system_test.rb +42 -0
- data/test/test_helper.rb +10 -0
- data/test/view_models/workarea/admin/package_product_view_model_test.rb +41 -0
- data/test/view_models/workarea/storefront/package_product_view_model_test.rb +27 -0
- data/test/view_models/workarea/storefront/package_templates/package_view_model_test.rb +34 -0
- data/test/workers/workarea/update_package_products_test.rb +27 -0
- data/workarea-package_products.gemspec +24 -0
- metadata +189 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
module Workarea
|
|
2
|
+
decorate Admin::ProductsSystemTest do
|
|
3
|
+
def test_managing_products
|
|
4
|
+
create_category(name: 'Test Category')
|
|
5
|
+
|
|
6
|
+
visit admin.catalog_products_path
|
|
7
|
+
click_link 'Add New Product'
|
|
8
|
+
click_button t('workarea.admin.create_catalog_products.select.button')
|
|
9
|
+
|
|
10
|
+
fill_in 'product[name]', with: 'Test Product'
|
|
11
|
+
click_button 'save_setup'
|
|
12
|
+
|
|
13
|
+
assert(page.has_content?('Success'))
|
|
14
|
+
assert(page.has_content?('Variants'))
|
|
15
|
+
|
|
16
|
+
fill_in 'variants[][sku]', with: 'TESTSKU'
|
|
17
|
+
fill_in 'variants[][price]', match: :first, with: '20'
|
|
18
|
+
fill_in 'variants[][inventory]', match: :first, with: '99'
|
|
19
|
+
click_button 'save_variants'
|
|
20
|
+
|
|
21
|
+
assert(page.has_content?('Success'))
|
|
22
|
+
assert(page.has_content?('Images'))
|
|
23
|
+
|
|
24
|
+
attach_file 'images[][image]', product_image_file_path
|
|
25
|
+
click_button 'save_images'
|
|
26
|
+
|
|
27
|
+
assert(page.has_content?('Success'))
|
|
28
|
+
assert(page.has_content?('Details'))
|
|
29
|
+
click_button 'save_details'
|
|
30
|
+
|
|
31
|
+
assert(page.has_content?('Success'))
|
|
32
|
+
assert(page.has_content?('Content'))
|
|
33
|
+
|
|
34
|
+
page.execute_script(<<-js
|
|
35
|
+
$("body", $("iframe.wysihtml-sandbox").contents())
|
|
36
|
+
.text("Description")
|
|
37
|
+
js
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
click_button 'save_content'
|
|
41
|
+
|
|
42
|
+
assert(page.has_content?('Success'))
|
|
43
|
+
assert(page.has_content?('Categorization'))
|
|
44
|
+
|
|
45
|
+
find('.select2-selection--multiple').click
|
|
46
|
+
assert(page.has_content?('Test Category'))
|
|
47
|
+
find('.select2-results__option', text: 'Test Category').click
|
|
48
|
+
|
|
49
|
+
click_button 'add_categories'
|
|
50
|
+
assert(page.has_content?('Success'))
|
|
51
|
+
assert(page.has_content?('Test Category'))
|
|
52
|
+
click_link 'Continue to Publish'
|
|
53
|
+
|
|
54
|
+
assert(page.has_content?('Publish'))
|
|
55
|
+
click_button 'publish'
|
|
56
|
+
|
|
57
|
+
click_link 'Attributes'
|
|
58
|
+
fill_in 'product[name]', with: 'Edited Product'
|
|
59
|
+
click_button 'save_product'
|
|
60
|
+
|
|
61
|
+
assert(page.has_content?('Success'))
|
|
62
|
+
assert(page.has_content?('Edited Product'))
|
|
63
|
+
click_link 'Delete'
|
|
64
|
+
|
|
65
|
+
assert_current_path(admin.catalog_products_path)
|
|
66
|
+
assert(page.has_no_content?('Edited Category'))
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
module Workarea
|
|
4
|
+
module Storefront
|
|
5
|
+
class CategoriesWithPackagesSystemTest < Workarea::SystemTest
|
|
6
|
+
include Storefront::SystemTest
|
|
7
|
+
|
|
8
|
+
setup :set_products
|
|
9
|
+
setup :update_search_settings
|
|
10
|
+
|
|
11
|
+
def set_products
|
|
12
|
+
@products ||= [
|
|
13
|
+
create_product(id: 'PROD1',
|
|
14
|
+
name: 'Integration Product 1',
|
|
15
|
+
filters: { 'Size' => 'Medium', 'Color' => %w(Green Red) },
|
|
16
|
+
created_at: Time.now - 1.hour,
|
|
17
|
+
variants: [{ sku: 'SKU1', regular: 10.to_m }]),
|
|
18
|
+
create_product(id: 'PROD2',
|
|
19
|
+
name: 'Integration Product 2',
|
|
20
|
+
filters: { 'Size' => %w(Medium Small), 'Color' => 'Red' },
|
|
21
|
+
created_at: Time.now - 2.hour,
|
|
22
|
+
variants: [{ sku: 'SKU2', regular: 5.to_m, details: { 'Size' => 'Medium' } },
|
|
23
|
+
{ sku: 'SKU4', regular: 5.to_m, details: { 'Size' => 'Large' } }]),
|
|
24
|
+
create_product(id: 'PROD3',
|
|
25
|
+
name: 'Integration Product 3',
|
|
26
|
+
filters: { 'Size' => %w(Medium Small), 'Color' => 'Blue' },
|
|
27
|
+
created_at: Time.now - 3.hour,
|
|
28
|
+
variants: [{ sku: 'SKU3', regular: 5.to_m }]),
|
|
29
|
+
create_product(id: 'PROD4',
|
|
30
|
+
name: 'Integration Package Product 1',
|
|
31
|
+
template: 'package',
|
|
32
|
+
filters: { 'Size' => ['Small', 'Medium', 'Large', 'Extra Large'], 'Color' => %w(Red Green) },
|
|
33
|
+
created_at: Time.now - 4.hour,
|
|
34
|
+
product_ids: %w(PROD1 PROD2 PROD3))
|
|
35
|
+
]
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def categorize_products(category)
|
|
39
|
+
category.update_attributes!(
|
|
40
|
+
product_ids: [@products.second.id, @products.first.id, @products.fourth.id]
|
|
41
|
+
)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_basic_category_setup
|
|
45
|
+
category = create_category
|
|
46
|
+
categorize_products(category)
|
|
47
|
+
|
|
48
|
+
visit storefront.category_path(category)
|
|
49
|
+
|
|
50
|
+
assert(page.has_content?('Integration Product 1'))
|
|
51
|
+
assert(page.has_content?('Integration Product 2'))
|
|
52
|
+
assert(page.has_content?('Integration Package Product 1'))
|
|
53
|
+
assert(page.has_content?('$10.00'))
|
|
54
|
+
assert(page.has_content?('$5.00'))
|
|
55
|
+
assert(page.has_content?('Medium (3)'))
|
|
56
|
+
assert(page.has_content?('Small (2)'))
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_sorting_products
|
|
60
|
+
category = create_category
|
|
61
|
+
categorize_products(category)
|
|
62
|
+
|
|
63
|
+
visit storefront.category_path(category)
|
|
64
|
+
|
|
65
|
+
select('Price, Low to High', from: 'sort_top')
|
|
66
|
+
assert(page.has_ordered_text?(
|
|
67
|
+
'Integration Product 2',
|
|
68
|
+
'Integration Package Product',
|
|
69
|
+
'Integration Product 1'
|
|
70
|
+
))
|
|
71
|
+
|
|
72
|
+
visit storefront.category_path(category)
|
|
73
|
+
select('Price, High to Low', from: 'sort_top')
|
|
74
|
+
assert(page.has_ordered_text?(
|
|
75
|
+
'Integration Product 1',
|
|
76
|
+
'Integration Product 2',
|
|
77
|
+
'Integration Package Product'
|
|
78
|
+
))
|
|
79
|
+
|
|
80
|
+
visit storefront.category_path(category)
|
|
81
|
+
select('Newest', from: 'sort_top')
|
|
82
|
+
assert(page.has_ordered_text?(
|
|
83
|
+
'Integration Product 1',
|
|
84
|
+
'Integration Product 2',
|
|
85
|
+
'Integration Package Product'
|
|
86
|
+
))
|
|
87
|
+
|
|
88
|
+
create_product_by_week(product_id: 'PROD2', orders: 3)
|
|
89
|
+
create_product_by_week(product_id: 'PROD1', orders: 1)
|
|
90
|
+
create_product_by_week(product_id: 'PROD3', orders: 2)
|
|
91
|
+
BulkIndexProducts.perform_by_models(@products)
|
|
92
|
+
|
|
93
|
+
visit storefront.category_path(category)
|
|
94
|
+
select('Top Sellers', from: 'sort_top')
|
|
95
|
+
assert(page.has_ordered_text?(
|
|
96
|
+
'Integration Product 2',
|
|
97
|
+
'Integration Package Product',
|
|
98
|
+
'Integration Product 1'
|
|
99
|
+
))
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def test_package_out_of_stock
|
|
103
|
+
category = create_category
|
|
104
|
+
categorize_products(category)
|
|
105
|
+
|
|
106
|
+
create_inventory(id: 'SKU', policy: 'standard', available: 0)
|
|
107
|
+
create_inventory(id: 'SKU1', policy: 'standard', available: 0)
|
|
108
|
+
create_inventory(id: 'SKU2', policy: 'standard', available: 0)
|
|
109
|
+
create_inventory(id: 'SKU3', policy: 'standard', available: 0)
|
|
110
|
+
create_inventory(id: 'SKU4', policy: 'standard', available: 0)
|
|
111
|
+
|
|
112
|
+
visit storefront.category_path(category)
|
|
113
|
+
|
|
114
|
+
assert(page.has_no_content?('Integration Product 1'))
|
|
115
|
+
assert(page.has_no_content?('Integration Product 2'))
|
|
116
|
+
assert(page.has_no_content?('Integration Package Product 1'))
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def test_filtering_products
|
|
120
|
+
category = create_category
|
|
121
|
+
categorize_products(category)
|
|
122
|
+
|
|
123
|
+
visit storefront.category_path(category)
|
|
124
|
+
|
|
125
|
+
Capybara.match = :first
|
|
126
|
+
click_link '$10.00 - $19.99 (2)'
|
|
127
|
+
|
|
128
|
+
assert(page.has_content?('Integration Product 1'))
|
|
129
|
+
assert(page.has_no_content?('Integration Product 2'))
|
|
130
|
+
assert(page.has_content?('Integration Package Product 1'))
|
|
131
|
+
|
|
132
|
+
click_link '$10.00 - $19.99 (remove)'
|
|
133
|
+
|
|
134
|
+
assert(page.has_content?('Integration Product 1'))
|
|
135
|
+
assert(page.has_content?('Integration Product 2'))
|
|
136
|
+
assert(page.has_content?('Integration Package Product 1'))
|
|
137
|
+
|
|
138
|
+
click_link 'Extra Large (1)'
|
|
139
|
+
|
|
140
|
+
assert(page.has_content?('Integration Package Product 1'))
|
|
141
|
+
assert(page.has_no_content?('Integration Product 1'))
|
|
142
|
+
assert(page.has_no_content?('Integration Product 2'))
|
|
143
|
+
|
|
144
|
+
click_link 'Extra Large (remove)'
|
|
145
|
+
|
|
146
|
+
assert(page.has_content?('Integration Product 1'))
|
|
147
|
+
assert(page.has_content?('Integration Product 2'))
|
|
148
|
+
assert(page.has_content?('Integration Package Product 1'))
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def test_product_filtering_and_sorting
|
|
152
|
+
category = create_category
|
|
153
|
+
categorize_products(category)
|
|
154
|
+
|
|
155
|
+
visit storefront.category_path(category)
|
|
156
|
+
|
|
157
|
+
Capybara.match = :first
|
|
158
|
+
click_link '$10.00 - $19.99 (2)'
|
|
159
|
+
|
|
160
|
+
assert(page.has_content?('Integration Product 1'))
|
|
161
|
+
assert(page.has_no_content?('Integration Product 2'))
|
|
162
|
+
assert(page.has_content?('Integration Package Product 1'))
|
|
163
|
+
|
|
164
|
+
select('Price, Low to High', from: 'sort_top')
|
|
165
|
+
|
|
166
|
+
assert(page.has_content?('Integration Product 1'))
|
|
167
|
+
assert(page.has_no_content?('Integration Product 2'))
|
|
168
|
+
assert(page.has_content?('Integration Package Product 1'))
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
module Workarea
|
|
4
|
+
module Storefront
|
|
5
|
+
class FamilyProductSystemTest < Workarea::SystemTest
|
|
6
|
+
include Storefront::SystemTest
|
|
7
|
+
|
|
8
|
+
def test_adding_a_family_product_to_cart
|
|
9
|
+
packaged_products = [
|
|
10
|
+
create_product(
|
|
11
|
+
name: 'Packaged Product 1',
|
|
12
|
+
variants: [
|
|
13
|
+
{ sku: 'SKU1', regular: 1.to_m },
|
|
14
|
+
{ sku: 'SKU2', regular: 2.to_m }
|
|
15
|
+
]
|
|
16
|
+
),
|
|
17
|
+
create_product(
|
|
18
|
+
name: 'Packaged Product 2',
|
|
19
|
+
variants: [
|
|
20
|
+
{ sku: 'SKU3', regular: 3.to_m },
|
|
21
|
+
{ sku: 'SKU4', regular: 4.to_m }
|
|
22
|
+
]
|
|
23
|
+
)
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
family = create_product(
|
|
27
|
+
name: 'Test Product',
|
|
28
|
+
template: 'family',
|
|
29
|
+
product_ids: packaged_products.map(&:id)
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
visit storefront.product_path(family)
|
|
33
|
+
|
|
34
|
+
assert(page.has_content?('Test Product'))
|
|
35
|
+
assert(page.has_content?('Packaged Product 1'))
|
|
36
|
+
assert(page.has_content?('Packaged Product 2'))
|
|
37
|
+
assert(page.has_content?('$1.00'))
|
|
38
|
+
assert(page.has_content?('$3.00'))
|
|
39
|
+
|
|
40
|
+
product_1 = packaged_products.first
|
|
41
|
+
check "family_product_#{product_1.id}"
|
|
42
|
+
select product_1.variants.first.sku, from: "sku_catalog_product_#{product_1.id}"
|
|
43
|
+
|
|
44
|
+
product_2 = packaged_products.second
|
|
45
|
+
check "family_product_#{product_2.id}"
|
|
46
|
+
select product_2.variants.first.sku, from: "sku_catalog_product_#{product_2.id}"
|
|
47
|
+
|
|
48
|
+
click_button 'Add to Cart'
|
|
49
|
+
|
|
50
|
+
dialog = find('.ui-dialog')
|
|
51
|
+
|
|
52
|
+
assert(dialog.has_content?('Success'))
|
|
53
|
+
assert(dialog.has_content?(product_1.name))
|
|
54
|
+
assert(dialog.has_content?(product_2.name))
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
module Workarea
|
|
4
|
+
module Storefront
|
|
5
|
+
class PackageProductSystemTest < Workarea::SystemTest
|
|
6
|
+
include Storefront::SystemTest
|
|
7
|
+
|
|
8
|
+
def test_showing_package_product
|
|
9
|
+
packaged_products = [
|
|
10
|
+
create_product(
|
|
11
|
+
name: 'Packaged Product 1',
|
|
12
|
+
variants: [
|
|
13
|
+
{ sku: 'SKU1', regular: 1.to_m },
|
|
14
|
+
{ sku: 'SKU2', regular: 2.to_m }
|
|
15
|
+
]
|
|
16
|
+
),
|
|
17
|
+
create_product(
|
|
18
|
+
name: 'Packaged Product 2',
|
|
19
|
+
variants: [
|
|
20
|
+
{ sku: 'SKU3', regular: 3.to_m },
|
|
21
|
+
{ sku: 'SKU4', regular: 4.to_m }
|
|
22
|
+
]
|
|
23
|
+
)
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
package = create_product(
|
|
27
|
+
name: 'Test Product',
|
|
28
|
+
template: 'package',
|
|
29
|
+
product_ids: packaged_products.map(&:id)
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
visit storefront.product_path(package)
|
|
33
|
+
|
|
34
|
+
assert(page.has_content?('Test Product'))
|
|
35
|
+
assert(page.has_content?('Packaged Product 1'))
|
|
36
|
+
assert(page.has_content?('Packaged Product 2'))
|
|
37
|
+
assert(page.has_content?('$1.00'))
|
|
38
|
+
assert(page.has_content?('$3.00'))
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
data/test/test_helper.rb
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Configure Rails Environment
|
|
2
|
+
ENV['RAILS_ENV'] = 'test'
|
|
3
|
+
|
|
4
|
+
require File.expand_path('../../test/dummy/config/environment.rb', __FILE__)
|
|
5
|
+
require 'rails/test_help'
|
|
6
|
+
require 'workarea/test_help'
|
|
7
|
+
|
|
8
|
+
# Filter out Minitest backtrace while allowing backtrace from other libraries
|
|
9
|
+
# to be shown.
|
|
10
|
+
Minitest.backtrace_filter = Minitest::BacktraceFilter.new
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
module Workarea
|
|
4
|
+
module Admin
|
|
5
|
+
# TODO: convert to decorator after base test is converted
|
|
6
|
+
class PackageProductViewModelTest < TestCase
|
|
7
|
+
def test_packaged_products
|
|
8
|
+
create_product(id: 'PROD1', name: 'Test Product 1')
|
|
9
|
+
create_product(id: 'PROD2', name: 'Test Product 2')
|
|
10
|
+
create_product(id: 'PROD3', name: 'Test Product 3')
|
|
11
|
+
|
|
12
|
+
product = create_product(
|
|
13
|
+
name: 'Test Package',
|
|
14
|
+
template: 'package',
|
|
15
|
+
product_ids: %w(PROD2 PROD3 PROD1)
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
view_model = Admin::ProductViewModel.new(product)
|
|
19
|
+
assert_equal(%w(PROD2 PROD3 PROD1), view_model.packaged_products.map(&:id))
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_templates
|
|
23
|
+
product = create_product(
|
|
24
|
+
template: 'package',
|
|
25
|
+
product_ids: ['PROD1']
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
view_model = Admin::ProductViewModel.new(product)
|
|
29
|
+
assert_equal(%w(package family), view_model.templates.map(&:last))
|
|
30
|
+
|
|
31
|
+
product = create_product(template: 'generic')
|
|
32
|
+
|
|
33
|
+
view_model = Admin::ProductViewModel.new(product)
|
|
34
|
+
templates = view_model.templates.map(&:last)
|
|
35
|
+
assert_includes(templates, 'generic')
|
|
36
|
+
refute_includes(templates, 'package')
|
|
37
|
+
refute_includes(templates, 'family')
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
module Workarea
|
|
4
|
+
module Storefront
|
|
5
|
+
class PackageProductViewModelTest < TestCase
|
|
6
|
+
def test_packaged_products
|
|
7
|
+
package_child_1 = create_product(variants: [{ sku: 'SKUC1', regular: 5.00 }])
|
|
8
|
+
package_child_2 = create_product
|
|
9
|
+
package_product = create_product(product_ids: [package_child_1.id, package_child_2.id])
|
|
10
|
+
|
|
11
|
+
view_model = ProductViewModel.new(package_product)
|
|
12
|
+
assert_equal(package_child_1.id, view_model.packaged_products[0].id)
|
|
13
|
+
assert_equal(package_child_2.id, view_model.packaged_products[1].id)
|
|
14
|
+
|
|
15
|
+
create_inventory(id: 'SKUC1', policy: 'standard', available: 0)
|
|
16
|
+
|
|
17
|
+
view_model = ProductViewModel.new(package_product)
|
|
18
|
+
assert_equal(package_child_2.id, view_model.packaged_products[0].id)
|
|
19
|
+
assert_equal(1, view_model.packaged_products.count)
|
|
20
|
+
|
|
21
|
+
bad_packaged_product = create_product(product_ids: [package_child_2.id, 'not_an_id'])
|
|
22
|
+
view_model = ProductViewModel.new(bad_packaged_product)
|
|
23
|
+
assert_equal(1, view_model.packaged_products.count)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
module Workarea
|
|
4
|
+
module Storefront
|
|
5
|
+
module ProductTemplates
|
|
6
|
+
class PackageViewModelTest < TestCase
|
|
7
|
+
def test_packaged_products
|
|
8
|
+
product_one = create_product(template: 'option_selects')
|
|
9
|
+
product_two = create_product
|
|
10
|
+
package = create_product(product_ids: [product_one.id, product_two.id])
|
|
11
|
+
|
|
12
|
+
view_model = Storefront::ProductTemplates::PackageViewModel.new(package)
|
|
13
|
+
|
|
14
|
+
assert_equal(
|
|
15
|
+
Storefront::ProductTemplates::OptionSelectsViewModel,
|
|
16
|
+
view_model.packaged_products.first.class
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
assert_equal(
|
|
20
|
+
Storefront::ProductViewModel,
|
|
21
|
+
view_model.packaged_products.second.class
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
product_one = create_product(template: 'test')
|
|
25
|
+
product_two = create_product(variants: [])
|
|
26
|
+
package = create_product(product_ids: [product_one.id, product_two.id])
|
|
27
|
+
|
|
28
|
+
view_model = Storefront::ProductTemplates::PackageViewModel.new(package)
|
|
29
|
+
assert_equal(1, view_model.packaged_products.length)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|