Skip to content

Commit d3253e1

Browse files
committed
Merge remote-tracking branch 'l3/MC-38787' into BUGFIX-11-23
2 parents 11f41ef + da82d9c commit d3253e1

File tree

9 files changed

+223
-4
lines changed

9 files changed

+223
-4
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AdminSearchGridByStringNoClearActionGroup">
12+
<annotations>
13+
<description>Search the Admin grid by string without clearing filters.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="keyword" defaultValue="" type="string"/>
17+
</arguments>
18+
19+
<fillField selector="{{AdminProductGridFilterSection.keywordSearch}}" userInput="{{keyword}}" stepKey="fillKeywordSearchField"/>
20+
<click selector="{{AdminProductGridFilterSection.keywordSearchButton}}" stepKey="clickKeywordSearch"/>
21+
<waitForPageLoad stepKey="waitForProductSearch"/>
22+
</actionGroup>
23+
</actionGroups>
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminGridPageNumberSetsToOneAfterNewSearchTest">
12+
<annotations>
13+
<features value="Catalog"/>
14+
<stories value="Catalog grid"/>
15+
<title value="Updating the search keyword in admin product grid should reset current page to the first one"/>
16+
<description value="When changing the search keyword in admin product grid, new results should be displayed from the page one"/>
17+
<severity value="AVERAGE"/>
18+
<testCaseId value="MC-39332"/>
19+
<useCaseId value="MC-38787"/>
20+
<group value="Catalog"/>
21+
</annotations>
22+
23+
<before>
24+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
25+
<comment userInput="Clear product grid" stepKey="commentClearProductGrid"/>
26+
<actionGroup ref="AdminProductCatalogPageOpenActionGroup" stepKey="goToProductCatalog"/>
27+
<actionGroup ref="ResetProductGridToDefaultViewActionGroup" stepKey="resetProductGridToDefaultView"/>
28+
<actionGroup ref="DeleteProductsIfTheyExistActionGroup" stepKey="deleteProductIfTheyExist"/>
29+
30+
<!-- Create required prerequisites -->
31+
<createData entity="SimpleSubCategory" stepKey="category1"/>
32+
<createData entity="SimpleProduct" stepKey="simpleProduct1">
33+
<requiredEntity createDataKey="category1"/>
34+
</createData>
35+
<createData entity="SimpleProduct" stepKey="simpleProduct2">
36+
<requiredEntity createDataKey="category1"/>
37+
</createData>
38+
<createData entity="SimpleProduct" stepKey="simpleProduct3">
39+
<requiredEntity createDataKey="category1"/>
40+
</createData>
41+
<createData entity="SimpleProduct" stepKey="simpleProduct4">
42+
<requiredEntity createDataKey="category1"/>
43+
</createData>
44+
<createData entity="VirtualProduct" stepKey="virtualProduct1">
45+
<requiredEntity createDataKey="category1"/>
46+
</createData>
47+
<createData entity="VirtualProduct" stepKey="virtualProduct2">
48+
<requiredEntity createDataKey="category1"/>
49+
</createData>
50+
<createData entity="VirtualProduct" stepKey="virtualProduct3">
51+
<requiredEntity createDataKey="category1"/>
52+
</createData>
53+
</before>
54+
55+
<after>
56+
<actionGroup ref="AdminProductCatalogPageOpenActionGroup" stepKey="goToProductCatalog"/>
57+
<actionGroup ref="AdminDataGridDeleteCustomPerPageActionGroup" stepKey="deleteCustomAddedPerPage">
58+
<argument name="perPage" value="ProductPerPage.productCount"/>
59+
</actionGroup>
60+
<actionGroup ref="AdminClearFiltersActionGroup" stepKey="clearFilters"/>
61+
62+
<!-- Delete prerequisites -->
63+
<deleteData createDataKey="simpleProduct1" stepKey="deleteSimpleProduct1"/>
64+
<deleteData createDataKey="simpleProduct2" stepKey="deleteSimpleProduct2"/>
65+
<deleteData createDataKey="simpleProduct3" stepKey="deleteSimpleProduct3"/>
66+
<deleteData createDataKey="simpleProduct4" stepKey="deleteSimpleProduct4"/>
67+
<deleteData createDataKey="virtualProduct1" stepKey="deleteVirtualProduct1"/>
68+
<deleteData createDataKey="virtualProduct2" stepKey="deleteVirtualProduct2"/>
69+
<deleteData createDataKey="virtualProduct3" stepKey="deleteVirtualProduct3"/>
70+
<deleteData createDataKey="category1" stepKey="deleteCategory1"/>
71+
72+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
73+
</after>
74+
75+
<actionGroup ref="AdminProductCatalogPageOpenActionGroup" stepKey="goToProductCatalog"/>
76+
77+
<!-- Set the product grid to display one product per page -->
78+
<actionGroup ref="AdminDataGridSelectCustomPerPageActionGroup" stepKey="select1ProductPerPage">
79+
<argument name="perPage" value="ProductPerPage.productCount"/>
80+
</actionGroup>
81+
82+
<!-- Performing the first search and assertions -->
83+
<actionGroup ref="AdminSearchGridByStringNoClearActionGroup" stepKey="searchForSimpleProduct">
84+
<argument name="keyword" value="SimpleProduct"/>
85+
</actionGroup>
86+
<actionGroup ref="AdminGridAssertTotalPageCountActionGroup" stepKey="waitForTotalPagesCountFourToBeVisible">
87+
<argument name="expectedTotalPageCount" value="4"/>
88+
</actionGroup>
89+
<actionGroup ref="AdminGridGoToNextPageActionGroup" stepKey="clickNextPageProductGrid"/>
90+
<actionGroup ref="AdminGridAssertCurrentPageNumberActionGroup" stepKey="assertCurrentPageIsTwoOnProductGridFirstSearch">
91+
<argument name="expectedCurrentPageNumber" value="2"/>
92+
</actionGroup>
93+
94+
<!-- Performing the second search and assertions of successful current page number reset -->
95+
<actionGroup ref="AdminSearchGridByStringNoClearActionGroup" stepKey="searchForVirtualProduct">
96+
<argument name="keyword" value="VirtualProduct"/>
97+
</actionGroup>
98+
<actionGroup ref="AdminGridAssertTotalPageCountActionGroup" stepKey="waitForTotalPagesCountThreeToBeVisible">
99+
<argument name="expectedTotalPageCount" value="3"/>
100+
</actionGroup>
101+
<actionGroup ref="AdminGridAssertCurrentPageNumberActionGroup" stepKey="assertCurrentPageIsOneOnProductGridSecondSearch">
102+
<argument name="expectedCurrentPageNumber" value="1"/>
103+
</actionGroup>
104+
</test>
105+
</tests>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="AdminGridAssertCurrentPageNumberActionGroup">
11+
<annotations>
12+
<description>
13+
Assert current page number on admin grid
14+
</description>
15+
</annotations>
16+
<arguments>
17+
<argument name="expectedCurrentPageNumber" defaultValue="1" type="string"/>
18+
</arguments>
19+
20+
<seeInField selector="{{AdminDataGridPaginationSection.currentPage}}" userInput="{{expectedCurrentPageNumber}}" stepKey="seeCurrentPageNumberOnGrid"/>
21+
</actionGroup>
22+
</actionGroups>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="AdminGridAssertTotalPageCountActionGroup">
11+
<annotations>
12+
<description>
13+
Assert total page count on admin grid
14+
</description>
15+
</annotations>
16+
<arguments>
17+
<argument name="expectedTotalPageCount" defaultValue="1" type="string"/>
18+
</arguments>
19+
20+
<waitForElementVisible selector="{{AdminDataGridPaginationSection.totalPagesCount('expectedTotalPageCount')}}" stepKey="waitForTotalPagesCountToBeVisible"/>
21+
</actionGroup>
22+
</actionGroups>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="AdminGridGoToNextPageActionGroup">
11+
<annotations>
12+
<description>
13+
Go to next page of the admin grid.
14+
</description>
15+
</annotations>
16+
17+
<click selector="{{AdminDataGridPaginationSection.nextPage}}" stepKey="clickNextPageOnGrid"/>
18+
</actionGroup>
19+
</actionGroups>

app/code/Magento/Ui/Test/Mftf/Section/AdminDataGridPaginationSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<element name="previousPage" type="button" selector="div.admin__data-grid-pager > button.action-previous" timeout="30"/>
2121
<element name="currentPage" type="input" selector="div.admin__data-grid-pager > input[data-ui-id='current-page-input']"/>
2222
<element name="totalPages" type="text" selector="div.admin__data-grid-pager > label"/>
23+
<element name="totalPagesCount" type="text" selector="//div[@class='admin__data-grid-pager']//label[@class='admin__control-support-text' and .='of {{arg1}}']" parameterized="true"/>
2324
<element name="perPageDropDownValue" type="input" selector=".selectmenu-value input" timeout="30"/>
2425
<element name="selectedPage" type="input" selector="#sales_order_create_search_grid_page-current" timeout="30"/>
2526
<element name="nextPageActive" type="button" selector="div.admin__data-grid-pager > button.action-next:not(.disabled)" timeout="30"/>

app/code/Magento/Ui/view/base/web/js/grid/paging/paging.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ define([
3636
imports: {
3737
totalSelected: '${ $.selectProvider }:totalSelected',
3838
totalRecords: '${ $.provider }:data.totalRecords',
39-
filters: '${ $.provider }:params.filters'
39+
filters: '${ $.provider }:params.filters',
40+
keywordUpdated: '${ $.provider }:params.keywordUpdated'
4041
},
4142

4243
exports: {
@@ -58,7 +59,8 @@ define([
5859
'pages': 'onPagesChange',
5960
'pageSize': 'onPageSizeChange',
6061
'totalRecords': 'updateCounter',
61-
'${ $.provider }:params.filters': 'goFirst'
62+
'${ $.provider }:params.filters': 'goFirst',
63+
'${ $.provider }:params.search': 'onSearchUpdate'
6264
},
6365

6466
modules: {
@@ -282,6 +284,17 @@ define([
282284
*/
283285
onPagesChange: function () {
284286
this.updateCursor();
287+
},
288+
289+
/**
290+
* Resent the pagination to Page 1 on search keyword update
291+
*/
292+
onSearchUpdate: function () {
293+
if (!_.isUndefined(this.keywordUpdated) && this.keywordUpdated) {
294+
this.goFirst();
295+
}
296+
297+
return this;
285298
}
286299
});
287300
});

app/code/Magento/Ui/view/base/web/js/grid/search/search.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ define([
2222
placeholder: $t('Search by keyword'),
2323
label: $t('Keyword'),
2424
value: '',
25+
keywordUpdated: false,
2526
previews: [],
2627
chipsProvider: 'componentType = filtersChips, ns = ${ $.ns }',
2728
statefull: {
@@ -31,15 +32,17 @@ define([
3132
value: true,
3233
previews: true,
3334
inputValue: true,
34-
focused: true
35+
focused: true,
36+
keywordUpdated: true
3537
},
3638
imports: {
3739
inputValue: 'value',
3840
updatePreview: 'value',
3941
focused: false
4042
},
4143
exports: {
42-
value: '${ $.provider }:params.search'
44+
value: '${ $.provider }:params.search',
45+
keywordUpdated: '${ $.provider }:params.keywordUpdated'
4346
},
4447
modules: {
4548
chips: '${ $.chipsProvider }'
@@ -124,6 +127,7 @@ define([
124127
apply: function (value) {
125128
value = value || this.inputValue;
126129

130+
this.keywordUpdated = this.value !== value;
127131
this.value = this.inputValue = value.trim();
128132

129133
return this;

dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/grid/search/search.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,15 @@ define([
3737
searchObj.updatePreview();
3838
expect(searchObj.updatePreview).toHaveBeenCalled();
3939
});
40+
it('set the proper keywordUpdated value on new search keyword', function () {
41+
searchObj.value = 'keyword 1';
42+
expect(searchObj.keywordUpdated).toEqual(false);
43+
searchObj.apply('keyword 2');
44+
expect(searchObj.keywordUpdated).toEqual(true);
45+
searchObj.apply('keyword 2');
46+
expect(searchObj.keywordUpdated).toEqual(false);
47+
searchObj.apply('keyword 3');
48+
expect(searchObj.keywordUpdated).toEqual(true);
49+
});
4050
});
4151
});

0 commit comments

Comments
 (0)