diff --git a/app/assets/javascripts/darkswarm/services/variants.js.coffee b/app/assets/javascripts/darkswarm/services/variants.js.coffee index 441258dc1a..456fd00f01 100644 --- a/app/assets/javascripts/darkswarm/services/variants.js.coffee +++ b/app/assets/javascripts/darkswarm/services/variants.js.coffee @@ -17,11 +17,11 @@ Darkswarm.factory 'Variants', -> extendedVariantName: (variant) => if variant.product_name == variant.name_to_display - variant.product_name + name = variant.product_name else name = "#{variant.product_name} - #{variant.name_to_display}" - name += " (#{variant.options_text})" if variant.options_text - name + name += " (#{variant.options_text})" if variant.options_text + name lineItemFor: (variant) -> variant: variant diff --git a/spec/javascripts/unit/darkswarm/services/variants_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/variants_spec.js.coffee index 7d8047ecc9..408fecf7ea 100644 --- a/spec/javascripts/unit/darkswarm/services/variants_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/services/variants_spec.js.coffee @@ -49,6 +49,14 @@ describe 'Variants service', -> variant = {product_name: 'product_name', name_to_display: 'product_name'} expect(Variants.extendedVariantName(variant)).toEqual "product_name" + it "includes the options text even if variant name is same as product", -> + variant = + product_name: 'product_name' + name_to_display: 'product_name' + options_text: 'options_text' + + expect(Variants.extendedVariantName(variant)).toEqual "product_name (options_text)" + describe "when the product name and the variant name differ", -> it "returns a combined name when there is no options text", -> variant =