Skip to content

Commit 1b3da7e

Browse files
committed
Fix unit and functional tests
1 parent 4f853e8 commit 1b3da7e

File tree

8 files changed

+148
-147
lines changed

8 files changed

+148
-147
lines changed

app/code/Magento/Catalog/Test/Mftf/Section/StorefrontCategorySidebarSection.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<element name="filterOptions" type="text" selector=".filter-options-content .items"/>
1414
<element name="filterOption" type="text" selector=".filter-options-content .item"/>
1515
<element name="optionQty" type="text" selector=".filter-options-content .item .count"/>
16-
<element name="filterOptionByLabel" type="button" selector=" div.filter-options-item div[option-label='{{optionLabel}}']" parameterized="true"/>
16+
<element name="filterOptionByLabel" type="button" selector=" div.filter-options-item div[data-option-label='{{optionLabel}}']" parameterized="true"/>
1717
<element name="removeFilter" type="button" selector="div.filter-current .remove"/>
1818
<element name="activeFilterOptions" type="text" selector=".filter-options-item.active .items"/>
1919
<element name="activeFilterOptionItemByPosition" type="text" selector=".filter-options-item.active .items li:nth-child({{itemPosition}}) a" parameterized="true"/>

app/code/Magento/Catalog/Test/Mftf/Test/AdminBackorderAllowedAddProductToCartTest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<!-- Set Magento back to default configuration -->
3232
<magentoCLI command="config:set {{CatalogInventoryOptionsShowOutOfStockDisable.path}} {{CatalogInventoryOptionsShowOutOfStockDisable.value}}" stepKey="setConfigShowOutOfStockFalse"/>
3333
<magentoCLI command="config:set {{CatalogInventoryItemOptionsBackordersDisable.path}} {{CatalogInventoryItemOptionsBackordersDisable.value}}" stepKey="setConfigAllowBackordersFalse"/>
34+
<magentoCLI command="cache:flush" stepKey="flushCache"/>
3435
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
3536
</after>
3637

app/code/Magento/Swatches/Test/Mftf/Section/StorefrontProductInfoMainSection.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1010
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
1111
<section name="StorefrontProductInfoMainSection">
12-
<element name="swatchOptionByLabel" type="button" selector="div.swatch-option[option-label='{{opt}}']" parameterized="true"/>
12+
<element name="swatchOptionByLabel" type="button" selector="div.swatch-option[data-option-label='{{opt}}']" parameterized="true"/>
1313
<element name="nthSwatchOption" type="button" selector="div.swatch-option:nth-of-type({{var}})" parameterized="true"/>
1414
<element name="selectedSwatchValue" type="text" selector="//div[contains(@class, 'swatch-attribute') and contains(., '{{attr}}')]//span[contains(@class, 'swatch-attribute-selected-option')]" parameterized="true"/>
1515
<element name="swatchAttributeOptions" type="text" selector="div.swatch-attribute-options"/>
1616
<element name="nthSwatchOptionText" type="button" selector="div.swatch-option.text:nth-of-type({{n}})" parameterized="true"/>
1717
<element name="productSwatch" type="button" selector="//div[@class='swatch-option'][@aria-label='{{var1}}']" parameterized="true"/>
18-
<element name="visualSwatchOption" type="button" selector=".swatch-option[option-tooltip-value='#{{visualSwatchOption}}']" parameterized="true"/>
18+
<element name="visualSwatchOption" type="button" selector=".swatch-option[data-option-tooltip-value='#{{visualSwatchOption}}']" parameterized="true"/>
1919
<element name="swatchOptionTooltip" type="block" selector="div.swatch-option-tooltip"/>
2020
</section>
2121
</sections>

app/code/Magento/Swatches/Test/Mftf/Test/AdminCreateTextSwatchTest.xml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
*/
77
-->
88

9-
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10-
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
1110
<test name="AdminCreateTextSwatchTest">
1211
<annotations>
1312
<features value="Swatches"/>
@@ -83,19 +82,19 @@
8382
<amOnPage url="{{_defaultProduct.urlKey}}.html" stepKey="amOnProductPage"/>
8483
<waitForPageLoad stepKey="waitForProductPage"/>
8584
<see selector="{{StorefrontProductInfoMainSection.swatchAttributeOptions}}" userInput="red" stepKey="seeRed"/>
86-
<grabAttributeFrom selector="{{StorefrontProductInfoMainSection.nthSwatchOptionText('1')}}" userInput="option-label" stepKey="grabRedLabel"/>
85+
<grabAttributeFrom selector="{{StorefrontProductInfoMainSection.nthSwatchOptionText('1')}}" userInput="data-option-label" stepKey="grabRedLabel"/>
8786
<assertEquals stepKey="assertRedLabel">
8887
<expectedResult type="string">Something red.</expectedResult>
8988
<actualResult type="string">{$grabRedLabel}</actualResult>
9089
</assertEquals>
9190
<see selector="{{StorefrontProductInfoMainSection.swatchAttributeOptions}}" userInput="green" stepKey="seeGreen"/>
92-
<grabAttributeFrom selector="{{StorefrontProductInfoMainSection.nthSwatchOptionText('2')}}" userInput="option-label" stepKey="grabGreenLabel"/>
91+
<grabAttributeFrom selector="{{StorefrontProductInfoMainSection.nthSwatchOptionText('2')}}" userInput="data-option-label" stepKey="grabGreenLabel"/>
9392
<assertEquals stepKey="assertGreenLabel">
9493
<expectedResult type="string">Something green.</expectedResult>
9594
<actualResult type="string">{$grabGreenLabel}</actualResult>
9695
</assertEquals>
9796
<see selector="{{StorefrontProductInfoMainSection.swatchAttributeOptions}}" userInput="blue" stepKey="seeBlue"/>
98-
<grabAttributeFrom selector="{{StorefrontProductInfoMainSection.nthSwatchOptionText('3')}}" userInput="option-label" stepKey="grabBlueLabel"/>
97+
<grabAttributeFrom selector="{{StorefrontProductInfoMainSection.nthSwatchOptionText('3')}}" userInput="data-option-label" stepKey="grabBlueLabel"/>
9998
<assertEquals stepKey="assertBlueLabel">
10099
<expectedResult type="string">Something blue.</expectedResult>
101100
<actualResult type="string">{$grabBlueLabel}</actualResult>

app/code/Magento/Swatches/view/base/web/js/swatch-renderer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,8 @@ define([
462462
if (showTooltip === 1) {
463463
// Connect Tooltip
464464
container
465-
.find('[data-option-type="1"], [data-option-type="2"], [data-option-type="0"], [data-option-type="3"]')
465+
.find('[data-option-type="1"], [data-option-type="2"],' +
466+
' [data-option-type="0"], [data-option-type="3"]')
466467
.SwatchRendererTooltip();
467468
}
468469

dev/tests/functional/tests/app/Magento/Swatches/Test/Block/Product/ProductList/ProductItem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ProductItem extends CatalogProductItem
1919
*
2020
* @var string
2121
*/
22-
protected $swatchSelector = 'div[option-id="%s"]';
22+
protected $swatchSelector = 'div[data-option-id="%s"]';
2323

2424
/**
2525
* Selector for the swatches of the product.

dev/tests/functional/tests/app/Magento/Swatches/Test/Block/Product/ViewWithSwatches.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ public function getSwatchAttributesData()
5555
$swatchAttributesData = [];
5656
$swatchAttributes = $this->_rootElement->getElements($this->swatchAttributesSelector);
5757
foreach ($swatchAttributes as $swatchAttribute) {
58-
$attributeCode = $swatchAttribute->getAttribute('attribute-code');
58+
$attributeCode = $swatchAttribute->getAttribute('data-attribute-code');
5959
$swatchAttributesData[$attributeCode] = [
6060
'attribute_code' => $attributeCode,
61-
'attribute_id' => $swatchAttribute->getAttribute('attribute-id'),
61+
'attribute_id' => $swatchAttribute->getAttribute('data-attribute-id'),
6262
'label' => $swatchAttribute->find($this->swatchAttributesLabelSelector)->getText(),
6363
'options' => $this->getSwatchAttributeOptionsData($swatchAttribute),
6464
];
@@ -77,7 +77,7 @@ private function getSwatchAttributeOptionsData(ElementInterface $swatchAttribute
7777
$optionsData = [];
7878
$options = $swatchAttribute->getElements($this->swatchAttributeOptionsSelector);
7979
foreach ($options as $option) {
80-
$optionId = $option->getAttribute('option-id');
80+
$optionId = $option->getAttribute('data-option-id');
8181
$optionsData[$optionId] = [
8282
'option_id' => $optionId,
8383
'label' => $option->getText(),
Lines changed: 134 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,134 +1,134 @@
1-
/**
2-
* Copyright © Magento, Inc. All rights reserved.
3-
* See COPYING.txt for license details.
4-
*/
5-
6-
define([
7-
'jquery',
8-
'Magento_Swatches/js/swatch-renderer'
9-
], function ($, SwatchRenderer) {
10-
'use strict';
11-
12-
describe('Testing "_RenderSwatchOptions" method of SwatchRenderer Widget', function () {
13-
var widget,
14-
html,
15-
optionConfig,
16-
attribute,
17-
optionId = 2,
18-
swathImageHeight = '60',
19-
swathImageWidth = '70',
20-
swathThumbImageHeight = '40',
21-
swathThumbImageWidth = '50';
22-
23-
beforeEach(function () {
24-
widget = new SwatchRenderer();
25-
attribute = {
26-
id: 1,
27-
options: [{
28-
id: optionId
29-
}]
30-
};
31-
32-
widget.options = {
33-
classes: {
34-
optionClass: 'swatch-option'
35-
},
36-
jsonSwatchConfig: {
37-
1: {
38-
2: {
39-
type: 2
40-
}
41-
}
42-
},
43-
jsonSwatchImageSizeConfig: {
44-
swatchImage: {
45-
width: swathImageWidth,
46-
height: swathImageHeight
47-
},
48-
swatchThumb: {
49-
width: swathThumbImageWidth,
50-
height: swathThumbImageHeight
51-
}
52-
}
53-
};
54-
55-
optionConfig = widget.options.jsonSwatchConfig[attribute.id];
56-
html = $(widget._RenderSwatchOptions(attribute, 'option-label-control-id-1'))[0];
57-
});
58-
59-
it('check if swatch config has attribute id', function () {
60-
expect(widget.options.jsonSwatchConfig.hasOwnProperty(attribute.id)).toEqual(true);
61-
});
62-
63-
it('check if option config has option id', function () {
64-
expect(optionConfig.hasOwnProperty(optionId)).toEqual(true);
65-
});
66-
67-
it('check swatch thumbnail image height attribute', function () {
68-
expect(html.hasAttribute('thumb-height')).toBe(true);
69-
expect(html.getAttribute('thumb-height')).toEqual(swathThumbImageHeight);
70-
});
71-
72-
it('check swatch thumbnail image width attribute', function () {
73-
expect(html.hasAttribute('thumb-width')).toBe(true);
74-
expect(html.getAttribute('thumb-width')).toEqual(swathThumbImageWidth);
75-
});
76-
77-
it('check swatch image styles', function () {
78-
expect(html.style.height).toEqual(swathImageHeight + 'px');
79-
expect(html.style.width).toEqual(swathImageWidth + 'px');
80-
});
81-
82-
it('check udate price method', function () {
83-
var productPriceMock = {
84-
find: jasmine.createSpy().and.returnValue({
85-
hide: jasmine.createSpy(),
86-
priceBox: jasmine.createSpy().and.returnValue(''),
87-
trigger: jasmine.createSpy(),
88-
find: jasmine.createSpy().and.returnValue({
89-
toggleClass: jasmine.createSpy()
90-
})
91-
})
92-
};
93-
94-
widget.element = {
95-
parents: jasmine.createSpy().and.returnValue(productPriceMock)
96-
};
97-
widget._getNewPrices = jasmine.createSpy().and.returnValue(undefined);
98-
widget._UpdatePrice();
99-
expect(productPriceMock.find().find.calls.count()).toBe(1);
100-
});
101-
102-
it('check getSelectedOptionPriceIndex', function () {
103-
var optionMock = '<div class="swatch-attribute" attribute-id="2" option-selected="4"></div>',
104-
element = $('<div class="' + widget.options.tooltipClass +
105-
'"><div class="image"></div><div class="title"></div><div class="corner"></div>' +
106-
optionMock + '</div>'
107-
),
108-
optionPricesMock = {
109-
optionPrices: {
110-
p: {
111-
finalPrice: {
112-
amount: 12
113-
}
114-
}
115-
}
116-
};
117-
118-
widget.element = element;
119-
widget.options.classes.attributeClass = 'swatch-attribute';
120-
widget.options.jsonConfig = optionPricesMock;
121-
widget.optionsMap = {
122-
2: {
123-
4: {
124-
products: 'p'
125-
},
126-
hasOwnProperty: jasmine.createSpy().and.returnValue(true)
127-
},
128-
hasOwnProperty: jasmine.createSpy().and.returnValue(true)
129-
};
130-
131-
expect(widget._getSelectedOptionPriceIndex()).toBe('p');
132-
});
133-
});
134-
});
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'jquery',
8+
'Magento_Swatches/js/swatch-renderer'
9+
], function ($, SwatchRenderer) {
10+
'use strict';
11+
12+
describe('Testing "_RenderSwatchOptions" method of SwatchRenderer Widget', function () {
13+
var widget,
14+
html,
15+
optionConfig,
16+
attribute,
17+
optionId = 2,
18+
swathImageHeight = '60',
19+
swathImageWidth = '70',
20+
swathThumbImageHeight = '40',
21+
swathThumbImageWidth = '50';
22+
23+
beforeEach(function () {
24+
widget = new SwatchRenderer();
25+
attribute = {
26+
id: 1,
27+
options: [{
28+
id: optionId
29+
}]
30+
};
31+
32+
widget.options = {
33+
classes: {
34+
optionClass: 'swatch-option'
35+
},
36+
jsonSwatchConfig: {
37+
1: {
38+
2: {
39+
type: 2
40+
}
41+
}
42+
},
43+
jsonSwatchImageSizeConfig: {
44+
swatchImage: {
45+
width: swathImageWidth,
46+
height: swathImageHeight
47+
},
48+
swatchThumb: {
49+
width: swathThumbImageWidth,
50+
height: swathThumbImageHeight
51+
}
52+
}
53+
};
54+
55+
optionConfig = widget.options.jsonSwatchConfig[attribute.id];
56+
html = $(widget._RenderSwatchOptions(attribute, 'option-label-control-id-1'))[0];
57+
});
58+
59+
it('check if swatch config has attribute id', function () {
60+
expect(widget.options.jsonSwatchConfig.hasOwnProperty(attribute.id)).toEqual(true);
61+
});
62+
63+
it('check if option config has option id', function () {
64+
expect(optionConfig.hasOwnProperty(optionId)).toEqual(true);
65+
});
66+
67+
it('check swatch thumbnail image height attribute', function () {
68+
expect(html.hasAttribute('data-thumb-height')).toBe(true);
69+
expect(html.getAttribute('data-thumb-height')).toEqual(swathThumbImageHeight);
70+
});
71+
72+
it('check swatch thumbnail image width attribute', function () {
73+
expect(html.hasAttribute('data-thumb-width')).toBe(true);
74+
expect(html.getAttribute('data-thumb-width')).toEqual(swathThumbImageWidth);
75+
});
76+
77+
it('check swatch image styles', function () {
78+
expect(html.style.height).toEqual(swathImageHeight + 'px');
79+
expect(html.style.width).toEqual(swathImageWidth + 'px');
80+
});
81+
82+
it('check udate price method', function () {
83+
var productPriceMock = {
84+
find: jasmine.createSpy().and.returnValue({
85+
hide: jasmine.createSpy(),
86+
priceBox: jasmine.createSpy().and.returnValue(''),
87+
trigger: jasmine.createSpy(),
88+
find: jasmine.createSpy().and.returnValue({
89+
toggleClass: jasmine.createSpy()
90+
})
91+
})
92+
};
93+
94+
widget.element = {
95+
parents: jasmine.createSpy().and.returnValue(productPriceMock)
96+
};
97+
widget._getNewPrices = jasmine.createSpy().and.returnValue(undefined);
98+
widget._UpdatePrice();
99+
expect(productPriceMock.find().find.calls.count()).toBe(1);
100+
});
101+
102+
it('check getSelectedOptionPriceIndex', function () {
103+
var optionMock = '<div class="swatch-attribute" data-attribute-id="2" data-option-selected="4"></div>',
104+
element = $('<div class="' + widget.options.tooltipClass +
105+
'"><div class="image"></div><div class="title"></div><div class="corner"></div>' +
106+
optionMock + '</div>'
107+
),
108+
optionPricesMock = {
109+
optionPrices: {
110+
p: {
111+
finalPrice: {
112+
amount: 12
113+
}
114+
}
115+
}
116+
};
117+
118+
widget.element = element;
119+
widget.options.classes.attributeClass = 'swatch-attribute';
120+
widget.options.jsonConfig = optionPricesMock;
121+
widget.optionsMap = {
122+
2: {
123+
4: {
124+
products: 'p'
125+
},
126+
hasOwnProperty: jasmine.createSpy().and.returnValue(true)
127+
},
128+
hasOwnProperty: jasmine.createSpy().and.returnValue(true)
129+
};
130+
131+
expect(widget._getSelectedOptionPriceIndex()).toBe('p');
132+
});
133+
});
134+
});

0 commit comments

Comments
 (0)