Skip to content

#29704 :- Submit search button in form-mini should be disabled until minimum search length is reached #29724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<!-- Filter by search query and select -->
<actionGroup name="AssertStorefrontVerifySearchButtonIsDisabledActionGroup">
<annotations>
<description>Verify search button has disabled attribute</description>
</annotations>

<grabAttributeFrom selector="{{StorefrontQuickSearchSection.searchButton}}" userInput="disabled" stepKey="grabSearchButtonDisabledAttribute"/>

<assertEquals stepKey="assertSearchButtonDisabled">
<actualResult type="const">$grabSearchButtonDisabledAttribute</actualResult>
<expectedResult type="string">true</expectedResult>
</assertEquals>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<!-- Filter by search query and select -->
<actionGroup name="AssertStorefrontVerifySearchButtonIsEnabledActionGroup">
<annotations>
<description>Verify search button does not disabled attribute</description>
</annotations>

<grabAttributeFrom selector="{{StorefrontQuickSearchSection.searchButton}}" userInput="disabled" stepKey="grabSearchButtonAttribute"/>

<assertEmpty stepKey="assertSearchButtonEnabled">
<actualResult type="string">$grabSearchButtonAttribute</actualResult>
</assertEmpty>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="StoreFrontFillSearchActionGroup">
<arguments>
<argument name="query" type="string"/>
</arguments>

<fillField stepKey="fillSearchField" selector="{{StorefrontQuickSearchSection.searchPhrase}}" userInput="{{query}}"/>
<waitForElementVisible selector="{{StorefrontQuickSearchSection.searchButton}}" stepKey="waitForSubmitButton"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="StorefrontVerifySearchButtonDisabledTillMinimumSearchLengthHitTest">
<annotations>
<stories value="Search Term Disabled"/>
<title value="Verify search button is disabled if search term is less than minimum search length"/>
<description value="Storefront verify search button is disabled if search term is less than minimum search length"/>
<severity value="AVERAGE"/>
<testCaseId value="MC-37380"/>
<group value="searchFrontend"/>
</annotations>

<actionGroup ref="StorefrontOpenHomePageActionGroup" stepKey="openStoreFrontHomePage"/>

<actionGroup ref="StoreFrontFillSearchActionGroup" stepKey="fillSearchByTextLessThanMinimumSearchLength">
<argument name="query" value="Te"/>
</actionGroup>

<actionGroup ref="AssertStorefrontVerifySearchButtonIsDisabledActionGroup" stepKey="assertSearchButtonIsDisabled"/>
</test>
</tests>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="StorefrontVerifySearchButtonEnabledAfterMinimumSearchLengthHitTest">
<annotations>
<stories value="Search Button Not Disabled"/>
<title value="Verify search button is not disabled if search term is equal or greater than minimum search length"/>
<description value="Storefront verify search button is not disabled if search term is equal or greater than minimum search length"/>
<severity value="AVERAGE"/>
<testCaseId value="MC-37381"/>
<group value="searchFrontend"/>
</annotations>

<actionGroup ref="StorefrontOpenHomePageActionGroup" stepKey="openStoreFrontHomePage"/>

<actionGroup ref="StoreFrontFillSearchActionGroup" stepKey="fillSearchByTextMoreThanMinimumSearchLength">
<argument name="query" value="Magento"/>
</actionGroup>

<actionGroup ref="AssertStorefrontVerifySearchButtonIsEnabledActionGroup" stepKey="assertSearchButtonIsNotDisabled"/>
</test>
</tests>
9 changes: 6 additions & 3 deletions app/code/Magento/Search/view/frontend/web/js/form-mini.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,10 @@ define([
break;

case $.ui.keyCode.ENTER:
this.searchForm.trigger('submit');
e.preventDefault();
if (this.element.val().length >= parseInt(this.options.minSearchLength, 10)) {
this.searchForm.trigger('submit');
e.preventDefault();
}
break;

case $.ui.keyCode.DOWN:
Expand Down Expand Up @@ -294,9 +296,10 @@ define([
dropdown = $('<ul role="listbox"></ul>'),
value = this.element.val();

this.submitBtn.disabled = isEmpty(value);
this.submitBtn.disabled = true;

if (value.length >= parseInt(this.options.minSearchLength, 10)) {
this.submitBtn.disabled = false;
$.getJSON(this.options.url, {
q: value
}, $.proxy(function (data) {
Expand Down