Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Adjust specs, refactor js and views

Przemek Kosakowskif905c6171ff6
diff --git a/backend/app/assets/javascripts/spree/backend/option_type_autocomplete.js b/backend/app/assets/javascripts/spree/backend/option_type_autocomplete.js
index 88b6ecf5da..d6163d1e7d 100644
--- a/backend/app/assets/javascripts/spree/backend/option_type_autocomplete.js
+++ b/backend/app/assets/javascripts/spree/backend/option_type_autocomplete.js
@@ -1,43 +1,40 @@
-$(document).ready(function () {
'use strict'
+ function set_option_type_select(selector) {
+ function formatOptionTypeResult (optionType) {
+ return optionType.name
+ }
- function formatOptionType (optionType) {
- return Select2.util.escapeMarkup(optionType.presentation + ' (' + optionType.name + ')')
- }
+ if ($(selector).length > 0) {
+ $(selector).select2({
+ minimumInputLength: 3,
+ multiple: true,
+ ajax: {
+ url: Spree.routes.option_types_api,
+ datatype: 'json',
+ data: function (params) {
+ var query = {
+ q: {
+ name_cont: params.term
+ },
+ token: Spree.api_key
+ }
- if ($('#product_option_type_ids').length > 0) {
- $('#product_option_type_ids').select2({
- placeholder: Spree.translations.option_type_placeholder,
- multiple: true,
- initSelection: function (element, callback) {
- var url = Spree.url(Spree.routes.option_types_api, {
- ids: element.val(),
- token: Spree.api_key
- })
- return $.getJSON(url, null, function (data) {
- return callback(data)
- })
- },
- ajax: {
- url: Spree.routes.option_types_api,
- quietMillis: 200,
- datatype: 'json',
- data: function (term) {
- return {
- q: {
- name_cont: term
- },
- token: Spree.api_key
+ return query
+ },
+ processResults: function (data) {
+ return {
+ results: data
+ }
}
},
- results: function (data) {
- return {
- results: data
- }
+ templateResult: formatOptionTypeResult,
+ templateSelection: function (optionType) {
+ return optionType.text
}
- },
- formatResult: formatOptionType,
- formatSelection: formatOptionType
- })
+ })
+ }
}
-})
+
+ $(document).ready(function () {
+ set_option_type_select('#product_option_type_ids')
+ })
diff --git a/backend/app/assets/javascripts/spree/backend/option_value_picker.js b/backend/app/assets/javascripts/spree/backend/option_value_picker.js
index ea13071bdb..abca5fa877 100644
--- a/backend/app/assets/javascripts/spree/backend/option_value_picker.js
+++ b/backend/app/assets/javascripts/spree/backend/option_value_picker.js
@@ -24,7 +24,7 @@ $.fn.optionValueAutocomplete = function (options) {
url: Spree.routes.option_values_api,
dataType: 'json',
data: function (params) {
- var productId = typeof (productSelect) !== 'undefined' ? $(productSelect).select2('val') : null
+ var productId = typeof (productSelect) !== 'undefined' ? $(productSelect).select2('data').id : null
var query = {
q: {
@@ -37,11 +37,15 @@ $.fn.optionValueAutocomplete = function (options) {
return query;
},
processResults: function(data) {
+ console.log('process results', data)
var results = formatOptionValueList(data)
return {
results: results
}
+ },
+ templateSelection: function(option_value) {
+ console.log('template selection', option_value)
}
}
})
diff --git a/backend/app/assets/javascripts/spree/backend/product_picker.js b/backend/app/assets/javascripts/spree/backend/product_picker.js
index c6e45c6268..0e4c06284e 100644
--- a/backend/app/assets/javascripts/spree/backend/product_picker.js
+++ b/backend/app/assets/javascripts/spree/backend/product_picker.js
@@ -19,7 +19,7 @@ $.fn.productAutocomplete = function (options) {
}
this.select2({
- multiple: true,
+ multiple: multiple,
minimumInputLength: 3,
ajax: {
url: Spree.routes.products_api,
@@ -45,12 +45,6 @@ $.fn.productAutocomplete = function (options) {
templateSelection: function(data, container) {
return data.text
}
- }).on("select2:unselect", function (e) {
- if($(this).select2('data').length == 0) {
- $('<input>').attr({ type: 'hidden', name: this.name, value: '', id: this.id }).appendTo('form.edit_promotion')
- }
- }).on('select2:select', function(e) {
- $('input#'+this.id).remove()
})
}
diff --git a/backend/app/assets/javascripts/spree/backend/promotions.js b/backend/app/assets/javascripts/spree/backend/promotions.js
index 54a5a83a3e..aa71f84e98 100644
--- a/backend/app/assets/javascripts/spree/backend/promotions.js
+++ b/backend/app/assets/javascripts/spree/backend/promotions.js
@@ -46,7 +46,7 @@ function initProductActions () {
optionValuesSelect: { value: values }
}))
var optionValue = $('.js-promo-rule-option-values .promo-rule-option-value').last()
- optionValue.find('.js-promo-rule-option-value-product-select').productAutocomplete({ multiple: false, allowClear: true })
+ optionValue.find('.js-promo-rule-option-value-product-select').productAutocomplete({ multiple: false })
optionValue.find('.js-promo-rule-option-value-option-values-select').optionValueAutocomplete({
productSelect: '.js-promo-rule-option-value-product-select'
})
diff --git a/backend/app/assets/javascripts/spree/backend/shipments.js b/backend/app/assets/javascripts/spree/backend/shipments.js
index eb00b6af81..3e1568dcf4 100644
--- a/backend/app/assets/javascripts/spree/backend/shipments.js
+++ b/backend/app/assets/javascripts/spree/backend/shipments.js
@@ -6,7 +6,6 @@ $(document).ready(function () {
// handle variant selection, show stock level.
$('#add_variant_id').change(function () {
var variantId = parseInt($(this).val())
-
var variant = _.find(window.variants, function (variant) {
return variant.id === variantId
})
@@ -284,9 +283,10 @@ function completeItemSplit(event) {
var stockLocationId = stockItemRow.find('#item_stock_location').val()
var originalShipmentNumber = link.closest('tbody').data('shipment-number')
- var selectedShipment = stockItemRow.find($('#item_stock_location').select2('data').element)
- var targetShipmentNumber = selectedShipment.data('shipment-number')
- var newShipment = selectedShipment.data('new-shipment')
+ var selectedShipment = stockItemRow.find($('#item_stock_location'))
+ var targetShipmentNumber = selectedShipment.select2().data('shipment-number')
+ var newShipment = selectedShipment
+
// eslint-disable-next-line eqeqeq
if (stockLocationId != 'new_shipment') {
var path, additionalData
@@ -335,7 +335,7 @@ function addVariantFromStockLocation(event) {
$('#stock_details').hide()
- var variantId = $('input.variant_autocomplete').val()
+ var variantId = $('select.variant_autocomplete').val()
var stockLocationId = $(this).data('stock-location-id')
var quantity = $("input.quantity[data-stock-location-id='" + stockLocationId + "']").val()
diff --git a/backend/app/assets/javascripts/spree/backend/stock_transfer.js b/backend/app/assets/javascripts/spree/backend/stock_transfer.js
index 97833d4405..4479db111e 100644
--- a/backend/app/assets/javascripts/spree/backend/stock_transfer.js
+++ b/backend/app/assets/javascripts/spree/backend/stock_transfer.js
@@ -128,8 +128,11 @@ $(function () {
}
function formattedVariantList(obj) {
- var item = { id: obj.id, text: obj.variant.name, name: obj.variant.name, sku: obj.variant.sku, options_text: obj.variant.options_text, variant: obj.variant }
- return item
+ return { id: obj.id, text: obj.name, name: obj.name, sku: obj.sku, options_text: obj.options_text, variant: obj }
+ }
+
+ function formattedStockItemsList(obj) {
+ return { id: obj.variant.id, text: obj.variant.name, name: obj.variant.name, sku: obj.variant.sku, options_text: obj.variant.options_text, variant: obj.variant }
}
TransferVariants.prototype.build_select = function (url, query) {
@@ -141,44 +144,44 @@ $(function () {
data: function (params) {
var q = {}
q[query] = params.term
- var search = {
+ return {
q: q,
token: Spree.api_key
}
-
- return search
-
},
processResults: function (data) {
- var result = data['variants'] || data['stock_items']
- if (data['stock_items'] != null) {
- result = _(result).map(function (variant) {
+ var result = data.variants || data.stock_items
+ console.log('Process Results', result)
+ if (data.variants != null) {
+ var res = (result).map(function (variant) {
return formattedVariantList(variant)
})
+ console.log('when variants present')
+ } else {
+ var res = (result).map(function (variant) {
+ return formattedStockItemsList(variant)
+ })
+ console.log('when stock items present')
}
return {
- results: result
+ results: res
}
}
},
templateResult: function(variant) {
- if (variant.loading) {
- return variant.text;
- }
-
- if (!!variant.options_text) {
- return variant.variant.name + ' - ' + variant.variant.sku + ' (' + variant.variant.options_text + ')'
+ if (variant.options_text !== "") {
+ return variant.name + ' - ' + variant.sku + ' (' + variant.options_text + ')'
} else {
- return variant.variant.name + ' - ' + variant.variant.sku
+ return variant.name + ' - ' + variant.sku
}
},
templateSelection: function (variant) {
// eslint-disable-next-line no-extra-boolean-cast
if (!!variant.options_text) {
- return variant.variant.name + (' (' + variant.variant.options_text + ')') + (' - ' + variant.variant.sku)
+ return variant.name + (' (' + variant.options_text + ')') + (' - ' + variant.sku)
} else {
- return variant.variant.name + (' - ' + variant.variant.sku)
+ return variant.name + (' - ' + variant.sku)
}
}
})
diff --git a/backend/app/assets/javascripts/spree/backend/taxon_autocomplete.js b/backend/app/assets/javascripts/spree/backend/taxon_autocomplete.js
index 4dea0163e3..23d50c6aab 100644
--- a/backend/app/assets/javascripts/spree/backend/taxon_autocomplete.js
+++ b/backend/app/assets/javascripts/spree/backend/taxon_autocomplete.js
@@ -3,17 +3,16 @@
function set_taxon_select (selector) {
function formatTaxonList(values) {
var formatted_data = $.map(values, function (obj) {
- var item = { id: obj.id, text: obj.pretty_name }
-
- return item
+ return {
+ id: obj.id,
+ text: obj.pretty_name
+ }
});
return formatted_data
}
if ($(selector).length > 0) {
-
- // deal with initSelection
$(selector).select2({
multiple: true,
placeholder: Spree.translations.taxon_placeholder,
diff --git a/backend/app/assets/javascripts/spree/backend/taxons.js b/backend/app/assets/javascripts/spree/backend/taxons.js
index 3d4c10d4b4..ac61bc7c25 100644
--- a/backend/app/assets/javascripts/spree/backend/taxons.js
+++ b/backend/app/assets/javascripts/spree/backend/taxons.js
@@ -35,71 +35,73 @@ $(function () {
taxonId.select2({
dropdownCssClass: 'taxon_select_box',
placeholder: Spree.translations.find_a_taxon,
+ minimumInputLength: 3,
+ multiple: false,
ajax: {
url: Spree.routes.taxons_api,
datatype: 'json',
- data: function (term, page) {
+ data: function (params, page) {
return {
per_page: 50,
page: page,
without_children: true,
- token: Spree.api_key,
q: {
- name_cont: term
- }
+ name_cont: params.term
+ },
+ token: Spree.api_key
}
},
- results: function (data, page) {
+ processResults: function (data, page) {
var more = page < data.pages
+ var results = formatTaxonList(data.taxons)
+
return {
- results: data['taxons'],
- more: more
+ results: results,
+ pagination: {
+ more: more
+ }
}
}
},
- formatResult: formatTaxon,
- formatSelection: formatTaxon
- })
- }
-
- taxonId.on('change', function (e) {
- var el = $('#taxon_products')
- $.ajax({
- url: Spree.routes.taxon_products_api,
- data: {
- id: e.val,
- token: Spree.api_key
- }
- }).done(function (data) {
- var i, j, len, len1, product, ref, ref1, results, variant
- el.empty()
- if (data.products.length === 0) {
- return $('#taxon_products').html('<div class="alert alert-info">' + Spree.translations.no_results + '</div>')
- } else {
- ref = data.products
- results = []
- for (i = 0, len = ref.length; i < len; i++) {
- product = ref[i]
- if (product.master.images[0] !== void 0 && product.master.images[0].small_url !== void 0) {
- product.image = product.master.images[0].small_url
- } else {
- ref1 = product.variants
- for (j = 0, len1 = ref1.length; j < len1; j++) {
- variant = ref1[j]
- if (variant.images[0] !== void 0 && variant.images[0].small_url !== void 0) {
- product.image = variant.images[0].small_url
- break
+ templateResult: formatTaxon,
+ templateSelection: formatTaxon
+ }).on('select2:select', function (e) {
+ var el = $('#taxon_products')
+ $.ajax({
+ url: Spree.routes.taxon_products_api,
+ data: { id: e.params.data.id, token: Spree.api_key }
+ }).done(function (data) {
+ var i, j, len, len1, product, ref, ref1, results, variant
+ el.empty()
+ if (data.products.length === 0) {
+ return $('#taxon_products').html('<div class="alert alert-info">' + Spree.translations.no_results + '</div>')
+ } else {
+ ref = data.products
+ results = []
+ for (i = 0, len = ref.length; i < len; i++) {
+ product = ref[i]
+ if (product.master.images[0] !== void 0 && product.master.images[0].small_url !== void 0) {
+ product.image = product.master.images[0].small_url
+ } else {
+ ref1 = product.variants
+ for (j = 0, len1 = ref1.length; j < len1; j++) {
+ variant = ref1[j]
+ if (variant.images[0] !== void 0 && variant.images[0].small_url !== void 0) {
+ product.image = variant.images[0].small_url
+ break
+ }
}
}
+ results.push(el.append(productTemplate({
+ product: product
+ })))
}
- results.push(el.append(productTemplate({
- product: product
- })))
+ return results
}
- return results
- }
+ })
})
- })
+ }
+
taxonProducts.on('click', '.js-delete-product', function (e) {
var currentTaxonId = $('#taxon_id').val()
var product = $(this).parents('.product')
@@ -126,6 +128,20 @@ $(function () {
$('.variant_autocomplete').variantAutocomplete()
function formatTaxon (taxon) {
- return Select2.util.escapeMarkup(taxon.pretty_name)
+ if (taxon.loading) {
+ return taxon.text;
+ }
+ return taxon.pretty_name
+ }
+
+ function formatTaxonList(values) {
+ var formatted_data = $.map(values, function (obj) {
+ return {
+ id: obj.id,
+ pretty_name: obj.pretty_name
+ }
+ });
+
+ return formatted_data
}
})
diff --git a/backend/app/assets/javascripts/spree/backend/user_picker.js b/backend/app/assets/javascripts/spree/backend/user_picker.js
index eddc60d21c..2f80b60dee 100644
--- a/backend/app/assets/javascripts/spree/backend/user_picker.js
+++ b/backend/app/assets/javascripts/spree/backend/user_picker.js
@@ -22,14 +22,12 @@ $.fn.userAutocomplete = function () {
url: Spree.routes.users_api,
dataType: 'json',
data: function (params) {
- var query = {
+ return {
q: {
email_start: params.term
},
token: Spree.api_key
}
-
- return query;
},
processResults: function(data) {
var results = formatUserList(data.users)
diff --git a/backend/app/assets/javascripts/spree/backend/variant_autocomplete.js b/backend/app/assets/javascripts/spree/backend/variant_autocomplete.js
index 0995da610b..4c9f425a95 100644
--- a/backend/app/assets/javascripts/spree/backend/variant_autocomplete.js
+++ b/backend/app/assets/javascripts/spree/backend/variant_autocomplete.js
@@ -27,7 +27,6 @@ $.fn.variantAutocomplete = function () {
// deal with initSelection
return this.select2({
placeholder: Spree.translations.variant_placeholder,
- debug: true,
minimumInputLength: 3,
quietMillis: 200,
ajax: {
@@ -44,6 +43,7 @@ $.fn.variantAutocomplete = function () {
return query;
},
processResults: function(data) {
+ window.variants = data['variants']
return {
results: data.variants
}
diff --git a/backend/app/controllers/spree/admin/products_controller.rb b/backend/app/controllers/spree/admin/products_controller.rb
index f682b38337..49102eeda1 100644
--- a/backend/app/controllers/spree/admin/products_controller.rb
+++ b/backend/app/controllers/spree/admin/products_controller.rb
@@ -20,10 +20,10 @@ module Spree
def update
if params[:product][:taxon_ids].present?
- params[:product][:taxon_ids] = params[:product][:taxon_ids].split(',')
+ params[:product][:taxon_ids] = params[:product][:taxon_ids].reject(&:empty?)
end
if params[:product][:option_type_ids].present?
- params[:product][:option_type_ids] = params[:product][:option_type_ids].split(',')
+ params[:product][:option_type_ids] = params[:product][:option_type_ids].reject(&:empty?)
end
invoke_callbacks(:update, :before)
if @object.update(permitted_resource_params)
diff --git a/backend/app/views/spree/admin/products/_form.html.erb b/backend/app/views/spree/admin/products/_form.html.erb
index 56c1ef8926..97fb30f6f8 100644
--- a/backend/app/views/spree/admin/products/_form.html.erb
+++ b/backend/app/views/spree/admin/products/_form.html.erb
@@ -195,7 +195,7 @@
<%= f.label :taxon_ids, Spree.t(:taxons) %>
<% if can? :modify, Spree::Classification %>
- <%= f.hidden_field :taxon_ids, value: @product.taxon_ids.join(',') %>
+ <%= f.select :taxon_ids, options_from_collection_for_select(@product.taxons, :id, :pretty_name, @product.taxons.pluck(:id)), { include_hidden: true }, multiple: true, class: 'd-block w-100' %>
<% elsif @product.taxons.any? %>
<ul class="text_list">
<% @product.taxons.each do |taxon| %>
@@ -214,7 +214,7 @@
<%= f.label :option_type_ids, Spree.t(:option_types) %>
<% if can? :modify, Spree::ProductOptionType %>
- <%= f.hidden_field :option_type_ids, value: @product.option_type_ids.join(',') %>
+ <%= f.select :option_type_ids, options_from_collection_for_select(Spree::OptionType.all, :id, :name, @product.option_types.pluck(:id)), { include_hidden: true }, multiple: true, class: 'd-block w-100' %>
<% elsif @product.option_types.any? %>
<ul class="text_list">
<% @product.option_types.each do |type| %>
diff --git a/backend/app/views/spree/admin/promotions/rules/_option_value.html.erb b/backend/app/views/spree/admin/promotions/rules/_option_value.html.erb
index 4a43544d4c..b07d02b88d 100644
--- a/backend/app/views/spree/admin/promotions/rules/_option_value.html.erb
+++ b/backend/app/views/spree/admin/promotions/rules/_option_value.html.erb
@@ -1,6 +1,6 @@
<div class="card-body">
<div class="promo-rule-option-values">
- <div class="js-promo-rule-option-values"></div>
+ <div class="js-promo-rule-option-values"></div> <!-- display div for option value select -->
<button class="btn btn-primary btn-success js-add-promo-rule-option-value">
<%= svg_icon name: "add.svg", width: '16', height: '16' %>
<%= Spree.t(:add) %>
@@ -25,11 +25,15 @@
</div>
<div class="card-body row p-3">
<div class="col-12 col-md-6">
- <%= select_tag 'product', nil, class: 'js-promo-rule-option-value-product-select d-block w-100' %> <!-- check this -->
+ <!-- TODO -->
+ <%= select_tag "product", nil, class: 'js-promo-rule-option-value-product-select d-block w-100' %>
</div>
<div class="col-12 col-md-6">
- <%= select_tag "#{param_prefix}[preferred_eligible_values][{{ productSelect.value }}]", nil, class: 'js-promo-rule-option-value-option-values-select d-block w-100' %>
+ <%#= select_tag "#{param_prefix}[preferred_eligible_values][{{ productSelect.value }}]", nil, class: 'js-promo-rule-option-value-option-values-select d-block w-100' %>
+ <%= select "#{param_prefix}","[preferred_eligible_values][]", {}, { include_hidden: true }, class: 'js-promo-rule-option-value-option-values-select d-block w-100' %>
</div>
</div>
</div>
</script>
+
+
diff --git a/backend/app/views/spree/admin/promotions/rules/_product.html.erb b/backend/app/views/spree/admin/promotions/rules/_product.html.erb
index 398bbbdfe7..005a435d89 100644
--- a/backend/app/views/spree/admin/promotions/rules/_product.html.erb
+++ b/backend/app/views/spree/admin/promotions/rules/_product.html.erb
@@ -1,7 +1,7 @@
<div class="card-body">
<div class="form-group products_rule_products">
<%= label_tag "#{param_prefix}_product_ids_string", Spree.t('product_rule.choose_products') %>
- <%= select_tag "#{param_prefix}[product_ids_string]", options_from_collection_for_select(promotion_rule.products, :id, :name, promotion_rule.products.pluck(:id)), multiple: true, class: 'product_picker d-block w-100' %>
+ <%= select "#{param_prefix}", 'product_ids_string', options_from_collection_for_select(promotion_rule.products, :id, :name, promotion_rule.products.pluck(:id)), { include_hidden: true }, multiple: true, class: 'product_picker d-block w-100' %>
</div>
<div class="form-group mb-0">
<%= label_tag Spree.t('product_rule.label') %>
diff --git a/backend/app/views/spree/admin/promotions/rules/_user.html.erb b/backend/app/views/spree/admin/promotions/rules/_user.html.erb
index e80af2085f..ba315f346f 100644
--- a/backend/app/views/spree/admin/promotions/rules/_user.html.erb
+++ b/backend/app/views/spree/admin/promotions/rules/_user.html.erb
@@ -1,6 +1,6 @@
<div class="card-body">
<div class="form-group mb-0">
<%= label_tag Spree.t('user_rule.choose_users') %>
- <%= select_tag "#{param_prefix}[user_ids_string]", options_from_collection_for_select(promotion_rule.users, :id, :email, promotion_rule.users.pluck(:id)), multiple: true, html: { class: 'user_picker d-block w-100' } %>
+ <%= select "#{param_prefix}", 'user_ids_string', options_from_collection_for_select(promotion_rule.users, :id, :email, promotion_rule.users.pluck(:id)), { include_hidden: true }, multiple: true, class: 'user_picker d-block w-100' %>
</div>
</div>
diff --git a/backend/app/views/spree/admin/taxons/index.html.erb b/backend/app/views/spree/admin/taxons/index.html.erb
index e24ed030fe..024179cfdf 100644
--- a/backend/app/views/spree/admin/taxons/index.html.erb
+++ b/backend/app/views/spree/admin/taxons/index.html.erb
@@ -4,7 +4,7 @@
<div class="taxon-products-view">
<div class="form-group">
- <%= text_field_tag :taxon_id %>
+ <%= select_tag :taxon_id, nil, class: 'd-block w-100' %>
</div>
<ul id="taxon_products" class="taxon row"></ul>
diff --git a/backend/spec/features/admin/configuration/stores_spec.rb b/backend/spec/features/admin/configuration/stores_spec.rb
index a0d58cbb9d..3089eb4c0a 100644
--- a/backend/spec/features/admin/configuration/stores_spec.rb
+++ b/backend/spec/features/admin/configuration/stores_spec.rb
@@ -35,7 +35,7 @@ describe 'Stores admin', type: :feature, js: true do
click_link 'New Store'
expect(page).to have_current_path(spree.new_admin_store_path)
- expect(page).to have_selector(:id, 's2id_store_checkout_zone_id', text: 'Asia')
+ expect(page).to have_selector(:id, 'select2-store_checkout_zone_id-container', text: 'Asia')
end
end
@@ -51,7 +51,7 @@ describe 'Stores admin', type: :feature, js: true do
click_link 'New Store'
expect(page).to have_current_path(spree.new_admin_store_path)
- expect(page).to have_selector(:id, 's2id_store_checkout_zone_id', text: 'No Limits')
+ expect(page).to have_selector(:id, 'select2-store_checkout_zone_id-container', text: 'No Limits')
end
end
@@ -61,7 +61,7 @@ describe 'Stores admin', type: :feature, js: true do
click_link 'New Store'
expect(page).to have_current_path(spree.new_admin_store_path)
- expect(page).to have_selector(:id, 's2id_store_default_currency', text: 'United States Dollar (USD)')
+ expect(page).to have_selector(:id, 'select2-store_default_currency-container', text: 'United States Dollar (USD)')
end
it 'saving store' do
diff --git a/backend/spec/features/admin/products/edit/taxons_spec.rb b/backend/spec/features/admin/products/edit/taxons_spec.rb
index 0c4cf1f148..fd191b4e58 100644
--- a/backend/spec/features/admin/products/edit/taxons_spec.rb
+++ b/backend/spec/features/admin/products/edit/taxons_spec.rb
@@ -4,10 +4,6 @@ describe 'Product Taxons', type: :feature, js: true do
stub_authorization!
context 'managing taxons' do
- def selected_taxons
- find('#product_taxon_ids', visible: :hidden).value.split(',').map(&:to_i).uniq
- end
-
it 'allows an admin to manage taxons' do
taxon_1 = create(:taxon)
taxon_2 = create(:taxon, name: 'Clothing')
@@ -17,16 +13,16 @@ describe 'Product Taxons', type: :feature, js: true do
visit spree.admin_products_path
within_row(1) { click_icon :edit }
- expect(page).to have_css('.select2-search-choice', exact_text: "#{taxon_1.parent.name} -> #{taxon_1.name}")
- expect(selected_taxons).to match_array([taxon_1.id])
+ expect(page).to have_css('.select2-selection__choice', text: "#{taxon_1.parent.name} -> #{taxon_1.name}")
- select2 'Clothing', from: 'Taxons'
+ select2_open label: 'Taxons'
+ select2_search 'Clothing', from: 'Taxons'
+ select2_select 'Clothing', from: 'Taxons', match: :first
wait_for { !page.has_button?('Update') }
click_button 'Update'
- expect(selected_taxons).to match_array([taxon_1.id, taxon_2.id])
- expect(page).to have_css('.select2-search-choice', text: taxon_1.name).
- and have_css('.select2-search-choice', text: taxon_2.name)
+ expect(page).to have_css('.select2-selection__choice', text: taxon_1.name).
+ and have_css('.select2-selection__choice', text: taxon_2.name)
end
end
end
diff --git a/backend/spec/features/admin/products/edit/variants_spec.rb b/backend/spec/features/admin/products/edit/variants_spec.rb
index d7325c4457..2c4480b081 100644
--- a/backend/spec/features/admin/products/edit/variants_spec.rb
+++ b/backend/spec/features/admin/products/edit/variants_spec.rb
@@ -36,7 +36,10 @@ describe 'Product Variants', type: :feature, js: true do
visit spree.admin_products_path
within_row(1) { click_icon :edit }
- select2 'shirt', from: 'Option Types'
+ select2_open label: 'Option Types'
+ select2_search 'shirt', label: 'Option Types'
+ select2_select 'shirt', from: 'Option Types', match: :first
+
wait_for { !page.has_button?('Update') }
click_button 'Update'
expect(page).to have_content('successfully updated!')
@@ -73,14 +76,19 @@ describe 'Product Variants', type: :feature, js: true do
visit spree.admin_products_path
within_row(1) { click_icon :edit }
- select2 'shirt', from: 'Option Types'
+ select2_open label: 'Option Types'
+ select2_search 'shirt', label: 'Option Types'
+ select2_select 'shirt', from: 'Option Types', match: :first
+
wait_for { !page.has_button?('Update') }
click_button 'Update'
within('#sidebar') { click_link 'Variants' }
click_link 'New Variant'
- select2 'black', from: 'Colors'
+ select2_open label: 'Colors'
+ select2_search 'black', label: 'Colors'
+ select2_select 'black', from: 'Colors', match: :first
fill_in 'variant_sku', with: 'A100'
click_button 'Create'
diff --git a/backend/spec/features/admin/products/prototypes_spec.rb b/backend/spec/features/admin/products/prototypes_spec.rb
index 436a275eb2..3aeacbad39 100644
--- a/backend/spec/features/admin/products/prototypes_spec.rb
+++ b/backend/spec/features/admin/products/prototypes_spec.rb
@@ -80,8 +80,8 @@ describe 'Prototypes', type: :feature, js: true do
click_icon :edit
- first('a[class="select2-search-choice-close"]').click
- find('a[class="select2-search-choice-close"]').click
+ first('span[class="select2-selection__choice__remove"]').click
+ find('span[class="select2-selection__choice__remove"]').click
click_button 'Update'
diff --git a/backend/spec/features/admin/promotions/adjustments_spec.rb b/backend/spec/features/admin/promotions/adjustments_spec.rb
index f281a27223..61db601634 100644
--- a/backend/spec/features/admin/promotions/adjustments_spec.rb
+++ b/backend/spec/features/admin/promotions/adjustments_spec.rb
@@ -218,9 +218,9 @@ describe 'Promotion Adjustments', type: :feature, js: true do
within('#action_fields') { click_button 'Add' }
- page.find('.create_line_items .select2-choice').click
- page.find('.select2-input').set('RoR Mug')
- page.find('.select2-highlighted').click
+ select2_open label: 'Variant'
+ select2_search 'RoR Mug', label: 'Variant'
+ select2_select 'RoR Mug', from: 'Variant', match: :first
wait_for { !page.has_button?('Update') }
within('#actions_container') { click_button 'Update' }
diff --git a/backend/spec/features/admin/promotions/user_rule_spec.rb b/backend/spec/features/admin/promotions/user_rule_spec.rb
index 40e8f155d2..39a82ca957 100644
--- a/backend/spec/features/admin/promotions/user_rule_spec.rb
+++ b/backend/spec/features/admin/promotions/user_rule_spec.rb
@@ -22,15 +22,15 @@ describe 'Promotion with user rule', type: :feature, js: true do
select2 'User', from: 'Add rule of type', match: :first
within('#rule_fields') { click_button 'Add' }
- find('.user_picker').fill_in with: 'first'
+ select2_open label: 'Choose users'
+ select2_search 'first', label: 'Choose users'
+
expect(page).to have_content('[email protected]')
expect(page).not_to have_content('[email protected]')
expect(page).not_to have_content('[email protected]')
- within('#select2-drop') do
- first('.select2-result').click
- end
+ select2_select '[email protected]', from: 'Choose users', match: :first
wait_for { !page.has_button?('Update') }
within('#rules_container') { click_button 'Update' }
@@ -45,7 +45,8 @@ describe 'Promotion with user rule', type: :feature, js: true do
select2 'User', from: 'Add rule of type', match: :first
within('#rule_fields') { click_button 'Add' }
- find('.user_picker').fill_in with: 'example'
+ select2_open label: 'Choose users'
+ select2_search 'example', label: 'Choose users'
expect(page).to have_content('[email protected]')
expect(page).to have_content('[email protected]')
@@ -59,7 +60,8 @@ describe 'Promotion with user rule', type: :feature, js: true do
select2 'User', from: 'Add rule of type', match: :first
within('#rule_fields') { click_button 'Add' }
- find('.user_picker').fill_in with: 'test'
+ select2_open label: 'Choose users'
+ select2_search 'test', label: 'Choose users'
expect(page).to have_content('[email protected]')
expect(page).to have_content('[email protected]')
diff --git a/backend/spec/features/admin/stock_transfer_spec.rb b/backend/spec/features/admin/stock_transfer_spec.rb
index 686e862034..eed419fa62 100644
--- a/backend/spec/features/admin/stock_transfer_spec.rb
+++ b/backend/spec/features/admin/stock_transfer_spec.rb
@@ -13,7 +13,9 @@ describe 'Stock Transfers', type: :feature, js: true do
visit spree.admin_stock_transfers_path
click_on 'New Stock Transfer'
- select2 variant.sku, from: 'Variant', search: true, match: :first
+ select2_open label: 'Variant'
+ select2_search variant.sku, from: 'Variant'
+ select2_select variant.name, from: 'Variant', match: :first
content = "#{variant.name} (#{variant.options_text}) - #{variant.sku}"
expect(page).to have_content(content)
@@ -29,7 +31,9 @@ describe 'Stock Transfers', type: :feature, js: true do
click_on 'New Stock Transfer'
fill_in 'reference', with: 'PO 666'
- select2 variant.name, from: 'Variant', search: true
+ select2_open label: 'Variant'
+ select2_search variant.name, from: 'Variant'
+ select2_select variant.name, from: 'Variant', match: :first
click_button 'Add'
click_button 'Transfer Stock'
@@ -54,7 +58,9 @@ describe 'Stock Transfers', type: :feature, js: true do
click_on 'New Stock Transfer'
fill_in 'reference', with: 'PO 666'
- select2 product.master.name, from: 'Variant', search: true
+ select2_open label: 'Variant'
+ select2_search product.master.name, from: 'Variant'
+ select2_select product.master.name, from: 'Variant', match: :first
click_button 'Add'
click_button 'Transfer Stock'
@@ -85,7 +91,9 @@ describe 'Stock Transfers', type: :feature, js: true do
check 'transfer_receive_stock'
select2 'NY', from: 'Destination'
- select2 variant.name, from: 'Variant', search: true
+ select2_open label: 'Variant'
+ select2_search variant.name, from: 'Variant'
+ select2_select variant.name, from: 'Variant', match: :first
click_button 'Add'
click_button 'Transfer Stock'
@@ -102,7 +110,10 @@ describe 'Stock Transfers', type: :feature, js: true do
fill_in 'reference', with: 'PO 666'
select2 'NY', from: 'Destination'
- select2 variant.name, from: 'Variant', search: true
+
+ select2_open label: 'Variant'
+ select2_search variant.name, from: 'Variant'
+ select2_select variant.name, from: 'Variant', match: :first
click_button 'Add'
click_button 'Transfer Stock'
diff --git a/backend/spec/features/admin/taxons_spec.rb b/backend/spec/features/admin/taxons_spec.rb
index 1424589db6..429557d304 100644
--- a/backend/spec/features/admin/taxons_spec.rb
+++ b/backend/spec/features/admin/taxons_spec.rb
@@ -49,6 +49,8 @@ describe 'Taxonomies and taxons', type: :feature do
end
def select_clothing_from_select2
- select2 'Clothing', css: '.taxon-products-view', search: true
+ select2_open css: '.taxon-products-view'
+ select2_search 'Clothing', css: '.taxon-products-view'
+ select2_select Spree::Product.first.taxons.first&.pretty_name, css: '.taxon-products-view'
end
end
diff --git a/backend/spec/spec_helper.rb b/backend/spec/spec_helper.rb
index 1a834d3537..1cfb1c1aa0 100644
--- a/backend/spec/spec_helper.rb
+++ b/backend/spec/spec_helper.rb
@@ -97,6 +97,7 @@ RSpec.configure do |config|
end
config.include CapybaraSelect2
+ config.include CapybaraSelect2::Helpers
config.include FactoryBot::Syntax::Methods
config.include Spree::TestingSupport::Preferences
diff --git a/backend/spree_backend.gemspec b/backend/spree_backend.gemspec
index b9e0207600..9f11badbbf 100644
--- a/backend/spree_backend.gemspec
+++ b/backend/spree_backend.gemspec
@@ -35,5 +35,4 @@ Gem::Specification.new do |s|
s.add_dependency 'jquery-rails', '~> 4.3'
s.add_dependency 'jquery-ui-rails', '~> 6.0.1'
s.add_dependency 'select2-rails', '~> 4.0.0'
- s.add_dependency 'pry'
end