From 21d29dc60ea149638fad1985cc67cea09ad12038 Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Tue, 13 Feb 2024 16:47:49 +0100 Subject: [PATCH] MOL-245: add cypress ui tests --- .../checkout/offcanvas-cart.html.twig | 2 +- .../component/product/card/action.html.twig | 2 +- .../page/checkout/address/index.html.twig | 2 +- .../page/checkout/cart/index.html.twig | 2 +- .../product-detail/buy-widget-form.html.twig | 5 - .../payment-methods/creditcard.cy.js | 4 +- .../payment-methods/paypal-express.cy.js | 204 ++++++++++++++++++ .../subscriptions/subscription.cy.js | 8 +- .../actions/admin/ShopConfigurationAction.js | 10 +- .../actions/storefront/products/PDPAction.js | 12 +- .../storefront/checkout/CartRepository.js | 7 + .../checkout/OffCanvasRepository.js | 7 + .../storefront/checkout/RegisterRepository.js | 11 + .../storefront/products/ListingRepository.js | 7 + .../storefront/products/PDPRepository.js | 16 ++ 15 files changed, 273 insertions(+), 26 deletions(-) create mode 100644 tests/Cypress/cypress/e2e/storefront/payment-methods/paypal-express.cy.js create mode 100644 tests/Cypress/cypress/support/repositories/storefront/checkout/RegisterRepository.js diff --git a/src/Resources/views/storefront/component/checkout/offcanvas-cart.html.twig b/src/Resources/views/storefront/component/checkout/offcanvas-cart.html.twig index 99d2a5880..932150463 100644 --- a/src/Resources/views/storefront/component/checkout/offcanvas-cart.html.twig +++ b/src/Resources/views/storefront/component/checkout/offcanvas-cart.html.twig @@ -15,7 +15,7 @@ {% if mollie_paypalexpress_enabled and ('offcanvas' not in mollie_paypalexpress_restrictions) %} {% block component_offcanvas_cart_actions_checkout_mollie_paypal_express_component %} -
+
{% include '@MolliePayments/mollie/component/paypal-express-button.twig' %}
diff --git a/src/Resources/views/storefront/component/product/card/action.html.twig b/src/Resources/views/storefront/component/product/card/action.html.twig index b83335226..4644a7fd3 100644 --- a/src/Resources/views/storefront/component/product/card/action.html.twig +++ b/src/Resources/views/storefront/component/product/card/action.html.twig @@ -30,7 +30,7 @@ {% block component_product_box_action_buy_paypal_express %} {% if mollie_paypalexpress_enabled and ('plp' not in mollie_paypalexpress_restrictions) %} {% block component_offcanvas_cart_actions_checkout_mollie_paypal_express_component %} - diff --git a/src/Resources/views/storefront/page/checkout/address/index.html.twig b/src/Resources/views/storefront/page/checkout/address/index.html.twig index fddb020df..e0d2886de 100644 --- a/src/Resources/views/storefront/page/checkout/address/index.html.twig +++ b/src/Resources/views/storefront/page/checkout/address/index.html.twig @@ -6,7 +6,7 @@ {% if mollie_paypalexpress_enabled and ('register' not in mollie_paypalexpress_restrictions) %} {% block page_checkout_address_mollie_paypal_express_component %} - +
{% include '@MolliePayments/mollie/component/paypal-express-button.twig' with {cols: 'col-5'} %}
diff --git a/src/Resources/views/storefront/page/checkout/cart/index.html.twig b/src/Resources/views/storefront/page/checkout/cart/index.html.twig index df54b9ba8..95155cd39 100644 --- a/src/Resources/views/storefront/page/checkout/cart/index.html.twig +++ b/src/Resources/views/storefront/page/checkout/cart/index.html.twig @@ -31,7 +31,7 @@ {% if mollie_paypalexpress_enabled and ('cart' not in mollie_paypalexpress_restrictions) %} {% block page_checkout_aside_actions_mollie_paypal_express_component %} - +
{% include '@MolliePayments/mollie/component/paypal-express-button.twig' %}
diff --git a/src/Resources/views/storefront/page/product-detail/buy-widget-form.html.twig b/src/Resources/views/storefront/page/product-detail/buy-widget-form.html.twig index f5a1cd6ec..e28bf23cc 100755 --- a/src/Resources/views/storefront/page/product-detail/buy-widget-form.html.twig +++ b/src/Resources/views/storefront/page/product-detail/buy-widget-form.html.twig @@ -54,12 +54,7 @@
{% include '@MolliePayments/mollie/component/paypal-express-button.twig' with {cols: 'col-8'} %} diff --git a/tests/Cypress/cypress/e2e/storefront/payment-methods/creditcard.cy.js b/tests/Cypress/cypress/e2e/storefront/payment-methods/creditcard.cy.js index c97249dde..69ee003ff 100644 --- a/tests/Cypress/cypress/e2e/storefront/payment-methods/creditcard.cy.js +++ b/tests/Cypress/cypress/e2e/storefront/payment-methods/creditcard.cy.js @@ -265,7 +265,7 @@ describe('Status Tests', () => { devices.setDevice(devices.getFirstDevice()); // turn off credit card components // to speed up a few things - configAction.setupPlugin(false, false, false, false); + configAction.setupPlugin(false, false, false, false,[]); }) @@ -306,7 +306,7 @@ describe('Administration Tests', () => { before(function () { devices.setDevice(devices.getFirstDevice()); - configAction.setupPlugin(false, false, false, false); + configAction.setupPlugin(false, false, false, false,[]); }) beforeEach(() => { diff --git a/tests/Cypress/cypress/e2e/storefront/payment-methods/paypal-express.cy.js b/tests/Cypress/cypress/e2e/storefront/payment-methods/paypal-express.cy.js new file mode 100644 index 000000000..0f2d43d84 --- /dev/null +++ b/tests/Cypress/cypress/e2e/storefront/payment-methods/paypal-express.cy.js @@ -0,0 +1,204 @@ +import TopMenuAction from "Actions/storefront/navigation/TopMenuAction"; +import ListingAction from "Actions/storefront/products/ListingAction"; +import Devices from "Services/utils/Devices"; +import ShopConfigurationAction from "Actions/admin/ShopConfigurationAction"; +import PDPRepository from "Repositories/storefront/products/PDPRepository"; +import PDPAction from "Actions/storefront/products/PDPAction"; +import OffCanvasRepository from "Repositories/storefront/checkout/OffCanvasRepository"; +import CheckoutAction from "Actions/storefront/checkout/CheckoutAction"; +import CartRepository from "Repositories/storefront/checkout/CartRepository"; +import ListingRepository from "Repositories/storefront/products/ListingRepository"; +import RegisterRepository from "Repositories/storefront/checkout/RegisterRepository"; + + +const devices = new Devices(); +const configAction = new ShopConfigurationAction(); +const topMenu = new TopMenuAction(); +const listing = new ListingAction(); +const pdp = new PDPAction(); +const checkout = new CheckoutAction(); + +const repoPDP = new PDPRepository(); +const repoListing = new ListingRepository(); +const repoOffcanvas = new OffCanvasRepository(); +const repoCart = new CartRepository(); +const registerRepo = new RegisterRepository(); + + +describe('Paypal Express - UI Tests', () => { + + + before(function () { + devices.setDevice(devices.getFirstDevice()); + }) + + beforeEach(function () { + devices.setDevice(devices.getFirstDevice()); + }) + + describe('PDP', () => { + + it('Paypal Express button is visible @core', () => { + configAction.setupPlugin(false,false,false,false,[]); + + cy.visit('/'); + topMenu.clickOnSecondCategory(); + listing.clickOnFirstProduct(); + const quantity = 5; + pdp.setQuantity(quantity); + + repoPDP.getPayPalExpressQuantity().should('have.value',quantity); + + const button = repoPDP.getPayPalExpressButton(); + button.should('be.visible'); + button.click(); + cy.url().should('include', 'paypal.com'); + + }) + + it('Paypal Express button is hidden because of restriction @core', () => { + + configAction.setupPlugin(false,false,false,false,['pdp']); + + cy.visit('/'); + topMenu.clickOnSecondCategory(); + listing.clickOnFirstProduct(); + + repoPDP.getPayPalExpressButton().should('not.exist'); + }) + + }) + + describe('Listing', () => { + + it('Paypal Express button is visible @core', () => { + + configAction.setupPlugin(false,false,false,false,[]); + + cy.visit('/'); + topMenu.clickOnSecondCategory(); + + const button = repoListing.getPayPalExpressButton().first(); + button.should('be.visible'); + button.click(); + cy.url().should('include', 'paypal.com'); + + }) + + it('Paypal Express button is hidden because of restriction @core', () => { + + configAction.setupPlugin(false,false,false,false,['plp']); + + cy.visit('/'); + topMenu.clickOnSecondCategory(); + + repoListing.getPayPalExpressButton().should('not.exist'); + }) + }) + + + describe('Offcanvas', () => { + + it('Paypal Express button is visible @core', () => { + + configAction.setupPlugin(false,false,false,false,[]); + + cy.visit('/'); + topMenu.clickOnSecondCategory(); + listing.clickOnFirstProduct(); + pdp.addToCart(1); + + const button = repoOffcanvas.getPayPalExpressButton(); + button.should('be.visible'); + button.click(); + cy.url().should('include', 'paypal.com'); + }) + + it('Paypal Express button is hidden because of restriction @core', () => { + + configAction.setupPlugin(false,false,false,false,['offcanvas']) + + + cy.visit('/'); + topMenu.clickOnSecondCategory(); + listing.clickOnFirstProduct(); + pdp.addToCart(1); + + repoOffcanvas.getPayPalExpressButton().should('not.exist'); + }) + + }) + + describe('Cart', () => { + + it('Paypal Express button is visible @core', () => { + + configAction.setupPlugin(false,false,false,false,[]); + + cy.visit('/'); + topMenu.clickOnSecondCategory(); + listing.clickOnFirstProduct(); + pdp.addToCart(1); + + checkout.goToCartInOffCanvas(); + + const button = repoCart.getPayPalExpressButton(); + button.should('be.visible'); + button.click(); + cy.url().should('include', 'paypal.com'); + + }) + + it('Paypal Express button is hidden because of restriction @core', () => { + + configAction.setupPlugin(false,false,false,false,['cart']); + + cy.visit('/'); + topMenu.clickOnSecondCategory(); + listing.clickOnFirstProduct(); + pdp.addToCart(1); + + checkout.goToCartInOffCanvas(); + + repoCart.getPayPalExpressButton().should('not.exist'); + }) + + }) + + describe('Register Page', () => { + + it('Paypal Express button is visible @core', () => { + + configAction.setupPlugin(false,false,false,false,[]); + + cy.visit('/'); + topMenu.clickOnSecondCategory(); + listing.clickOnFirstProduct(); + pdp.addToCart(1); + + checkout.goToCheckoutInOffCanvas(); + + const button = registerRepo.getPayPalExpressButton(); + button.should('be.visible'); + button.click(); + cy.url().should('include', 'paypal.com'); + + }) + + it('Paypal Express button is hidden because of restriction @core', () => { + + configAction.setupPlugin(false,false,false,false,['register']); + + cy.visit('/'); + topMenu.clickOnSecondCategory(); + listing.clickOnFirstProduct(); + pdp.addToCart(1); + + checkout.goToCheckoutInOffCanvas(); + + registerRepo.getPayPalExpressButton().should('not.exist'); + }) + + }) + +}); \ No newline at end of file diff --git a/tests/Cypress/cypress/e2e/storefront/subscriptions/subscription.cy.js b/tests/Cypress/cypress/e2e/storefront/subscriptions/subscription.cy.js index 3baa86497..4bf1cfb2c 100644 --- a/tests/Cypress/cypress/e2e/storefront/subscriptions/subscription.cy.js +++ b/tests/Cypress/cypress/e2e/storefront/subscriptions/subscription.cy.js @@ -225,7 +225,7 @@ describe('Subscription', () => { it('C4067: Subscription Indicator on PDP can be turned ON @core', () => { configAction.updateProducts('', true, 3, 'weeks'); - configAction.setupPlugin(true, false, false, true); + configAction.setupPlugin(true, false, false, true,[]); cy.wait(2000); cy.visit('/'); @@ -241,7 +241,7 @@ describe('Subscription', () => { it('C4068: Subscription Indicator on PDP can be turned OFF @core', () => { configAction.updateProducts('', true, 3, 'weeks'); - configAction.setupPlugin(true, false, false, false); + configAction.setupPlugin(true, false, false, false,[]); cy.wait(2000); cy.visit('/'); @@ -333,7 +333,7 @@ describe('Subscription', () => { function purchaseSubscriptionAndGoToPayment(){ - configAction.setupPlugin(true, false, false, true); + configAction.setupPlugin(true, false, false, true,[]); configAction.updateProducts('', true, 3, 'weeks'); dummyUserScenario.execute(); @@ -452,7 +452,7 @@ function assertAvailablePaymentMethods() { } function prepareSubscriptionAndOpenAdminDetails() { - configAction.setupPlugin(true, false, false, true); + configAction.setupPlugin(true, false, false, true,[]); configAction.updateProducts('', true, 3, 'weeks'); const dummyScenario = new DummyBasketScenario(1) diff --git a/tests/Cypress/cypress/support/actions/admin/ShopConfigurationAction.js b/tests/Cypress/cypress/support/actions/admin/ShopConfigurationAction.js index f3231b82a..992a0bfdb 100644 --- a/tests/Cypress/cypress/support/actions/admin/ShopConfigurationAction.js +++ b/tests/Cypress/cypress/support/actions/admin/ShopConfigurationAction.js @@ -27,7 +27,7 @@ export default class ShopConfigurationAction { this.prepareShippingMethods(); - this.setupPlugin(mollieFailureMode, creditCardComponents, applePayDirect, false); + this.setupPlugin(mollieFailureMode, creditCardComponents, applePayDirect, false,[]); this._clearCache(); } @@ -40,7 +40,7 @@ export default class ShopConfigurationAction { * @param applePayDirect * @param subscriptionIndicator */ - setupPlugin(mollieFailureMode, creditCardComponents, applePayDirect, subscriptionIndicator) { + setupPlugin(mollieFailureMode, creditCardComponents, applePayDirect, subscriptionIndicator, paypalExpressRestrictions) { // assign all payment methods to // all available sales channels @@ -52,7 +52,7 @@ export default class ShopConfigurationAction { channels.forEach(channel => { this._configureSalesChannel(channel.id); - this._configureMolliePlugin(channel.id, mollieFailureMode, creditCardComponents, applePayDirect, subscriptionIndicator); + this._configureMolliePlugin(channel.id, mollieFailureMode, creditCardComponents, applePayDirect, subscriptionIndicator, paypalExpressRestrictions); }); }); } @@ -150,7 +150,7 @@ export default class ShopConfigurationAction { * @param subscriptionIndicator * @private */ - _configureMolliePlugin(channelId, mollieFailureMode, creditCardComponents, applePayDirect, subscriptionIndicator) { + _configureMolliePlugin(channelId, mollieFailureMode, creditCardComponents, applePayDirect, subscriptionIndicator,paypalExpressRestrictions) { const data = {}; const config = { @@ -173,6 +173,8 @@ export default class ShopConfigurationAction { "MolliePayments.config.subscriptionsShowIndicator": subscriptionIndicator, "MolliePayments.config.subscriptionsAllowPauseResume": true, "MolliePayments.config.subscriptionsAllowSkip": true, + // --------------------------------------------------------------- + "MolliePayments.config.paypalExpressRestrictions":paypalExpressRestrictions }; data[null] = config; // also add for "All Sales Channels" otherwise things in admin wouldnt work diff --git a/tests/Cypress/cypress/support/actions/storefront/products/PDPAction.js b/tests/Cypress/cypress/support/actions/storefront/products/PDPAction.js index 491bf2a2e..c70c14a61 100644 --- a/tests/Cypress/cypress/support/actions/storefront/products/PDPAction.js +++ b/tests/Cypress/cypress/support/actions/storefront/products/PDPAction.js @@ -2,19 +2,21 @@ import PDPRepository from 'Repositories/storefront/products/PDPRepository'; import Shopware from "Services/shopware/Shopware"; const shopware = new Shopware(); - +const repo = new PDPRepository(); export default class PDPAction { - /** * * @param quantity */ addToCart(quantity) { - const repo = new PDPRepository(); + this.setQuantity(quantity); + repo.getAddToCartButton().click(); + } + setQuantity(quantity){ if (shopware.isVersionGreaterEqual('6.5')) { const repetitions = quantity - 1; // its already 1 initially @@ -26,9 +28,5 @@ export default class PDPAction { } else { repo.getQuantityDropdown().select(quantity + ""); } - - - repo.getAddToCartButton().click(); } - } diff --git a/tests/Cypress/cypress/support/repositories/storefront/checkout/CartRepository.js b/tests/Cypress/cypress/support/repositories/storefront/checkout/CartRepository.js index 97b01098c..6a0f83347 100644 --- a/tests/Cypress/cypress/support/repositories/storefront/checkout/CartRepository.js +++ b/tests/Cypress/cypress/support/repositories/storefront/checkout/CartRepository.js @@ -8,4 +8,11 @@ export default class CartRepository { return cy.get('.mollie-apple-pay-direct-cart > div > .js-apple-pay'); } + /** + * + * @returns {Cypress.Chainable>} + */ + getPayPalExpressButton(){ + return cy.get('#molliePayPalExpressCartForm button[name="paypal-express"]'); + } } diff --git a/tests/Cypress/cypress/support/repositories/storefront/checkout/OffCanvasRepository.js b/tests/Cypress/cypress/support/repositories/storefront/checkout/OffCanvasRepository.js index 77c66d3ce..afb6d588d 100644 --- a/tests/Cypress/cypress/support/repositories/storefront/checkout/OffCanvasRepository.js +++ b/tests/Cypress/cypress/support/repositories/storefront/checkout/OffCanvasRepository.js @@ -24,4 +24,11 @@ export default class OffCanvasRepository { return cy.get('.mollie-apple-pay-direct-offcanvas > div > .js-apple-pay'); } + /** + * + * @returns {Cypress.Chainable>} + */ + getPayPalExpressButton(){ + return cy.get('#molliePayPalExpressOffcanvasForm button[name="paypal-express"]'); + } } diff --git a/tests/Cypress/cypress/support/repositories/storefront/checkout/RegisterRepository.js b/tests/Cypress/cypress/support/repositories/storefront/checkout/RegisterRepository.js new file mode 100644 index 000000000..6015eca11 --- /dev/null +++ b/tests/Cypress/cypress/support/repositories/storefront/checkout/RegisterRepository.js @@ -0,0 +1,11 @@ +export default class RegisterRepository { + + + /** + * + * @returns {Cypress.Chainable>} + */ + getPayPalExpressButton(){ + return cy.get('#molliePayPalExpressRegisterForm button[name="paypal-express"]'); + } +} \ No newline at end of file diff --git a/tests/Cypress/cypress/support/repositories/storefront/products/ListingRepository.js b/tests/Cypress/cypress/support/repositories/storefront/products/ListingRepository.js index f033d40c5..379275178 100644 --- a/tests/Cypress/cypress/support/repositories/storefront/products/ListingRepository.js +++ b/tests/Cypress/cypress/support/repositories/storefront/products/ListingRepository.js @@ -25,4 +25,11 @@ export default class ListingRepository { return cy.get('.mollie-apple-pay-direct-listing > div > .js-apple-pay'); } + /** + * + * @returns {Cypress.Chainable>} + */ + getPayPalExpressButton(){ + return cy.get('.molliePayPalExpressProductListingForm button[name="paypal-express"]') + } } diff --git a/tests/Cypress/cypress/support/repositories/storefront/products/PDPRepository.js b/tests/Cypress/cypress/support/repositories/storefront/products/PDPRepository.js index 4ceecdb18..444694f0f 100644 --- a/tests/Cypress/cypress/support/repositories/storefront/products/PDPRepository.js +++ b/tests/Cypress/cypress/support/repositories/storefront/products/PDPRepository.js @@ -44,4 +44,20 @@ export default class PDPRepository { return cy.get('.mollie-apple-pay-direct-pdp > div > .js-apple-pay'); } + /** + * + * @returns {Cypress.Chainable>} + */ + getPayPalExpressButton(){ + return cy.get('#molliePayPalExpressProductDetailForm button[name="paypal-express"]'); + } + + /** + * + * @returns {Cypress.Chainable>} + */ + getPayPalExpressQuantity(){ + return cy.get('#molliePayPalExpressProductDetailForm input[name="quantity"]'); + } + }