workarea-swatches 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- 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 +21 -0
- data/CHANGELOG.md +121 -0
- data/CODE_OF_CONDUCT.md +3 -0
- data/CONTRIBUTING.md +3 -0
- data/Gemfile +17 -0
- data/LICENSE +52 -0
- data/README.md +40 -0
- data/Rakefile +60 -0
- data/app/assets/javascripts/workarea/storefront/swatches/modules/product_summary_swatches.js +63 -0
- data/app/assets/stylesheets/workarea/storefront/swatches/components/_option_button.scss +17 -0
- data/app/assets/stylesheets/workarea/storefront/swatches/components/_swatch_facet.scss +25 -0
- data/app/assets/stylesheets/workarea/storefront/swatches/components/_swatch_options.scss +54 -0
- data/app/controllers/workarea/admin/catalog_product_swatches_controller.rb +47 -0
- data/app/controllers/workarea/admin/catalog_swatches_controller.rb +48 -0
- data/app/controllers/workarea/storefront/products_controller.decorator +12 -0
- data/app/helpers/workarea/storefront/swatches_helper.rb +84 -0
- data/app/models/workarea/catalog/product.decorator +7 -0
- data/app/models/workarea/catalog/product_swatch.rb +10 -0
- data/app/models/workarea/catalog/swatch.rb +37 -0
- data/app/models/workarea/search/settings.decorator +8 -0
- data/app/queries/workarea/search/category_browse.decorator +7 -0
- data/app/queries/workarea/search/product_search.decorator +7 -0
- data/app/queries/workarea/search/swatched_facets.rb +19 -0
- data/app/queries/workarea/search/swatches_facet.rb +13 -0
- data/app/seeds/workarea/swatches_seeds.rb +37 -0
- data/app/view_models/workarea/storefront/product_templates/swatches_view_model.rb +57 -0
- data/app/views/workarea/admin/activities/_catalog_product_swatch_create.html.haml +10 -0
- data/app/views/workarea/admin/activities/_catalog_product_swatch_destroy.html.haml +10 -0
- data/app/views/workarea/admin/activities/_catalog_swatch_create.html.haml +12 -0
- data/app/views/workarea/admin/activities/_catalog_swatch_destroy.html.haml +10 -0
- data/app/views/workarea/admin/catalog_product_swatches/edit.html.haml +52 -0
- data/app/views/workarea/admin/catalog_product_swatches/index.html.haml +65 -0
- data/app/views/workarea/admin/catalog_products/_swatches_card.html.haml +27 -0
- data/app/views/workarea/admin/catalog_swatches/_primary_navigation.html.haml +1 -0
- data/app/views/workarea/admin/catalog_swatches/index.html.haml +78 -0
- data/app/views/workarea/api/storefront/facets/_swatches.json.jbuilder +17 -0
- data/app/views/workarea/storefront/facets/_swatches.html.haml +14 -0
- data/app/views/workarea/storefront/products/_swatch_summary.html.haml +17 -0
- data/app/views/workarea/storefront/products/templates/_swatches.html.haml +79 -0
- data/bin/rails +19 -0
- data/config/initializers/dragonfly.rb +11 -0
- data/config/initializers/workarea.rb +40 -0
- data/config/locales/en.yml +52 -0
- data/config/routes.rb +15 -0
- data/lib/tasks/swatches_tasks.rake +4 -0
- data/lib/workarea/swatches.rb +11 -0
- data/lib/workarea/swatches/engine.rb +12 -0
- data/lib/workarea/swatches/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/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/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/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 +30 -0
- data/test/dummy/bin/update +26 -0
- data/test/dummy/bin/yarn +11 -0
- data/test/dummy/config.ru +5 -0
- data/test/dummy/config/application.rb +30 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/cable.yml +10 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +51 -0
- data/test/dummy/config/environments/production.rb +88 -0
- data/test/dummy/config/environments/test.rb +44 -0
- data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/test/dummy/config/initializers/assets.rb +14 -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/workarea.rb +5 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
- data/test/dummy/config/locales/en.yml +33 -0
- data/test/dummy/config/puma.rb +56 -0
- data/test/dummy/config/routes.rb +5 -0
- data/test/dummy/config/secrets.yml +32 -0
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/db/seeds.rb +2 -0
- data/test/dummy/log/.keep +0 -0
- data/test/factories/workarea/swatches.rb +14 -0
- data/test/integration/workarea/admin/product_swatches_integration_test.rb +43 -0
- data/test/integration/workarea/admin/swatches_integration_test.rb +37 -0
- data/test/integration/workarea/storefront/swatches_integration_test.rb +72 -0
- data/test/system/workarea/admin/swatches_system_test.rb +58 -0
- data/test/system/workarea/storefront/browse_swatches_system_test.rb +50 -0
- data/test/system/workarea/storefront/swatches_system_test.rb +101 -0
- data/test/teaspoon_env.rb +6 -0
- data/test/test_helper.rb +10 -0
- data/test/view_models/workarea/storefront/product_templates/swatches_view_model_test.rb +74 -0
- data/workarea-swatches.gemspec +19 -0
- metadata +147 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Admin
|
5
|
+
class SwatchesIntegrationTest < Workarea::IntegrationTest
|
6
|
+
include Admin::IntegrationTest
|
7
|
+
|
8
|
+
def test_create
|
9
|
+
post admin.catalog_swatches_path,
|
10
|
+
params: { swatch: { name: 'Red', hex: '000000' } }
|
11
|
+
|
12
|
+
assert_equal(1, Catalog::Swatch.count)
|
13
|
+
swatch = Catalog::Swatch.find('red')
|
14
|
+
assert_equal('Red', swatch.name)
|
15
|
+
assert_equal('#000000', swatch.hex)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_update
|
19
|
+
swatch = create_swatch(name: 'Red', hex: '000000')
|
20
|
+
|
21
|
+
patch admin.catalog_swatch_path(swatch),
|
22
|
+
params: { swatch: { name: 'Redder', hex: '111111' } }
|
23
|
+
|
24
|
+
assert_equal(1, Catalog::Swatch.count)
|
25
|
+
swatch = Catalog::Swatch.find('red')
|
26
|
+
assert_equal('Redder', swatch.name)
|
27
|
+
assert_equal('#111111', swatch.hex)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_destroy
|
31
|
+
swatch = create_swatch(name: 'Red', hex: '000000')
|
32
|
+
delete admin.catalog_swatch_path(swatch)
|
33
|
+
assert_equal(0, Catalog::Swatch.count)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Storefront
|
5
|
+
class SwatchesIntegrationTest < Workarea::IntegrationTest
|
6
|
+
setup :set_products
|
7
|
+
setup :set_swatches
|
8
|
+
|
9
|
+
def set_products
|
10
|
+
@products = [
|
11
|
+
create_product(
|
12
|
+
name: 'Test Product 1',
|
13
|
+
filters: { 'Color' => %w(Red Blue) }
|
14
|
+
),
|
15
|
+
create_product(
|
16
|
+
name: 'Test Product 2',
|
17
|
+
filters: { 'Color' => %w(Red Green) }
|
18
|
+
)
|
19
|
+
]
|
20
|
+
end
|
21
|
+
|
22
|
+
def set_swatches
|
23
|
+
create_swatch(name: 'Red', hex: 'ff0000')
|
24
|
+
create_swatch(name: 'Blue', hex: '0000ff')
|
25
|
+
create_swatch(name: 'Green', image: product_image_file)
|
26
|
+
|
27
|
+
Search::Settings.current.update_attributes!(swatch_facets: ['Color'])
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_showing_swatch_filters_on_search
|
31
|
+
get storefront.search_path(q: 'test')
|
32
|
+
assert_select('.swatch-facet--red', 2)
|
33
|
+
assert_select('.swatch-facet--blue', 2)
|
34
|
+
assert_select('.swatch-facet--green', 2)
|
35
|
+
assert_includes(response.body, '#ff0000')
|
36
|
+
assert_includes(response.body, '#0000ff')
|
37
|
+
|
38
|
+
get storefront.search_path(q: 'test', color: ['Red'])
|
39
|
+
assert_select('.swatch-facet--red', 2)
|
40
|
+
assert_select('.swatch-facet--blue', 2)
|
41
|
+
assert_select('.swatch-facet--green', 2)
|
42
|
+
assert_includes(response.body, '#ff0000')
|
43
|
+
assert_includes(response.body, '#0000ff')
|
44
|
+
|
45
|
+
get storefront.search_path(q: 'test', color: ['Blue'])
|
46
|
+
assert_select('.swatch-facet--red', 2)
|
47
|
+
assert_select('.swatch-facet--blue', 2)
|
48
|
+
assert_select('.swatch-facet--green', 2)
|
49
|
+
assert_includes(response.body, '#ff0000')
|
50
|
+
assert_includes(response.body, '#0000ff')
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_showing_product_with_no_swatches_present_on_browse_pages
|
54
|
+
product = create_product(
|
55
|
+
template: 'swatches',
|
56
|
+
variants: [
|
57
|
+
{
|
58
|
+
sku: 'SKU1',
|
59
|
+
details: { size: 'Small' }
|
60
|
+
},
|
61
|
+
]
|
62
|
+
)
|
63
|
+
|
64
|
+
category = create_category(product_ids: [product.id])
|
65
|
+
|
66
|
+
get storefront.category_path(category)
|
67
|
+
|
68
|
+
assert_includes(response.body, 'Test Product')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Admin
|
5
|
+
class SwatchesSystemTest < SystemTest
|
6
|
+
include Admin::IntegrationTest
|
7
|
+
|
8
|
+
def test_managing
|
9
|
+
visit admin.catalog_swatches_path
|
10
|
+
assert(
|
11
|
+
page.has_content?(
|
12
|
+
t('workarea.admin.catalog_swatches.index.no_swatches')
|
13
|
+
)
|
14
|
+
)
|
15
|
+
|
16
|
+
fill_in 'swatch[name]', with: 'Red'
|
17
|
+
fill_in 'swatch[hex]', with: '000000'
|
18
|
+
click_button 'save_new_swatch'
|
19
|
+
|
20
|
+
assert(page.has_content?('Success'))
|
21
|
+
assert(page.has_content?('Red'))
|
22
|
+
|
23
|
+
click_button 'remove_swatch'
|
24
|
+
assert(page.has_content?('Success'))
|
25
|
+
assert(page.has_no_content?('Red'))
|
26
|
+
assert(
|
27
|
+
page.has_content?(
|
28
|
+
t('workarea.admin.catalog_swatches.index.no_swatches')
|
29
|
+
)
|
30
|
+
)
|
31
|
+
|
32
|
+
fill_in 'settings[swatch_facets_list]', with: 'Color, Material'
|
33
|
+
click_button 'save_settings'
|
34
|
+
assert_current_path(admin.catalog_swatches_path)
|
35
|
+
assert(page.has_content?('Success'))
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_managing_on_products
|
39
|
+
product = create_product
|
40
|
+
visit admin.catalog_product_swatches_path(product)
|
41
|
+
|
42
|
+
fill_in 'swatch[name]', with: 'Blue'
|
43
|
+
attach_file 'swatch[image]', product_image_file_path
|
44
|
+
click_button 'save_new_swatch'
|
45
|
+
|
46
|
+
assert_equal(admin.catalog_product_swatches_path(product), current_path)
|
47
|
+
assert(page.has_content?('Success'))
|
48
|
+
assert(page.has_content?('Blue'))
|
49
|
+
|
50
|
+
click_button 'remove_swatch'
|
51
|
+
|
52
|
+
assert_equal(admin.catalog_product_swatches_path(product), current_path)
|
53
|
+
assert(page.has_content?('Success'))
|
54
|
+
assert(page.has_no_content?('Blue'))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Storefront
|
5
|
+
class BrowseSwatchesSystemTest < Workarea::SystemTest
|
6
|
+
def test_swatches_on_browse_pages
|
7
|
+
create_swatch(name: 'Red', image: product_image_file)
|
8
|
+
create_swatch(name: 'Blue', hex: '0000ff')
|
9
|
+
|
10
|
+
product = create_product(
|
11
|
+
template: 'swatches',
|
12
|
+
variants: [
|
13
|
+
{
|
14
|
+
sku: 'SKU1',
|
15
|
+
details: { color: 'Red', size: 'Small', material: 'Cotton' }
|
16
|
+
},
|
17
|
+
{
|
18
|
+
sku: 'SKU2',
|
19
|
+
details: { color: 'Blue', size: 'Small', material: 'Suede' }
|
20
|
+
}
|
21
|
+
]
|
22
|
+
)
|
23
|
+
|
24
|
+
category = create_category(product_ids: [product.id])
|
25
|
+
|
26
|
+
visit storefront.category_path(category)
|
27
|
+
|
28
|
+
assert_selector('.swatch-options__swatch-button-image--red')
|
29
|
+
assert_selector('.swatch-options__swatch-button--blue')
|
30
|
+
|
31
|
+
find('.swatch-options__swatch-button-image--red').click
|
32
|
+
wait_for_xhr
|
33
|
+
|
34
|
+
assert_selector(
|
35
|
+
'.swatch-options__swatch--selected .swatch-options__swatch-button-image--red'
|
36
|
+
)
|
37
|
+
|
38
|
+
find('.swatch-options__swatch-button--blue').click
|
39
|
+
wait_for_xhr
|
40
|
+
|
41
|
+
assert_selector(
|
42
|
+
'.swatch-options__swatch--selected .swatch-options__swatch-button--blue'
|
43
|
+
)
|
44
|
+
|
45
|
+
click_link product.name, match: :first
|
46
|
+
assert_current_path(storefront.product_path(product, color: 'Blue'))
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Storefront
|
5
|
+
class SwatchesSystemTest < Workarea::SystemTest
|
6
|
+
def test_product_template
|
7
|
+
create_swatch(name: 'Red', image: product_image_file)
|
8
|
+
create_swatch(name: 'Blue', hex: '0000ff')
|
9
|
+
product = create_product(
|
10
|
+
template: 'swatches',
|
11
|
+
variants: [
|
12
|
+
{
|
13
|
+
sku: 'SKU1',
|
14
|
+
details: { color: 'Red', size: 'Large', material: 'Cotton' }
|
15
|
+
},
|
16
|
+
{
|
17
|
+
sku: 'SKU2',
|
18
|
+
details: { color: 'Red', size: 'Small', material: 'Cotton' }
|
19
|
+
},
|
20
|
+
{
|
21
|
+
sku: 'SKU3',
|
22
|
+
details: { color: 'Blue', size: 'Small', material: 'Suede' }
|
23
|
+
}
|
24
|
+
]
|
25
|
+
)
|
26
|
+
|
27
|
+
visit storefront.product_path(product)
|
28
|
+
|
29
|
+
within '.product-details' do
|
30
|
+
assert(page.has_selector?('.option-button__image--red'))
|
31
|
+
assert(page.has_selector?('.option-button__swatch--blue'))
|
32
|
+
assert(page.has_selector?('[style="background-color: #0000ff;"]'))
|
33
|
+
assert(page.has_content?('Large'))
|
34
|
+
assert(page.has_content?('Small'))
|
35
|
+
assert(page.has_content?('Cotton'))
|
36
|
+
assert(page.has_content?('Suede'))
|
37
|
+
|
38
|
+
find('.option-button__image--red').click
|
39
|
+
assert(page.has_selector?('.option-button__image--red'))
|
40
|
+
assert(page.has_selector?('.option-button__swatch--blue'))
|
41
|
+
assert(page.has_selector?('[style="background-color: #0000ff;"]'))
|
42
|
+
assert(page.has_content?('Large'))
|
43
|
+
assert(page.has_content?('Small'))
|
44
|
+
assert(page.has_content?('Cotton'))
|
45
|
+
assert(page.has_no_content?('Suede'))
|
46
|
+
|
47
|
+
click_link 'Small'
|
48
|
+
assert(page.has_selector?('.option-button__image--red'))
|
49
|
+
assert(page.has_selector?('.option-button__swatch--blue'))
|
50
|
+
assert(page.has_selector?('[style="background-color: #0000ff;"]'))
|
51
|
+
assert(page.has_content?('Large'))
|
52
|
+
assert(page.has_content?('Small'))
|
53
|
+
assert(page.has_content?('Cotton'))
|
54
|
+
assert(page.has_no_content?('Suede'))
|
55
|
+
|
56
|
+
find('.option-button__swatch--blue').click
|
57
|
+
assert(page.has_selector?('.option-button__image--red'))
|
58
|
+
assert(page.has_selector?('.option-button__swatch--blue'))
|
59
|
+
assert(page.has_selector?('[style="background-color: #0000ff;"]'))
|
60
|
+
assert(page.has_no_content?('Large'))
|
61
|
+
assert(page.has_content?('Small'))
|
62
|
+
assert(page.has_no_content?('Cotton'))
|
63
|
+
assert(page.has_content?('Suede'))
|
64
|
+
|
65
|
+
find('.option-button__swatch--blue').click # to unselect
|
66
|
+
assert(page.has_selector?('.option-button__image--red'))
|
67
|
+
assert(page.has_selector?('.option-button__swatch--blue'))
|
68
|
+
assert(page.has_selector?('[style="background-color: #0000ff;"]'))
|
69
|
+
assert(page.has_content?('Large'))
|
70
|
+
assert(page.has_content?('Small'))
|
71
|
+
assert(page.has_content?('Cotton'))
|
72
|
+
assert(page.has_content?('Suede'))
|
73
|
+
|
74
|
+
find('.option-button__swatch--blue').click
|
75
|
+
click_link t('workarea.storefront.products.clear_selections')
|
76
|
+
assert(page.has_selector?('.option-button__image--red'))
|
77
|
+
assert(page.has_selector?('.option-button__swatch--blue'))
|
78
|
+
assert(page.has_selector?('[style="background-color: #0000ff;"]'))
|
79
|
+
assert(page.has_content?('Large'))
|
80
|
+
assert(page.has_content?('Small'))
|
81
|
+
assert(page.has_content?('Cotton'))
|
82
|
+
assert(page.has_content?('Suede'))
|
83
|
+
end
|
84
|
+
|
85
|
+
visit storefront.product_path(product, sku: 'SKU1')
|
86
|
+
within '.product-details' do
|
87
|
+
assert(page.has_selector?('.option-button__image--red'))
|
88
|
+
assert(page.has_no_selector?('.option-button__swatch--blue'))
|
89
|
+
assert(page.has_no_selector?('[style="background-color: #0000ff;"]'))
|
90
|
+
assert(page.has_content?('Large'))
|
91
|
+
assert(page.has_content?('Small'))
|
92
|
+
assert(page.has_content?('Cotton'))
|
93
|
+
assert(page.has_no_content?('Suede'))
|
94
|
+
assert(page.has_selector?('.option-button--red.option-button--active'))
|
95
|
+
assert(page.has_selector?('.option-button--large.option-button--active'))
|
96
|
+
assert(page.has_selector?('.option-button--cotton.option-button--active'))
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
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,74 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Storefront
|
5
|
+
module ProductTemplates
|
6
|
+
class SwatchesViewModelTest < TestCase
|
7
|
+
def test_groups_images_by_options
|
8
|
+
product = create_product(
|
9
|
+
images: [
|
10
|
+
{ image: product_image_file, option: 'blue' },
|
11
|
+
{ image: product_image_file, option: 'red' },
|
12
|
+
{ image: product_image_file, option: 'Blue' },
|
13
|
+
{ image: product_image_file, option: nil }
|
14
|
+
]
|
15
|
+
)
|
16
|
+
|
17
|
+
view_model = SwatchesViewModel.wrap(product)
|
18
|
+
assert_equal(2, view_model.images_by_option.size)
|
19
|
+
assert_equal(2, view_model.images_by_option['blue'].size)
|
20
|
+
assert_equal(1, view_model.images_by_option['red'].size)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_swatches_by_options
|
24
|
+
product = create_product(swatches: [{ name: 'Blue' }, { name: 'Red' }])
|
25
|
+
blue = create_swatch(name: 'Blue')
|
26
|
+
green = create_swatch(name: 'Green')
|
27
|
+
|
28
|
+
view_model = SwatchesViewModel.wrap(product)
|
29
|
+
assert_equal(3, view_model.swatches_by_option.size)
|
30
|
+
assert_equal(green, view_model.swatches_by_option['green'])
|
31
|
+
assert_equal(
|
32
|
+
product.swatches.find('blue'),
|
33
|
+
view_model.swatches_by_option['blue']
|
34
|
+
)
|
35
|
+
assert_equal(
|
36
|
+
product.swatches.find('red'),
|
37
|
+
view_model.swatches_by_option['red']
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_browse_link_options
|
42
|
+
product = create_product(
|
43
|
+
variants: [{ sku: 'SKU', details: { 'Color' => %w(red) } }]
|
44
|
+
)
|
45
|
+
|
46
|
+
view_model = SwatchesViewModel.wrap(product, color: 'red')
|
47
|
+
assert_equal('red', view_model.browse_link_options['color'])
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_browse_swatch_option
|
51
|
+
product = create_product(
|
52
|
+
variants: [
|
53
|
+
{ sku: 'SKU', details: { 'Color' => %w(red), 'Size' => %w(large) } },
|
54
|
+
{ sku: 'SKU', details: { 'Color' => %w(blue), 'Size' => %w(small) } }
|
55
|
+
]
|
56
|
+
)
|
57
|
+
|
58
|
+
Workarea.with_config do |config|
|
59
|
+
config.option_selections_sort = ->(p, o) { o.sort_by(&:name) }
|
60
|
+
config.browse_swatch_option = ->(product, options) { options.first }
|
61
|
+
|
62
|
+
view_model = SwatchesViewModel.wrap(product)
|
63
|
+
assert_equal('color', view_model.browse_swatch_option.slug)
|
64
|
+
|
65
|
+
config.browse_swatch_option = ->(product, options) { options.last }
|
66
|
+
|
67
|
+
view_model = SwatchesViewModel.wrap(product)
|
68
|
+
assert_equal('size', view_model.browse_swatch_option.slug)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
$:.push File.expand_path('../lib', __FILE__)
|
2
|
+
|
3
|
+
# Maintain your gem's version:
|
4
|
+
require 'workarea/swatches/version'
|
5
|
+
|
6
|
+
# Describe your gem and declare its dependencies:
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = 'workarea-swatches'
|
9
|
+
s.version = Workarea::Swatches::VERSION
|
10
|
+
s.authors = ['Ben Crouse']
|
11
|
+
s.email = ['bcrouse@weblinc.com']
|
12
|
+
s.homepage = 'https://github.com/workarea-commerce/workarea-swatches'
|
13
|
+
s.summary = 'Adds swatching to the Workarea platform'
|
14
|
+
s.description = 'Provides global and custom swatches for products'
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
|
18
|
+
s.license = 'Business Software License'
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: workarea-swatches
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Crouse
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-08-21 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Provides global and custom swatches for products
|
14
|
+
email:
|
15
|
+
- bcrouse@weblinc.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".editorconfig"
|
21
|
+
- ".github/ISSUE_TEMPLATE/bug_report.md"
|
22
|
+
- ".github/ISSUE_TEMPLATE/documentation-request.md"
|
23
|
+
- ".github/ISSUE_TEMPLATE/feature_request.md"
|
24
|
+
- ".gitignore"
|
25
|
+
- CHANGELOG.md
|
26
|
+
- CODE_OF_CONDUCT.md
|
27
|
+
- CONTRIBUTING.md
|
28
|
+
- Gemfile
|
29
|
+
- LICENSE
|
30
|
+
- README.md
|
31
|
+
- Rakefile
|
32
|
+
- app/assets/javascripts/workarea/storefront/swatches/modules/product_summary_swatches.js
|
33
|
+
- app/assets/stylesheets/workarea/storefront/swatches/components/_option_button.scss
|
34
|
+
- app/assets/stylesheets/workarea/storefront/swatches/components/_swatch_facet.scss
|
35
|
+
- app/assets/stylesheets/workarea/storefront/swatches/components/_swatch_options.scss
|
36
|
+
- app/controllers/workarea/admin/catalog_product_swatches_controller.rb
|
37
|
+
- app/controllers/workarea/admin/catalog_swatches_controller.rb
|
38
|
+
- app/controllers/workarea/storefront/products_controller.decorator
|
39
|
+
- app/helpers/workarea/storefront/swatches_helper.rb
|
40
|
+
- app/models/workarea/catalog/product.decorator
|
41
|
+
- app/models/workarea/catalog/product_swatch.rb
|
42
|
+
- app/models/workarea/catalog/swatch.rb
|
43
|
+
- app/models/workarea/search/settings.decorator
|
44
|
+
- app/queries/workarea/search/category_browse.decorator
|
45
|
+
- app/queries/workarea/search/product_search.decorator
|
46
|
+
- app/queries/workarea/search/swatched_facets.rb
|
47
|
+
- app/queries/workarea/search/swatches_facet.rb
|
48
|
+
- app/seeds/workarea/swatches_seeds.rb
|
49
|
+
- app/view_models/workarea/storefront/product_templates/swatches_view_model.rb
|
50
|
+
- app/views/workarea/admin/activities/_catalog_product_swatch_create.html.haml
|
51
|
+
- app/views/workarea/admin/activities/_catalog_product_swatch_destroy.html.haml
|
52
|
+
- app/views/workarea/admin/activities/_catalog_swatch_create.html.haml
|
53
|
+
- app/views/workarea/admin/activities/_catalog_swatch_destroy.html.haml
|
54
|
+
- app/views/workarea/admin/catalog_product_swatches/edit.html.haml
|
55
|
+
- app/views/workarea/admin/catalog_product_swatches/index.html.haml
|
56
|
+
- app/views/workarea/admin/catalog_products/_swatches_card.html.haml
|
57
|
+
- app/views/workarea/admin/catalog_swatches/_primary_navigation.html.haml
|
58
|
+
- app/views/workarea/admin/catalog_swatches/index.html.haml
|
59
|
+
- app/views/workarea/api/storefront/facets/_swatches.json.jbuilder
|
60
|
+
- app/views/workarea/storefront/facets/_swatches.html.haml
|
61
|
+
- app/views/workarea/storefront/products/_swatch_summary.html.haml
|
62
|
+
- app/views/workarea/storefront/products/templates/_swatches.html.haml
|
63
|
+
- bin/rails
|
64
|
+
- config/initializers/dragonfly.rb
|
65
|
+
- config/initializers/workarea.rb
|
66
|
+
- config/locales/en.yml
|
67
|
+
- config/routes.rb
|
68
|
+
- lib/tasks/swatches_tasks.rake
|
69
|
+
- lib/workarea/swatches.rb
|
70
|
+
- lib/workarea/swatches/engine.rb
|
71
|
+
- lib/workarea/swatches/version.rb
|
72
|
+
- test/dummy/Rakefile
|
73
|
+
- test/dummy/app/assets/config/manifest.js
|
74
|
+
- test/dummy/app/assets/javascripts/application.js
|
75
|
+
- test/dummy/app/assets/stylesheets/application.css
|
76
|
+
- test/dummy/app/controllers/application_controller.rb
|
77
|
+
- test/dummy/app/helpers/application_helper.rb
|
78
|
+
- test/dummy/app/jobs/application_job.rb
|
79
|
+
- test/dummy/app/mailers/application_mailer.rb
|
80
|
+
- test/dummy/app/views/layouts/application.html.erb
|
81
|
+
- test/dummy/app/views/layouts/mailer.html.erb
|
82
|
+
- test/dummy/app/views/layouts/mailer.text.erb
|
83
|
+
- test/dummy/bin/bundle
|
84
|
+
- test/dummy/bin/rails
|
85
|
+
- test/dummy/bin/rake
|
86
|
+
- test/dummy/bin/setup
|
87
|
+
- test/dummy/bin/update
|
88
|
+
- test/dummy/bin/yarn
|
89
|
+
- test/dummy/config.ru
|
90
|
+
- test/dummy/config/application.rb
|
91
|
+
- test/dummy/config/boot.rb
|
92
|
+
- test/dummy/config/cable.yml
|
93
|
+
- test/dummy/config/environment.rb
|
94
|
+
- test/dummy/config/environments/development.rb
|
95
|
+
- test/dummy/config/environments/production.rb
|
96
|
+
- test/dummy/config/environments/test.rb
|
97
|
+
- test/dummy/config/initializers/application_controller_renderer.rb
|
98
|
+
- test/dummy/config/initializers/assets.rb
|
99
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
100
|
+
- test/dummy/config/initializers/cookies_serializer.rb
|
101
|
+
- test/dummy/config/initializers/filter_parameter_logging.rb
|
102
|
+
- test/dummy/config/initializers/inflections.rb
|
103
|
+
- test/dummy/config/initializers/mime_types.rb
|
104
|
+
- test/dummy/config/initializers/workarea.rb
|
105
|
+
- test/dummy/config/initializers/wrap_parameters.rb
|
106
|
+
- test/dummy/config/locales/en.yml
|
107
|
+
- test/dummy/config/puma.rb
|
108
|
+
- test/dummy/config/routes.rb
|
109
|
+
- test/dummy/config/secrets.yml
|
110
|
+
- test/dummy/config/spring.rb
|
111
|
+
- test/dummy/db/seeds.rb
|
112
|
+
- test/dummy/log/.keep
|
113
|
+
- test/factories/workarea/swatches.rb
|
114
|
+
- test/integration/workarea/admin/product_swatches_integration_test.rb
|
115
|
+
- test/integration/workarea/admin/swatches_integration_test.rb
|
116
|
+
- test/integration/workarea/storefront/swatches_integration_test.rb
|
117
|
+
- test/system/workarea/admin/swatches_system_test.rb
|
118
|
+
- test/system/workarea/storefront/browse_swatches_system_test.rb
|
119
|
+
- test/system/workarea/storefront/swatches_system_test.rb
|
120
|
+
- test/teaspoon_env.rb
|
121
|
+
- test/test_helper.rb
|
122
|
+
- test/view_models/workarea/storefront/product_templates/swatches_view_model_test.rb
|
123
|
+
- workarea-swatches.gemspec
|
124
|
+
homepage: https://github.com/workarea-commerce/workarea-swatches
|
125
|
+
licenses:
|
126
|
+
- Business Software License
|
127
|
+
metadata: {}
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubygems_version: 3.0.4
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: Adds swatching to the Workarea platform
|
147
|
+
test_files: []
|