Skip to content

Commit 3a31d15

Browse files
committed
ACP2E-2308: [CLOUD]: Configurable product with drop down attribute throws unexpected exception error and does not allow selection when a product carousel is present on PDP
1 parent da20c4e commit 3a31d15

File tree

2 files changed

+78
-21
lines changed

2 files changed

+78
-21
lines changed

dev/tests/js/jasmine/tests/app/code/Magento/ConfigurableProduct/view/frontend/js/configurable.test.js

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,14 @@ define([
6767
'salable': []
6868
}
6969
},
70-
blockHtml = '<form id="cart"/>'
71-
+ '<select name=\'super_attribute[93]\'' +
70+
blockHtml = '<div class="product-info-main">' +
71+
'<div class="product-info-price">' +
72+
'<div class="price-box price-final_price" data-role="priceBox">' +
73+
'</div>' +
74+
'</div>' +
75+
'<div class="product-add-form">' +
76+
'<form id="cart"/>' +
77+
'<select name=\'super_attribute[93]\'' +
7278
' data-selector=\'super_attribute[93]\'' +
7379
' data-validate=\'{required:true}\'' +
7480
' id=\'attribute93\'' +
@@ -78,7 +84,9 @@ define([
7884
'<option value=\'15\'>beige</option>' +
7985
'</select>' +
8086
'<input id="qty"/>' +
81-
'</form>',
87+
'</form>' +
88+
'</div>' +
89+
'</div>',
8290
selectElement,
8391
qtyElement,
8492
formElement;
@@ -89,13 +97,22 @@ define([
8997
selectElement = $('#attribute93');
9098
qtyElement = $('#qty');
9199
formElement = $('#cart');
92-
widget = new Configurable($.extend(true, {}, options), formElement);
93100
$.fn.trigFunc = $.fn.trigger;
101+
$.fn.priceBoxFunc = $.fn.priceBox;
102+
$.fn.priceBox = function () {
103+
return {
104+
prices: $.extend(true, {}, this.data('price-box'))
105+
};
106+
};
107+
$('body').find('[data-role=priceBox]').data('price-box', $.extend(true, {}, options.spConfig.prices));
108+
widget = new Configurable($.extend(true, {}, options), formElement);
94109
});
95110
afterEach(function () {
96111
formElement.remove();
97112
$.fn.trigger = $.fn.trigFunc;
113+
$.fn.priceBox = $.fn.priceBoxFunc;
98114
delete $.fn.trigFunc;
115+
delete $.fn.priceBoxFunc;
99116
});
100117
it('check if attribute value is possible to be set as configurable option', function () {
101118
expect($.mage.configurable).toBeDefined();
@@ -112,17 +129,6 @@ define([
112129
it('check if widget will return correct price values in case option is selected or not.', function () {
113130
var result;
114131

115-
spyOn($.fn, 'priceBox').and.callFake(function () {
116-
return {
117-
prices: {
118-
'baseOldPrice': {'amount': 10},
119-
'oldPrice': {'amount': 10},
120-
'basePrice': {'amount': 10},
121-
'finalPrice': {'amount': 10},
122-
'msrpPrice': {'amount': 0}
123-
}
124-
};
125-
});
126132
result = widget._getPrices().prices;
127133
expect(result.baseOldPrice.amount).toBe(0);
128134
expect(result.oldPrice.amount).toBe(0);
@@ -140,7 +146,26 @@ define([
140146
it('check that price is reloaded on qty change', function () {
141147
spyOn($.fn, 'trigger');
142148
qtyElement.trigFunc('input');
143-
expect($.fn.trigger).toHaveBeenCalledWith('updatePrice', {});
149+
expect($.fn.trigger)
150+
.toHaveBeenCalledWith(
151+
'updatePrice',
152+
{
153+
prices: {
154+
baseOldPrice: {
155+
amount: 0
156+
},
157+
oldPrice: {
158+
amount: 0
159+
},
160+
basePrice: {
161+
amount: 0
162+
},
163+
finalPrice: {
164+
amount: 0
165+
}
166+
}
167+
}
168+
);
144169
});
145170

146171
it('check if the _configureElement method is enabling configurable option or not', function () {

dev/tests/js/jasmine/tests/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.test.js

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,55 @@ define([
9494
});
9595

9696
it('check udate price method', function () {
97-
var productPriceMock = {
98-
find: jasmine.createSpy().and.returnValue({
99-
hide: jasmine.createSpy(),
97+
var productBlock, parentsResultMap, findResultMap;
98+
99+
parentsResultMap = {
100+
'[data-role=priceBox]': {
100101
priceBox: jasmine.createSpy().and.returnValue(''),
101102
trigger: jasmine.createSpy(),
102103
find: jasmine.createSpy().and.returnValue({
103104
toggleClass: jasmine.createSpy()
104105
})
106+
},
107+
'.normal-price .price-label': {
108+
hide: jasmine.createSpy(),
109+
show: jasmine.createSpy()
110+
},
111+
'.sly-old-price': {
112+
hide: jasmine.createSpy()
113+
}
114+
};
115+
116+
findResultMap = {
117+
'.swatch-attribute-options': [
118+
$('<div class="swatch-attribute-options"><div class="swatch-option"></div></div>')
119+
]
120+
};
121+
122+
productBlock = {
123+
// eslint-disable-next-line max-nested-callbacks
124+
find: jasmine.createSpy().and.callFake(function (selector) {
125+
return parentsResultMap[selector];
105126
})
106127
};
107128

108129
widget.element = {
109-
parents: jasmine.createSpy().and.returnValue(productPriceMock)
130+
parents: jasmine.createSpy().and.returnValue(productBlock),
131+
// eslint-disable-next-line max-nested-callbacks
132+
find: jasmine.createSpy().and.callFake(function (selector) {
133+
return findResultMap[selector];
134+
})
110135
};
111136
widget._getNewPrices = jasmine.createSpy().and.returnValue(undefined);
112137
widget._UpdatePrice();
113-
expect(productPriceMock.find().find.calls.count()).toBe(1);
138+
expect(widget.element.parents).toHaveBeenCalledOnceWith('.product-info-main');
139+
expect(widget.element.find).toHaveBeenCalledOnceWith('.swatch-attribute-options');
140+
expect(parentsResultMap['[data-role=priceBox]'].find).toHaveBeenCalledOnceWith('span:first');
141+
expect(parentsResultMap['.sly-old-price'].hide).toHaveBeenCalledTimes(1);
142+
expect(parentsResultMap['.normal-price .price-label'].hide).toHaveBeenCalledTimes(1);
143+
expect(parentsResultMap['.normal-price .price-label'].hide)
144+
.toHaveBeenCalledBefore(parentsResultMap['.normal-price .price-label'].show);
145+
expect(parentsResultMap['.normal-price .price-label'].show).toHaveBeenCalledTimes(1);
114146
});
115147

116148
it('check getSelectedOptionPriceIndex', function () {

0 commit comments

Comments
 (0)