@@ -11,92 +11,102 @@ define([
1111 'use strict' ;
1212
1313 var widget ,
14- option = '<select name=\'super_attribute[93]\'' +
15- 'data-selector=\'super_attribute[93]\'' +
16- 'data-validate=\'{required:true}\'' +
17- 'id=\'attribute93\'' +
18- 'class=\'super-attribute-select\'>' +
19- '<option value=\'\'></option>' +
20- '</select>' ,
21- selectElement = $ ( option ) ;
22-
23- beforeEach ( function ( ) {
24- widget = new Configurable ( ) ;
25- widget . options = {
26- settings : [
27- {
28- selectedIndex : 0 ,
29- options : [
30- {
31- label : 'Chose an Option...'
32- } ,
33- {
34- label : 'red' ,
35- config : {
36- id : '4' ,
37- label : 'red' ,
38- products : [
39- '4'
40- ] ,
41- initialLabel : 'red' ,
42- allowedProducts : [ '4' ]
43- }
44- }
45- ]
46- }
47- ] ,
48- priceHolderSelector : 'testSelector' ,
49- spConfig : {
50- chooseText : 'Chose an Option...' ,
51- optionPrices : {
52- 4 : {
53- testPrice1 : {
54- amount : 40
55- } ,
56- testPrice2 : {
57- amount : 30
58- }
14+ options = {
15+ 'spConfig' : {
16+ 'attributes' : {
17+ '93' : {
18+ 'id' : '93' ,
19+ 'code' : 'color' ,
20+ 'label' : 'Color' ,
21+ 'options' : [
22+ { 'id' : '14' , 'label' : 'brown' , 'products' : [ '2' ] } ,
23+ { 'id' : '15' , 'label' : 'beige' , 'products' : [ '3' ] }
24+ ] ,
25+ 'position' : '0'
5926 }
6027 } ,
61- attributes :
62- {
63- 'size' : {
64- options : [
65- {
66- id : '2' ,
67- value : '2'
68- } ,
69- {
70- id : 3 ,
71- value : 'red'
72-
73- }
74- ]
75- }
28+ 'template' : '$<%- data.price %>' ,
29+ 'currencyFormat' : '$%s' ,
30+ 'optionPrices' : {
31+ '2' : {
32+ 'baseOldPrice' : { 'amount' : 12 } ,
33+ 'oldPrice' : { 'amount' : 12 } ,
34+ 'basePrice' : { 'amount' : 12 } ,
35+ 'finalPrice' : { 'amount' : 12 } ,
36+ 'tierPrices' : [ { 'qty' : 4 , 'price' : 8.4 , 'percentage' : 30 , 'excl_tax_price' : 8.4 } ] ,
37+ 'msrpPrice' : { 'amount' : 0 }
7638 } ,
77- prices : {
78- finalPrice : {
79- amount : 12
39+ '3' : {
40+ 'baseOldPrice' : { 'amount' : 10 } ,
41+ 'oldPrice' : { 'amount' : 10 } ,
42+ 'basePrice' : { 'amount' : 10 } ,
43+ 'finalPrice' : { 'amount' : 10 } ,
44+ 'tierPrices' : [ ] ,
45+ 'msrpPrice' : { 'amount' : 0 }
8046 }
81- }
82- } ,
83- values : { }
84- } ;
85- } ) ;
47+ } ,
48+ 'priceFormat' : {
49+ 'pattern' : '$%s' ,
50+ 'precision' : 2 ,
51+ 'requiredPrecision' : 2 ,
52+ 'decimalSymbol' : '.' ,
53+ 'groupSymbol' : ',' ,
54+ 'groupLength' : 3 ,
55+ 'integerRequired' : false
56+ } ,
57+ 'prices' : {
58+ 'baseOldPrice' : { 'amount' : 10 } ,
59+ 'oldPrice' : { 'amount' : 10 } ,
60+ 'basePrice' : { 'amount' : 10 } ,
61+ 'finalPrice' : { 'amount' : 10 }
62+ } ,
63+ 'productId' : '4' ,
64+ 'chooseText' : 'Choose an Option...' ,
65+ 'images' : [ ] ,
66+ 'index' : { '2' : { '93' : '14' } , '3' : { '93' : '15' } } ,
67+ 'salable' : [ ]
68+ }
69+ } ,
70+ blockHtml = '<form id="cart"/>'
71+ + '<select name=\'super_attribute[93]\'' +
72+ ' data-selector=\'super_attribute[93]\'' +
73+ ' data-validate=\'{required:true}\'' +
74+ ' id=\'attribute93\'' +
75+ ' class=\'super-attribute-select\'>' +
76+ '<option value=\'\'>Choose an Option...</option>' +
77+ '<option value=\'14\'>brown +$2.00</option>' +
78+ '<option value=\'15\'>beige</option>' +
79+ '</select>' +
80+ '<input id="qty"/>' +
81+ '</form>' ,
82+ selectElement ,
83+ qtyElement ,
84+ formElement ;
8685
8786 describe ( 'Magento_ConfigurableProduct/js/configurable' , function ( ) {
88-
87+ beforeEach ( function ( ) {
88+ $ ( blockHtml ) . appendTo ( 'body' ) ;
89+ selectElement = $ ( '#attribute93' ) ;
90+ qtyElement = $ ( '#qty' ) ;
91+ formElement = $ ( '#cart' ) ;
92+ widget = new Configurable ( $ . extend ( true , { } , options ) , formElement ) ;
93+ $ . fn . trigFunc = $ . fn . trigger ;
94+ } ) ;
95+ afterEach ( function ( ) {
96+ formElement . remove ( ) ;
97+ $ . fn . trigger = $ . fn . trigFunc ;
98+ delete $ . fn . trigFunc ;
99+ } ) ;
89100 it ( 'check if attribute value is possible to be set as configurable option' , function ( ) {
90101 expect ( $ . mage . configurable ) . toBeDefined ( ) ;
91- widget . _parseQueryParams ( 'size=2 ' ) ;
92- expect ( widget . options . values . size ) . toBe ( '2 ' ) ;
102+ widget . _parseQueryParams ( '93=14 ' ) ;
103+ expect ( widget . options . values [ '93' ] ) . toBe ( '14 ' ) ;
93104 } ) ;
94105
95106 it ( 'check that attribute value is not set if provided option does not exists' , function ( ) {
96107 expect ( $ . mage . configurable ) . toBeDefined ( ) ;
97- widget . _parseQueryParams ( 'size=10' ) ;
98- widget . _fillSelect ( selectElement [ 0 ] ) ;
99- expect ( widget . options . values . size ) . toBe ( undefined ) ;
108+ widget . _parseQueryParams ( '93=10' ) ;
109+ expect ( widget . options . values [ '93' ] ) . toBe ( undefined ) ;
100110 } ) ;
101111
102112 it ( 'check if widget will return correct price values in case option is selected or not.' , function ( ) {
@@ -105,23 +115,32 @@ define([
105115 spyOn ( $ . fn , 'priceBox' ) . and . callFake ( function ( ) {
106116 return {
107117 prices : {
108- testPrice1 : {
109- amount : 10
110- } ,
111- testPrice2 : {
112- amount : 20
113- }
118+ 'baseOldPrice' : { 'amount' : 10 } ,
119+ 'oldPrice' : { 'amount' : 10 } ,
120+ 'basePrice' : { 'amount' : 10 } ,
121+ 'finalPrice' : { 'amount' : 10 } ,
122+ 'msrpPrice' : { 'amount' : 0 }
114123 }
115124 } ;
116125 } ) ;
117126 result = widget . _getPrices ( ) . prices ;
118- expect ( result . testPrice1 . amount ) . toBe ( 0 ) ;
119- expect ( result . testPrice2 . amount ) . toBe ( 0 ) ;
127+ expect ( result . baseOldPrice . amount ) . toBe ( 0 ) ;
128+ expect ( result . oldPrice . amount ) . toBe ( 0 ) ;
129+ expect ( result . basePrice . amount ) . toBe ( 0 ) ;
130+ expect ( result . finalPrice . amount ) . toBe ( 0 ) ;
120131
121- widget . options . settings [ 0 ] . selectedIndex = 1 ;
132+ selectElement . val ( 14 ) ;
122133 result = widget . _getPrices ( ) . prices ;
123- expect ( result . testPrice1 . amount ) . toBe ( 30 ) ;
124- expect ( result . testPrice2 . amount ) . toBe ( 10 ) ;
134+ expect ( result . baseOldPrice . amount ) . toBe ( 2 ) ;
135+ expect ( result . oldPrice . amount ) . toBe ( 2 ) ;
136+ expect ( result . basePrice . amount ) . toBe ( 2 ) ;
137+ expect ( result . finalPrice . amount ) . toBe ( 2 ) ;
138+ } ) ;
139+
140+ it ( 'check that price is reloaded on qty change' , function ( ) {
141+ spyOn ( $ . fn , 'trigger' ) ;
142+ qtyElement . trigFunc ( 'input' ) ;
143+ expect ( $ . fn . trigger ) . toHaveBeenCalledWith ( 'updatePrice' , { } ) ;
125144 } ) ;
126145 } ) ;
127146} ) ;
0 commit comments