Skip to content

Commit ab4c545

Browse files
author
Serhii Balko
committed
Merge remote-tracking branch 'origin/MC-40240' into 2.4-develop-pr51
2 parents 0a71ba5 + 9f9b35d commit ab4c545

File tree

7 files changed

+185
-4
lines changed

7 files changed

+185
-4
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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="FilterProductGridByCustomDateRangeActionGroup">
12+
<annotations>
13+
<description>Filters the Admin Products grid by the provided Date Filter.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="code" type="string"/>
17+
<argument name="date" type="string"/>
18+
</arguments>
19+
20+
<conditionalClick selector="{{AdminProductGridFilterSection.clearFilters}}" dependentSelector="{{AdminProductGridFilterSection.clearFilters}}" visible="true" stepKey="clickClearFiltersInitial"/>
21+
<click selector="{{AdminProductGridFilterSection.filters}}" stepKey="openProductFilters"/>
22+
<fillField selector="{{AdminProductGridFilterSection.inputByCodeRangeFrom(code)}}" userInput="{{date}}" stepKey="fillProductDatetimeFromFilter"/>
23+
<fillField selector="{{AdminProductGridFilterSection.inputByCodeRangeTo(code)}}" userInput="{{date}}" stepKey="fillProductDatetimeToFilter"/>
24+
<click selector="{{AdminProductGridFilterSection.applyFilters}}" stepKey="clickApplyFilters"/>
25+
<waitForElementNotVisible selector="{{AdminProductGridSection.loadingMask}}" stepKey="waitForFilteredGridLoad" time="30"/>
26+
</actionGroup>
27+
</actionGroups>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
<element name="selectMultipleCategories" type="input" selector="//*[@data-index='container_category_ids']//*[contains(@class, '_selected')]"/>
7676
<element name="countryOfManufacture" type="select" selector="select[name='product[country_of_manufacture]']"/>
7777
<element name="newAddedAttribute" type="text" selector="//fieldset[@class='admin__fieldset']//div[contains(@data-index,'{{attributeCode}}')]" parameterized="true"/>
78+
<element name="newAddedAttributeInput" type="text" selector="//fieldset[@class='admin__fieldset']//div[contains(@data-index,'{{attributeCode}}')]//input" parameterized="true"/>
7879
<element name="newCategoryButton" type="button" selector="button[data-index='create_category_button']" timeout="30"/>
7980
<element name="footerBlock" type="block" selector="//footer"/>
8081
<element name="categories" type="text" selector="//*[@class='admin__action-multiselect-crumb']/span[contains(text(), '{{categoryName}}')]" parameterized="true"/>
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="AdminProductGridFilteringByDateWithCustomLocaleTest">
11+
<annotations>
12+
<features value="Catalog"/>
13+
<stories value="Filter products"/>
14+
<title value="Product grid date filters does not work for en_GB locale"/>
15+
<description value="Product grid date filters does not work for en_GB locale"/>
16+
<severity value="CRITICAL"/>
17+
<testCaseId value="MC-40644"/>
18+
<useCaseId value="MC-40240"/>
19+
<group value="catalog"/>
20+
</annotations>
21+
22+
<before>
23+
<!-- Deploy static content with United Kingdom locale-->
24+
<magentoCLI command="setup:static-content:deploy en_GB" stepKey="deployStaticContentWithUnitedKingdomLocale"/>
25+
<createData entity="_defaultCategory" stepKey="createCategory"/>
26+
<createData entity="SimpleProduct" stepKey="createProduct">
27+
<requiredEntity createDataKey="createCategory"/>
28+
</createData>
29+
30+
<!-- Create new User -->
31+
<actionGroup ref="AdminLoginActionGroup" stepKey="adminLogin"/>
32+
<actionGroup ref="AdminCreateUserWithRoleAndLocaleActionGroup" stepKey="createAdminUser">
33+
<argument name="user" value="activeAdmin"/>
34+
<argument name="role" value="roleDefaultAdministrator"/>
35+
<argument name="interfaceLocale" value="en_GB"/>
36+
</actionGroup>
37+
</before>
38+
<after>
39+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
40+
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
41+
<actionGroup ref="DeleteProductAttributeActionGroup" stepKey="deleteAttribute">
42+
<argument name="ProductAttribute" value="dateProductAttribute"/>
43+
</actionGroup>
44+
<actionGroup ref="AdminGridFilterResetActionGroup" stepKey="resetGridFilter"/>
45+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
46+
</after>
47+
48+
<!-- Generate date for use as default value, needs to be MM/d/YYYY and mm/d/yy -->
49+
<generateDate date="now" format="m/j/Y" stepKey="generateDefaultDate"/>
50+
<generateDate date="now" format="j/m/Y" stepKey="generateDefaultDateGB"/>
51+
52+
<!-- Navigate to Stores > Attributes > Product. -->
53+
<actionGroup ref="AdminOpenProductAttributePageActionGroup" stepKey="goToProductAttributes"/>
54+
55+
<!-- Create new Product Attribute as TextField, with code and default value. -->
56+
<actionGroup ref="CreateProductAttributeWithDateFieldActionGroup" stepKey="createAttribute">
57+
<argument name="attribute" value="dateProductAttribute"/>
58+
<argument name="date" value="{$generateDefaultDate}"/>
59+
</actionGroup>
60+
61+
<!-- Go to default attribute set edit page -->
62+
<amOnPage url="{{AdminProductAttributeSetEditPage.url}}/{{AddToDefaultSet.attributeSetId}}/" stepKey="onAttributeSetEdit"/>
63+
<!-- Assert created attribute in unassigned section -->
64+
<see userInput="{{dateProductAttribute.attribute_code}}" selector="{{AdminProductAttributeSetEditSection.unassignedAttributesTree}}" stepKey="seeAttributeInUnassigned"/>
65+
<!-- Assign attribute to a group -->
66+
<actionGroup ref="AssignAttributeToGroupActionGroup" stepKey="assignAttributeToGroup">
67+
<argument name="group" value="Product Details"/>
68+
<argument name="attribute" value="{{dateProductAttribute.attribute_code}}"/>
69+
</actionGroup>
70+
<!-- Assert attribute in a group -->
71+
<see userInput="{{dateProductAttribute.attribute_code}}" selector="{{AdminProductAttributeSetEditSection.groupTree}}" stepKey="seeAttributeInGroup"/>
72+
<!-- Save attribute set -->
73+
<actionGroup ref="SaveAttributeSetActionGroup" stepKey="SaveAttributeSet"/>
74+
75+
<!-- Open Product Edit Page and set custom attribute value -->
76+
<actionGroup ref="SearchForProductOnBackendActionGroup" stepKey="searchForProduct">
77+
<argument name="product" value="$createProduct$"/>
78+
</actionGroup>
79+
<actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="openEditProduct">
80+
<argument name="product" value="$createProduct$"/>
81+
</actionGroup>
82+
<fillField selector="{{AdminProductFormSection.newAddedAttributeInput(dateProductAttribute.attribute_code)}}" userInput="{$generateDefaultDate}" stepKey="fillCustomDateValue"/>
83+
<actionGroup ref="SaveProductFormActionGroup" stepKey="saveProduct"/>
84+
85+
<!-- Logout master admin and Login as new User -->
86+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logoutMasterAdmin"/>
87+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginToNewAdmin">
88+
<argument name="username" value="{{activeAdmin.username}}"/>
89+
<argument name="password" value="{{activeAdmin.password}}"/>
90+
</actionGroup>
91+
92+
<!-- Open Product Index Page and filter the product -->
93+
<actionGroup ref="AdminOpenProductIndexPageActionGroup" stepKey="navigateToProductIndex2"/>
94+
<actionGroup ref="FilterProductGridByCustomDateRangeActionGroup" stepKey="filterProductGridByCustomDateRange">
95+
<argument name="code" value="{{dateProductAttribute.attribute_code}}"/>
96+
<argument name="date" value="{$generateDefaultDateGB}"/>
97+
</actionGroup>
98+
<!-- Check products filtering -->
99+
<see selector="{{AdminProductGridSection.productGridNameProduct($createProduct.name$)}}" userInput="$createProduct.name$" stepKey="seeProductName"/>
100+
</test>
101+
</tests>

app/code/Magento/Ui/Component/Filters.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Ui\Component;
77

8+
use Magento\Framework\App\ObjectManager;
9+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
810
use Magento\Framework\View\Element\UiComponent\ContextInterface;
911
use Magento\Framework\View\Element\UiComponent\ObserverInterface;
1012
use Magento\Framework\View\Element\UiComponentFactory;
@@ -47,16 +49,42 @@ class Filters extends AbstractComponent implements ObserverInterface
4749
protected $uiComponentFactory;
4850

4951
/**
50-
* @inheritDoc
52+
* @var TimezoneInterface
53+
*/
54+
private $localeDate;
55+
56+
/**
57+
* Filters constructor.
58+
*
59+
* @param ContextInterface $context
60+
* @param UiComponentFactory $uiComponentFactory
61+
* @param array $components
62+
* @param array $data
63+
* @param TimezoneInterface|null $localeDate
5164
*/
5265
public function __construct(
5366
ContextInterface $context,
5467
UiComponentFactory $uiComponentFactory,
5568
array $components = [],
56-
array $data = []
69+
array $data = [],
70+
?TimezoneInterface $localeDate = null
5771
) {
5872
parent::__construct($context, $components, $data);
5973
$this->uiComponentFactory = $uiComponentFactory;
74+
$this->localeDate = $localeDate ?? ObjectManager::getInstance()->get(TimezoneInterface::class);
75+
}
76+
77+
/**
78+
* @inheritDoc
79+
*/
80+
public function prepare()
81+
{
82+
$config = $this->getData('config');
83+
// Set date format pattern by current locale
84+
$localeDateFormat = $this->localeDate->getDateFormat();
85+
$config['options']['dateFormat'] = $localeDateFormat;
86+
$this->setData('config', $config);
87+
parent::prepare();
6088
}
6189

6290
/**

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ define([
124124
*
125125
* @returns {Filters} Chainable.
126126
*/
127-
initialize: function () {
127+
initialize: function (config) {
128+
if (typeof config.options !== 'undefined' && config.options.dateFormat) {
129+
this.constructor.defaults.templates.filters.dateRange.dateFormat = config.options.dateFormat;
130+
}
128131
_.bindAll(this, 'updateActive');
129132

130133
this._super()

app/code/Magento/Ui/view/base/web/js/grid/filters/range.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ define([
5959
*
6060
* @returns {Range} Chainable.
6161
*/
62-
initialize: function () {
62+
initialize: function (config) {
63+
if (config.dateFormat) {
64+
this.constructor.defaults.templates.date.pickerDefaultDateFormat = config.dateFormat;
65+
}
6366
this._super()
6467
.initChildren();
6568

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
<!-- Create new user with role and locale setting-->
11+
<actionGroup name="AdminCreateUserWithRoleAndLocaleActionGroup" extends="AdminCreateUserWithRoleActionGroup">
12+
<arguments>
13+
<argument name="interfaceLocale" defaultValue="en_US" type="string"/>
14+
</arguments>
15+
16+
<selectOption selector="{{AdminNewUserFormSection.interfaceLocale}}" userInput="{{interfaceLocale}}" stepKey="setInterfaceLocate" after="confirmPassword"/>
17+
</actionGroup>
18+
</actionGroups>

0 commit comments

Comments
 (0)