workarea-browse_option 2.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +20 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
  4. data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  6. data/.gitignore +14 -0
  7. data/CHANGELOG.md +315 -0
  8. data/CODE_OF_CONDUCT.md +3 -0
  9. data/CONTRIBUTING.md +3 -0
  10. data/Gemfile +12 -0
  11. data/LICENSE +52 -0
  12. data/README.md +67 -0
  13. data/Rakefile +52 -0
  14. data/app/controllers/workarea/admin/categorizations_controller.decorator +25 -0
  15. data/app/controllers/workarea/admin/featured_products_controller.decorator +63 -0
  16. data/app/models/workarea/catalog/product.decorator +20 -0
  17. data/app/models/workarea/featured_browse_option_products.rb +13 -0
  18. data/app/models/workarea/search/storefront/product_option.rb +51 -0
  19. data/app/models/workarea/search/storefront/product_option_image_url.rb +18 -0
  20. data/app/queries/workarea/categorization.decorator +12 -0
  21. data/app/queries/workarea/search/product_entries.decorator +17 -0
  22. data/app/queries/workarea/search/related_products.decorator +30 -0
  23. data/app/services/workarea/browse_option_ids.rb +39 -0
  24. data/app/view_models/workarea/admin/bulk_action_product_edit_view_model.decorator +10 -0
  25. data/app/view_models/workarea/admin/featured_browse_option_product_view_model.rb +18 -0
  26. data/app/view_models/workarea/admin/featured_browse_option_products_view_model.rb +23 -0
  27. data/app/view_models/workarea/admin/featured_products_search_view_model.rb +45 -0
  28. data/app/view_models/workarea/admin/product_view_model.decorator +9 -0
  29. data/app/view_models/workarea/storefront/product_view_model/cache_key.decorator +12 -0
  30. data/app/view_models/workarea/storefront/product_view_model/image_collection.decorator +26 -0
  31. data/app/view_models/workarea/storefront/product_view_model.decorator +15 -0
  32. data/app/views/workarea/admin/bulk_action_product_edits/_browse_option_field.html.haml +10 -0
  33. data/app/views/workarea/admin/catalog_products/_browse_option_attribute_card.html.haml +3 -0
  34. data/app/views/workarea/admin/catalog_products/_browse_option_field.html.haml +3 -0
  35. data/app/views/workarea/api/storefront/products/_browse_option_field.json.jbuilder +2 -0
  36. data/app/workers/workarea/bulk_index_products.decorator +34 -0
  37. data/app/workers/workarea/index_category_changes.decorator +7 -0
  38. data/app/workers/workarea/index_product.decorator +18 -0
  39. data/bin/rails +17 -0
  40. data/config/initializers/appends.rb +21 -0
  41. data/config/initializers/configuration.rb +17 -0
  42. data/config/locales/en.yml +8 -0
  43. data/lib/tasks/browse_option_tasks.rake +4 -0
  44. data/lib/workarea/browse_option/engine.rb +20 -0
  45. data/lib/workarea/browse_option/version.rb +5 -0
  46. data/lib/workarea/browse_option.rb +11 -0
  47. data/test/dummy/Rakefile +6 -0
  48. data/test/dummy/app/assets/config/manifest.js +4 -0
  49. data/test/dummy/app/assets/images/.keep +0 -0
  50. data/test/dummy/app/assets/javascripts/application.js +13 -0
  51. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  52. data/test/dummy/app/controllers/application_controller.rb +3 -0
  53. data/test/dummy/app/controllers/concerns/.keep +0 -0
  54. data/test/dummy/app/helpers/application_helper.rb +2 -0
  55. data/test/dummy/app/jobs/application_job.rb +2 -0
  56. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  57. data/test/dummy/app/models/concerns/.keep +0 -0
  58. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  59. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  60. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  61. data/test/dummy/bin/bundle +3 -0
  62. data/test/dummy/bin/rails +4 -0
  63. data/test/dummy/bin/rake +4 -0
  64. data/test/dummy/bin/setup +34 -0
  65. data/test/dummy/bin/update +29 -0
  66. data/test/dummy/config/application.rb +20 -0
  67. data/test/dummy/config/boot.rb +5 -0
  68. data/test/dummy/config/cable.yml +9 -0
  69. data/test/dummy/config/environment.rb +5 -0
  70. data/test/dummy/config/environments/development.rb +57 -0
  71. data/test/dummy/config/environments/production.rb +86 -0
  72. data/test/dummy/config/environments/test.rb +43 -0
  73. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  74. data/test/dummy/config/initializers/assets.rb +11 -0
  75. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  76. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  77. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  78. data/test/dummy/config/initializers/inflections.rb +16 -0
  79. data/test/dummy/config/initializers/mime_types.rb +4 -0
  80. data/test/dummy/config/initializers/new_framework_defaults.rb +18 -0
  81. data/test/dummy/config/initializers/session_store.rb +3 -0
  82. data/test/dummy/config/initializers/workarea.rb +5 -0
  83. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  84. data/test/dummy/config/locales/en.yml +23 -0
  85. data/test/dummy/config/puma.rb +47 -0
  86. data/test/dummy/config/routes.rb +6 -0
  87. data/test/dummy/config/secrets.yml +22 -0
  88. data/test/dummy/config/spring.rb +6 -0
  89. data/test/dummy/config.ru +5 -0
  90. data/test/dummy/db/seeds.rb +10 -0
  91. data/test/dummy/lib/assets/.keep +0 -0
  92. data/test/dummy/log/.keep +0 -0
  93. data/test/dummy/public/404.html +67 -0
  94. data/test/dummy/public/422.html +67 -0
  95. data/test/dummy/public/500.html +66 -0
  96. data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
  97. data/test/dummy/public/apple-touch-icon.png +0 -0
  98. data/test/dummy/public/favicon.ico +1 -0
  99. data/test/fixtures/files/large.jpg +0 -0
  100. data/test/fixtures/files/medium.jpg +0 -0
  101. data/test/integration/workarea/admin/browse_option_categorizations_integration_test.rb +47 -0
  102. data/test/integration/workarea/admin/browse_option_featured_products_integration_test.rb +45 -0
  103. data/test/integration/workarea/api/storefront/browse_option_product_integration_test.rb +74 -0
  104. data/test/models/workarea/catalog/browse_option_product_test.rb +20 -0
  105. data/test/models/workarea/featured_browse_option_products_test.rb +28 -0
  106. data/test/models/workarea/search/storefront/product_option_image_url_test.rb +19 -0
  107. data/test/models/workarea/search/storefront/product_option_test.rb +105 -0
  108. data/test/queries/workarea/browse_option_categorization_test.rb +20 -0
  109. data/test/queries/workarea/search/product_entries_test.decorator +19 -0
  110. data/test/queries/workarea/search/related_products_test.decorator +39 -0
  111. data/test/services/workarea/browse_option_ids_test.rb +63 -0
  112. data/test/system/workarea/admin/browse_option_featured_products_system_test.rb +57 -0
  113. data/test/system/workarea/admin/bulk_action_product_edit_browse_option_test.rb +54 -0
  114. data/test/system/workarea/storefront/browse_option_system_test.rb +110 -0
  115. data/test/test_helper.rb +10 -0
  116. data/test/view_models/workarea/admin/browse_option_product_view_model_test.rb +22 -0
  117. data/test/view_models/workarea/storefront/browse_option_product_view_model_test.rb +74 -0
  118. data/test/view_models/workarea/storefront/product_view_model/image_collection_test.rb +74 -0
  119. data/test/workers/workarea/browse_option_index_product_test.rb +37 -0
  120. data/test/workers/workarea/bulk_index_products_test.decorator +49 -0
  121. data/workarea-browse_option.gemspec +21 -0
  122. metadata +184 -0
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
@@ -0,0 +1 @@
1
+
Binary file
Binary file
@@ -0,0 +1,47 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class Admin::BrowseOptionCategorizationsIntegrationTest < IntegrationTest
5
+ include Admin::IntegrationTest
6
+
7
+ setup :setup_models
8
+
9
+ def test_creation
10
+ post admin.catalog_product_categorizations_path(@product),
11
+ params: { category_ids: [@category.id] }
12
+
13
+ assert_includes(@category.reload.product_ids, @id)
14
+ assert_equal(@product.browse_options.size, @category.products.size)
15
+ assert_redirected_to(admin.catalog_product_categorizations_path(@product))
16
+ end
17
+
18
+ def test_deletion
19
+ @category.update!(product_ids: [@id])
20
+ delete admin.catalog_product_categorization_path(@product, @category)
21
+ @category.reload
22
+
23
+ refute_includes(@category.product_ids, @id)
24
+ assert_empty(@category.products)
25
+ assert_response(:ok)
26
+ end
27
+
28
+ private
29
+
30
+ def setup_models
31
+ @product =
32
+ create_product(
33
+ id: 'PROD1',
34
+ name: 'Integration Product',
35
+ details: { 'Size' => %w(Medium Large) },
36
+ filters: { 'Size' => %w(Medium Large), 'Color' => 'Red' },
37
+ browse_option: 'size',
38
+ variants: [
39
+ { sku: 'SKU1', regular: 5.to_m, details: { 'Size' => 'Medium' } },
40
+ { sku: 'SKU2', regular: 5.to_m, details: { 'Size' => 'Large' } }
41
+ ]
42
+ )
43
+ @id = BrowseOptionIds.for(@product, @product.browse_options.first)
44
+ @category = Storefront::CategoryViewModel.wrap(create_category)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,45 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Admin
5
+ class BrowseOptionFeaturedProductsIntegrationTest < Workarea::IntegrationTest
6
+ include Admin::IntegrationTest
7
+
8
+ setup :product
9
+
10
+ def product
11
+ @product ||=
12
+ create_product(
13
+ id: 'PROD1',
14
+ name: 'Integration Product',
15
+ filters: { 'Size' => %w(Medium Large), 'Color' => 'Red' },
16
+ browse_option: 'size',
17
+ variants: [
18
+ { sku: 'SKU1', regular: 5.to_m, details: { 'Size' => 'Medium' } },
19
+ { sku: 'SKU2', regular: 5.to_m, details: { 'Size' => 'Large' } }
20
+ ]
21
+ )
22
+ end
23
+
24
+ def test_adding_a_product_that_browses_by_option
25
+ option_id = BrowseOptionIds.for(product, 'Medium')
26
+ category = create_category(product_ids: [])
27
+
28
+ post admin.add_featured_product_path(category.to_global_id),
29
+ params: { product_id: option_id }
30
+
31
+ assert_equal([option_id], category.reload.product_ids)
32
+ end
33
+
34
+ def test_removing_a_product
35
+ option_id = BrowseOptionIds.for(product, 'Medium')
36
+ category = create_category(product_ids: [option_id])
37
+
38
+ delete admin.remove_featured_product_path(category.to_global_id),
39
+ params: { product_id: option_id }
40
+
41
+ assert_equal([], category.reload.product_ids)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,74 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Api
5
+ module Storefront
6
+ class BrowseOptionProductIntegrationTest < Workarea::IntegrationTest
7
+ if Plugin.installed?('Workarea::Api::Storefront')
8
+ setup :product, :category, :index_product
9
+
10
+ def product
11
+ @product ||=
12
+ create_product(
13
+ id: 'PROD1',
14
+ name: 'Integration Product',
15
+ filters: { 'Size' => %w(Medium Large), 'Color' => 'Red' },
16
+ browse_option: 'size',
17
+ variants: [
18
+ { sku: 'SKU1', regular: 5.to_m, details: { 'Size' => 'Medium' } },
19
+ { sku: 'SKU2', regular: 5.to_m, details: { 'Size' => 'Large' } }
20
+ ]
21
+ )
22
+ end
23
+
24
+ def category
25
+ @category ||= begin
26
+ category = create_category(
27
+ product_ids: [product.id],
28
+ terms_facets: %w(Size Color)
29
+ )
30
+
31
+ first_level = create_taxon(name: 'First Level')
32
+ first_level.children.create!(navigable: category)
33
+
34
+ content = Content.for(category)
35
+ content.blocks.build(
36
+ area: :above_results,
37
+ type: :text,
38
+ data: { text: 'text' }
39
+ )
40
+
41
+ category
42
+ end
43
+ end
44
+
45
+ def index_product
46
+ Workarea::IndexProduct.perform(product)
47
+ end
48
+
49
+ def test_category_show
50
+ get storefront_api.category_path(category)
51
+ result = JSON.parse(response.body)
52
+
53
+ assert_equal(category.id.to_s, result['id'])
54
+
55
+ assert_equal(2, result['total_results'])
56
+ assert_equal(2, result['products'].count)
57
+
58
+ product_result = result['products'].first
59
+ assert_equal(product.browse_option, product_result['browse_option'])
60
+ assert_equal('Medium', product_result['current_browse_option'])
61
+ end
62
+
63
+ def test_product_show
64
+ get storefront_api.product_path(@product)
65
+ results = JSON.parse(response.body)
66
+ product_result = results['product']
67
+
68
+ assert_equal(product.browse_option, product_result['browse_option'])
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Catalog
5
+ class BrowseOptionProductTest < TestCase
6
+ def test_browse_options
7
+ product = Product.new(browse_option: 'color')
8
+ product.variants.build(details: { 'color' => 'red' })
9
+ product.variants.build(details: { 'color' => 'red' })
10
+ product.variants.build(details: { 'color' => 'green' })
11
+ product.variants.build(details: { 'color' => %w(blue violet) })
12
+ product.variants.build(details: { 'color' => '' })
13
+ product.variants.build(active: false, details: { 'color' => 'orange' })
14
+
15
+ assert_equal(6, product.variants.length)
16
+ assert_equal(%w(red green blue violet), product.browse_options)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class FeaturedBrowseOptionProductsTest < TestCase
5
+ class Foo
6
+ include FeaturedBrowseOptionProducts
7
+ attr_accessor :product_ids
8
+ end
9
+
10
+ def test_featured_product?
11
+ model = Foo.new
12
+ product = Catalog::Product.new
13
+
14
+ model.product_ids = [product.id]
15
+ assert(model.featured_product?(product.id))
16
+
17
+ model.product_ids = [BrowseOptionIds.build(product.id, 'blue')]
18
+ assert(model.featured_product?(product.id))
19
+ end
20
+
21
+ def test_unique_product_ids
22
+ model = Foo.new
23
+ model.product_ids = ['1245', BrowseOptionIds.build('2451', 'red')]
24
+
25
+ assert_equal(%w(1245 2451), model.unique_product_ids)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Search
5
+ class Storefront
6
+ class ProductOptionImageUrlTest < TestCase
7
+ def test_image
8
+ product = create_product
9
+ image = product.images.create!(option: 'red')
10
+ url = ProductOptionImageUrl.new(product, option: image.option)
11
+
12
+ assert_equal(image, url.send(:image))
13
+ refute_nil(url.path)
14
+ refute_nil(url.url)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,105 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Search
5
+ class Storefront
6
+ class ProductOptionTest < IntegrationTest
7
+ setup :set_product
8
+
9
+ def set_product
10
+ @product = create_product
11
+ end
12
+
13
+ def test_id_includes_the_first_browse_sku
14
+ @product.id = 'PROD'
15
+ search_doc = ProductOption.new(@product, value: 'The CraZY Value')
16
+ assert_includes(search_doc.id, 'PROD-the_crazy_value')
17
+ end
18
+
19
+ def test_variants_only_includes_variants_which_match_the_option
20
+ @product.variants.build(sku: 'SKU1', details: { color: 'red' })
21
+ @product.variants.build(sku: 'SKU2', details: { color: 'green' })
22
+ @product.variants.build(sku: 'SKU3', details: { color: 'green' })
23
+
24
+ search_doc = ProductOption.new(
25
+ @product,
26
+ option: 'color',
27
+ value: 'green'
28
+ )
29
+ assert_equal(2, search_doc.variants.length)
30
+ assert_equal('SKU2', search_doc.variants.first.sku)
31
+ assert_equal('SKU3', search_doc.variants.second.sku)
32
+ end
33
+
34
+ def test_primary_image
35
+ @product.variants.create!(sku: 'SKU1', details: { color: 'red' })
36
+ image = @product.images.create!(option: 'red')
37
+ product_option = ProductOption.new(@product, option: 'color', value: 'red')
38
+
39
+ assert_includes(product_option.primary_image, '/product_images')
40
+ assert_includes(product_option.primary_image, image.option)
41
+ assert_includes(product_option.primary_image, @product.slug)
42
+ end
43
+
44
+ def test_category_positions
45
+ @product.update(
46
+ browse_option: 'color',
47
+ variants: [{ sku: 'SKU3', details: { color: 'green' } }]
48
+ )
49
+ category = create_category(
50
+ product_ids: ['123', BrowseOptionIds.build(@product.id, 'green')]
51
+ )
52
+ search_doc = ProductOption.new(
53
+ @product,
54
+ option: 'color',
55
+ value: 'green'
56
+ )
57
+
58
+ assert_equal(
59
+ { category.id => 1 },
60
+ search_doc.category_positions
61
+ )
62
+ end
63
+
64
+ def test_facets
65
+ sizes = ["XS", "S", "M", "L", "XL"]
66
+ color = 'Lilac'
67
+
68
+ @product.update!(
69
+ browse_option: 'color',
70
+ filters: {
71
+ "size" => sizes,
72
+ "color" => ["Cotton Candy", "Cherry", "Lilac"]
73
+ },
74
+ variants: [
75
+ { sku: "248428849-2", details: { "size" => ["XS"], "color" => ["Cotton Candy"] } },
76
+ { sku: "294249838-2", details: { "size" => ["S"], "color" => ["Cotton Candy"] } },
77
+ { sku: "498401905-0", details: { "size" => ["M"], "color" => ["Cotton Candy"] } },
78
+ { sku: "578902813-6", details: { "size" => ["L"], "color" => ["Cotton Candy"] } },
79
+ { sku: "512627649-2", details: { "size" => ["XL"], "color" => ["Cotton Candy"] } },
80
+ { sku: "788914021-5", details: { "size" => ["XS"], "color" => ["Cherry"] } },
81
+ { sku: "921696744-7", details: { "size" => ["S"], "color" => ["Cherry"] } },
82
+ { sku: "898374652-1", details: { "size" => ["M"], "color" => ["Cherry"] } },
83
+ { sku: "526629545-7", details: { "size" => ["L"], "color" => ["Cherry"] } },
84
+ { sku: "606887371-4", details: { "size" => ["XL"], "color" => ["Cherry"] } },
85
+ { sku: "096342594-3", details: { "size" => ["XS"], "color" => ["Lilac"] } },
86
+ { sku: "896263254-3", details: { "size" => ["S"], "color" => ["Lilac"] } },
87
+ { sku: "746152723-1", details: { "size" => ["M"], "color" => ["Lilac"] } },
88
+ { sku: "384474791-5", details: { "size" => ["L"], "color" => ["Lilac"] } },
89
+ { sku: "629519307-2", details: { "size" => ["XL"], "color" => ["Lilac"] } }
90
+ ]
91
+ )
92
+
93
+ document = ProductOption.new(
94
+ @product,
95
+ option: 'color',
96
+ value: color
97
+ ).as_document
98
+
99
+ assert_equal(sizes, document[:facets]['size'])
100
+ assert_equal([color], document[:facets]['color'])
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class BrowseOptionCategorizationTest < TestCase
5
+ def test_manual
6
+ product = create_product(
7
+ browse_option: 'color',
8
+ variants: [{ sku: 'SKU', details: { 'color' => 'red' } }]
9
+ )
10
+ category_one = create_category(product_ids: [product.id])
11
+ category_two = create_category(
12
+ product_ids: [BrowseOptionIds.build(product.id, 'red')]
13
+ )
14
+
15
+ categorization = Categorization.new(product)
16
+ assert(categorization.manual.include?(category_one.id))
17
+ assert(categorization.manual.include?(category_two.id))
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ decorate Search::ProductEntriesTest, with: :browse_option do
5
+ def test_browse_option_entries
6
+ products = Array.new(2) { create_product }
7
+
8
+ products.first.update_attributes!(
9
+ browse_option: 'color',
10
+ variants: [
11
+ { sku: 'SKU1', details: { color: ['Red'] } },
12
+ { sku: 'SKU2', details: { color: ['Blue'] } }
13
+ ]
14
+ )
15
+
16
+ assert_equal(3, Search::ProductEntries.new(products).entries.size)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ decorate Search::RelatedProductsTest, with: :browse_option do
5
+ def test_browse_option_search_product_ids
6
+ products = Array.new(2) { create_product }
7
+ browse_option_product = products.first
8
+ browse_option_product.update_attributes!(
9
+ browse_option: 'color',
10
+ variants: [
11
+ { sku: 'SKU1', details: { color: ['Red'] } },
12
+ { sku: 'SKU2', details: { color: ['Blue'] } }
13
+ ]
14
+ )
15
+ query = Search::RelatedProducts.new(product_ids: products.map(&:id))
16
+
17
+ assert_includes(query.search_product_ids, "product-#{products.second.id}")
18
+ assert_includes(query.search_product_ids, "product-#{browse_option_product.id}-red")
19
+ assert_includes(query.search_product_ids, "product-#{browse_option_product.id}-blue")
20
+ end
21
+
22
+ def test_browse_option_exclude_search_product_ids
23
+ products = Array.new(2) { create_product }
24
+ products.first.update_attributes!(
25
+ browse_option: 'color',
26
+ variants: [
27
+ { sku: 'SKU1', details: { color: ['Red'] } },
28
+ { sku: 'SKU2', details: { color: ['Blue'] } }
29
+ ]
30
+ )
31
+ query = Search::RelatedProducts.new(
32
+ product_ids: products.map(&:id),
33
+ exclude_product_ids: products.last.id
34
+ )
35
+
36
+ assert_includes(query.exclude_search_product_ids, "product-#{products.last.id}")
37
+ end
38
+ end
39
+ end