Skip to content

Commit

Permalink
Issue#24785: Added JS method to handle input checks with MFTF
Browse files Browse the repository at this point in the history
  • Loading branch information
drpayyne committed Oct 6, 2019
1 parent 6f1a6f7 commit a289dc4
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 0 deletions.
Expand Up @@ -15,5 +15,6 @@
<element name="downloadableLinkSampleByTitle" type="text" selector="//label[contains(., '{{title}}')]/a[contains(@class, 'sample link')]" parameterized="true"/>
<element name="downloadableSampleLabel" type="text" selector="//a[contains(.,normalize-space('{{title}}'))]" parameterized="true" timeout="30"/>
<element name="downloadableLinkSelectAllCheckbox" type="checkbox" selector="#links_all" />
<element name="downloadableLinkSelectAllLabel" type="text" selector="label[for='links_all']" />
</section>
</sections>
@@ -0,0 +1,122 @@
<?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="ManualSelectAllDownloadableLinksDownloadableProductTest">
<annotations>
<features value="Catalog"/>
<stories value="Create Downloadable Product"/>
<title value="Manual select all downloadable links downloadable product test"/>
<description value="Manually selecting all downloadable links must change 'Select/Unselect all' button label to 'Unselect all', and 'Select all' otherwise"/>
<severity value="MAJOR"/>
<group value="Downloadable"/>
</annotations>
<before>
<!-- Create category -->
<createData entity="SimpleSubCategory" stepKey="createCategory"/>

<!-- Login as admin -->
<actionGroup ref="LoginAsAdmin" stepKey="LoginAsAdmin"/>

<!-- Create downloadable product -->
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="amOnProductGridPage"/>
<waitForPageLoad stepKey="waitForProductGridPageLoad"/>
<actionGroup ref="GoToSpecifiedCreateProductPage" stepKey="createProduct">
<argument name="productType" value="downloadable"/>
</actionGroup>

<!-- Fill downloadable product values -->
<actionGroup ref="fillMainProductFormNoWeight" stepKey="fillDownloadableProductForm">
<argument name="product" value="DownloadableProduct"/>
</actionGroup>

<!-- Add downloadable product to category -->
<searchAndMultiSelectOption selector="{{AdminProductFormSection.categoriesDropdown}}"
parameterArray="[$$createCategory.name$$]" stepKey="fillCategory"/>

<!-- Fill downloadable link information before the creation link -->
<actionGroup ref="AdminAddDownloadableLinkInformationActionGroup" stepKey="addDownloadableLinkInformation"/>

<!-- Links can be purchased separately -->
<checkOption selector="{{AdminProductDownloadableSection.isLinksPurchasedSeparately}}"
stepKey="checkOptionPurchaseSeparately"/>

<!-- Add first downloadable link -->
<actionGroup ref="addDownloadableProductLinkWithMaxDownloads" stepKey="addFirstDownloadableProductLink">
<argument name="link" value="downloadableLinkWithMaxDownloads"/>
</actionGroup>

<!-- Add second downloadable link -->
<actionGroup ref="addDownloadableProductLink" stepKey="addSecondDownloadableProductLink">
<argument name="link" value="downloadableLink"/>
</actionGroup>

<!-- Save product -->
<actionGroup ref="saveProductForm" stepKey="saveProduct"/>
</before>
<after>
<!-- Delete category -->
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>

<!-- Delete created downloadable product -->
<actionGroup ref="deleteProductUsingProductGrid" stepKey="deleteProduct">
<argument name="product" value="DownloadableProduct"/>
</actionGroup>

<!-- Log out -->
<actionGroup ref="logout" stepKey="logout"/>
</after>

<!-- Step 1: Navigate to store front Product page as guest -->
<amOnPage url="/{{DownloadableProduct.sku}}.html"
stepKey="amOnStorefrontProductPage"/>

<!-- Step 2: Check first downloadable link checkbox -->
<click
selector="{{StorefrontDownloadableProductSection.downloadableLinkByTitle(downloadableLinkWithMaxDownloads.title)}}"
stepKey="selectFirstCheckbox"/>

<!-- Step 3: Check second downloadable link checkbox -->
<click
selector="{{StorefrontDownloadableProductSection.downloadableLinkByTitle(downloadableLink.title)}}"
stepKey="selectSecondCheckbox"/>

<!-- Step 4: Grab "Select/Unselect All" button label text -->
<grabTextFrom
selector="{{StorefrontDownloadableProductSection.downloadableLinkSelectAllLabel}}"
stepKey="grabUnselectAllButtonText"/>

<!-- Step 5: Assert that 'Select/Unselect all' button text is 'Unselect all' after manually checking all checkboxes -->
<assertEquals
message="Assert that 'Select/Unselect all' button text is 'Unselect all' after manually checking all checkboxes"
stepKey="assertButtonTextOne">
<expectedResult type="string">Unselect all</expectedResult>
<actualResult type="string">{$grabUnselectAllButtonText}</actualResult>
</assertEquals>

<!-- Step 6: Uncheck second downloadable link checkbox -->
<click
selector="{{StorefrontDownloadableProductSection.downloadableLinkByTitle(downloadableLink.title)}}"
stepKey="unselectSecondCheckbox"/>

<!-- Step 7: Grab "Select/Unselect All" button label text -->
<grabTextFrom
selector="{{StorefrontDownloadableProductSection.downloadableLinkSelectAllLabel}}"
stepKey="grabSelectAllButtonText"/>

<!-- Step 8: Assert that 'Select/Unselect all' button text is 'Select all' after manually unchecking one checkbox -->
<assertEquals
message="Assert that 'Select/Unselect all' button text is 'Select all' after manually unchecking one checkbox"
stepKey="assertButtonTextTwo">
<expectedResult type="string">Select all</expectedResult>
<actualResult type="string">{$grabSelectAllButtonText}</actualResult>
</assertEquals>

</test>
</tests>
25 changes: 25 additions & 0 deletions app/code/Magento/Downloadable/view/frontend/web/js/downloadable.js
Expand Up @@ -65,6 +65,31 @@ define([
}
}
});

this.reloadAllCheckText();
},

/**
* Reload all-elements-checkbox's label
* @private
*/
reloadAllCheckText: function () {
let allChecked = true,
allElementsCheck = $(this.options.allElements),
allElementsLabel = $('label[for="' + allElementsCheck.attr('id') + '"] > span');
$(this.options.linkElement).each(function () {
if (!this.checked) {
allChecked = false;
}
});

if (allChecked) {
allElementsLabel.text(allElementsCheck.attr('data-checked'));
allElementsCheck.prop('checked', true)
} else {
allElementsLabel.text(allElementsCheck.attr('data-notchecked'));
allElementsCheck.prop('checked', false)
}
}
});

Expand Down

0 comments on commit a289dc4

Please sign in to comment.