Skip to content
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

Fix #29971 - Layered navigation swatches ignore show tooltip setting #30115

Open
wants to merge 3 commits into
base: 2.5-develop
Choose a base branch
from
Open
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,21 @@
<?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="AdminAssignCategoryToProductActionGroup">
<arguments>
<argument name="categoryName" type="string"/>
</arguments>
<!-- on edit Product page catalog/product/edit/id/{{product_id}}/ -->
<click selector="{{AdminProductFormSection.categoriesDropdown}}" stepKey="openDropDown"/>
<checkOption selector="{{AdminProductFormSection.selectCategory(categoryName)}}" stepKey="selectCategory"/>
<click selector="{{AdminProductFormSection.done}}" stepKey="clickDone"/>
<waitForPageLoad stepKey="waitForApplyCategory"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,9 @@

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminAssignCategoryToProductAndSaveActionGroup">
<arguments>
<argument name="categoryName" type="string"/>
</arguments>
<!-- on edit Product page catalog/product/edit/id/{{product_id}}/ -->
<click selector="{{AdminProductFormSection.categoriesDropdown}}" stepKey="openDropDown"/>
<checkOption selector="{{AdminProductFormSection.selectCategory(categoryName)}}" stepKey="selectCategory"/>
<click selector="{{AdminProductFormSection.done}}" stepKey="clickDone"/>
<waitForPageLoad stepKey="waitForApplyCategory"/>
<actionGroup name="AdminAssignCategoryToProductAndSaveActionGroup" extends="AdminAssignCategoryToProductActionGroup">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a very good cleanup. But unfortunately, it makes the PR backward-incompatible for 2.4-develop branch. There might be 3rd-party modules that extend the current action group and rely on the step keys. By removing the existing step keys we may brake such systems

<click selector="{{AdminProductFormSection.save}}" stepKey="clickSave"/>
<waitForPageLoad stepKey="waitForSavingProduct"/>
<see userInput="You saved the product." selector="{{CatalogProductsSection.messageSuccessSavedProduct}}" stepKey="seeSuccessMessage"/>
</actionGroup>
</actionGroups>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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="AdminSaveProductWithNewAttributeActionGroup">
<annotations>
<description>Clicks on the Save button. If popup related to new attribute appears, clicks on the Confirm button to close it. Validates that the Success Message is present and correct.</description>
</annotations>

<scrollToTopOfPage stepKey="scrollTopPageProduct"/>
<waitForElementVisible selector="{{AdminProductFormActionSection.saveButton}}" stepKey="waitForSaveProductButton"/>
<click selector="{{AdminProductFormActionSection.saveButton}}" stepKey="clickSaveProduct"/>
<wait time="1" stepKey="waitForPopup"/>
<conditionalClick selector="{{AdminChooseAffectedAttributeSetPopup.confirm}}"
dependentSelector="{{AdminChooseAffectedAttributeSetPopup.confirm}}" visible="true"
stepKey="clickOnConfirmInPopup"/>
<waitForElementVisible selector="{{AdminMessagesSection.success}}" stepKey="waitProductSaveSuccessMessage"/>
<see selector="{{AdminMessagesSection.success}}" userInput="You saved the product." stepKey="seeSaveConfirmation"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<element name="filterOptionByLabel" type="button" selector=" div.filter-options-item div[data-option-label='{{optionLabel}}']" parameterized="true"/>
<element name="removeFilter" type="button" selector="div.filter-current .remove"/>
<element name="activeFilterOptions" type="text" selector=".filter-options-item.active .items"/>
<element name="activeFilterOptionsByTitle" type="text" selector="//div[@class='filter-options-title' and contains(text(), '{{var1}}')]/following-sibling::*[@class='filter-options-item active'][1]/*[@class='items']" parameterized="true"/>
<element name="activeFilterOptionItemByPosition" type="text" selector=".filter-options-item.active .items li:nth-child({{itemPosition}}) a" parameterized="true"/>
<element name="enabledFilterOptionItemByLabel" type="text" selector="//div[@class='filter-options']//li[@class='item']//a[contains(text(), '{{optionLabel}}')]" parameterized="true"/>
<element name="disabledFilterOptionItemByLabel" type="text" selector="//div[@class='filter-options']//li[@class='item' and contains(text(), '{{optionLabel}}')]" parameterized="true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
</arguments>

<click selector="{{AdminProductFormConfigurationsSection.createConfigurations}}" stepKey="clickCreateConfigurations"/>
<waitForElementVisible selector="{{AdminCreateProductConfigurationsPanel.createNewAttribute}}" time="30" stepKey="waitForConfigurationModalOpen"/>
<click selector="{{AdminCreateProductConfigurationsPanel.filters}}" stepKey="clickFilters"/>
<fillField selector="{{AdminCreateProductConfigurationsPanel.attributeCode}}" userInput="{{attributeCode}}" stepKey="fillFilterAttributeCodeField"/>
<click selector="{{AdminCreateProductConfigurationsPanel.applyFilters}}" stepKey="clickApplyFiltersButton"/>
Expand All @@ -28,5 +29,6 @@
<fillField selector="{{AdminCreateProductConfigurationsPanel.quantity}}" userInput="99" stepKey="enterAttributeQuantity"/>
<click selector="{{AdminCreateProductConfigurationsPanel.next}}" stepKey="clickOnNextButton3"/>
<click selector="{{AdminCreateProductConfigurationsPanel.next}}" stepKey="clickOnNextButton4"/>
<waitForElementVisible selector="{{AdminProductFormActionSection.saveButton}}" stepKey="waitForSaveBtnVisible"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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="StorefrontExpandFilterInLayeredNavigationActionGroup">
<annotations>
<description>Expands the filter on a Storefront layered navigation if it is not expanded.</description>
</annotations>
<arguments>
<argument name="filterLabel"/>
</arguments>

<conditionalClick selector="{{StorefrontCategorySidebarSection.filterOptionsTitle(filterLabel)}}" dependentSelector="{{StorefrontCategorySidebarSection.activeFilterOptionsByTitle(filterLabel)}}" visible="false" stepKey="expandFilterOptions"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
<section name="StorefrontLayeredNavigationSection">
<element name="shoppingOptionsByName" type="button" selector="//*[text()='Shopping Options']/..//*[contains(text(),'{{arg}}')]" parameterized="true"/>
<element name="nthSwatchOption" type="button" selector="div#layered-filter-block div.swatch-option:nth-of-type({{var}})" parameterized="true"/>
</section>
</sections>
77 changes: 47 additions & 30 deletions app/code/Magento/Swatches/Model/Plugin/FilterRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,80 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Swatches\Model\Plugin;

/**
* Class FilterRenderer
*/
use Closure;
use Magento\Catalog\Model\Layer\Filter\FilterInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\View\LayoutInterface;
use Magento\LayeredNavigation\Block\Navigation\FilterRenderer as Subject;
use Magento\Swatches\Block\LayeredNavigation\RenderLayered;
use Magento\Swatches\Helper\Data;
use Magento\Swatches\ViewModel\Product\Renderer\Configurable as ConfigurableViewModel;

class FilterRenderer
{
/**
* @var \Magento\Framework\View\LayoutInterface
* @var LayoutInterface
*/
protected $layout;
private $layout;

/**
* Path to RenderLayered Block
*
* @var string
* @var Data
*/
protected $block = \Magento\Swatches\Block\LayeredNavigation\RenderLayered::class;
private $swatchHelper;

/**
* @var \Magento\Swatches\Helper\Data
* @var ConfigurableViewModel|null
*/
protected $swatchHelper;
private $configurableViewModel;

/**
* @param \Magento\Framework\View\LayoutInterface $layout
* @param \Magento\Swatches\Helper\Data $swatchHelper
* @var string
*/
private $block = RenderLayered::class;

/**
* @param LayoutInterface $layout
* @param Data $swatchHelper
* @param ConfigurableViewModel $configurableViewModel
*/
public function __construct(
\Magento\Framework\View\LayoutInterface $layout,
\Magento\Swatches\Helper\Data $swatchHelper
LayoutInterface $layout,
Data $swatchHelper,
ConfigurableViewModel $configurableViewModel
) {
$this->layout = $layout;
$this->swatchHelper = $swatchHelper;
$this->configurableViewModel = $configurableViewModel;
}

/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @param \Magento\LayeredNavigation\Block\Navigation\FilterRenderer $subject
* @param \Closure $proceed
* @param \Magento\Catalog\Model\Layer\Filter\FilterInterface $filter
* Override block rendered for swatch attribute in layered navigation
*
* @param Subject $subject
* @param Closure $proceed
* @param FilterInterface $filter
*
* @return mixed
* @throws \Magento\Framework\Exception\LocalizedException
* @throws LocalizedException
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundRender(
\Magento\LayeredNavigation\Block\Navigation\FilterRenderer $subject,
\Closure $proceed,
\Magento\Catalog\Model\Layer\Filter\FilterInterface $filter
Subject $subject,
Closure $proceed,
FilterInterface $filter
) {
if ($filter->hasAttributeModel()) {
if ($this->swatchHelper->isSwatchAttribute($filter->getAttributeModel())) {
return $this->layout
->createBlock($this->block)
->setSwatchFilter($filter)
->toHtml();
}
if ($filter->hasAttributeModel() && $this->swatchHelper->isSwatchAttribute($filter->getAttributeModel())) {
return $this->layout
->createBlock($this->block)
->setSwatchFilter($filter)
->setData('configurable_view_model', $this->configurableViewModel)
->toHtml();
}

return $proceed($filter);
}
}
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="AssertLayeredNavigationSwatchTooltipHiddenActionGroup" extends="AssertLayeredNavigationSwatchTooltipVisibleActionGroup">
<annotations>
<description>Validates that the swatch tooltip doesn't appear on layered navigation after hovering swatch.</description>
</annotations>

<remove keyForRemoval="swatchTooltipVisible"/>
<dontSeeElement selector="{{StorefrontProductInfoMainSection.swatchOptionTooltip}}" stepKey="swatchTooltipHidden"/>
</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">
<actionGroup name="AssertLayeredNavigationSwatchTooltipVisibleActionGroup">
<annotations>
<description>Validates that the swatch tooltip appears on layered navigation after hovering swatch.</description>
</annotations>
<arguments>
<argument name="nthSwatch" type="string" defaultValue="1"/>
</arguments>

<moveMouseOver selector="{{StorefrontLayeredNavigationSection.nthSwatchOption(nthSwatch)}}" stepKey="hoverSwatch"/>
<wait time="1" stepKey="waitForTooltip"/>
<seeElement selector="{{StorefrontProductInfoMainSection.swatchOptionTooltip}}" stepKey="swatchTooltipVisible"/>
</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="AssertProductPageSwatchTooltipHiddenActionGroup" extends="AssertProductPageSwatchTooltipVisibleActionGroup">
<annotations>
<description>Validates that the swatch tooltip doesn't appear on product page after hovering swatch.</description>
</annotations>

<remove keyForRemoval="swatchTooltipVisible"/>
<dontSeeElement selector="{{StorefrontProductInfoMainSection.swatchOptionTooltip}}" stepKey="swatchTooltipHidden"/>
</actionGroup>
</actionGroups>
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">
<actionGroup name="AssertProductPageSwatchTooltipVisibleActionGroup">
<annotations>
<description>Validates that the swatch tooltip appears on product page after hovering swatch.</description>
</annotations>
<arguments>
<argument name="nthSwatch" type="string" defaultValue="1"/>
</arguments>

<waitForElementVisible selector="{{StorefrontProductInfoMainSection.nthSwatchOption(nthSwatch)}}" stepKey="waitForSwatchVisible"/>
<moveMouseOver selector="{{StorefrontProductInfoMainSection.nthSwatchOption(nthSwatch)}}" stepKey="hoverSwatch"/>
<wait time="1" stepKey="waitForTooltip"/>
<seeElement selector="{{StorefrontProductInfoMainSection.swatchOptionTooltip}}" stepKey="swatchTooltipVisible"/>
</actionGroup>
</actionGroups>
Loading