Skip to content

Commit

Permalink
MOL-245: add cypress ui tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitalij Mik committed Feb 13, 2024
1 parent b993ee8 commit 21d29dc
Show file tree
Hide file tree
Showing 15 changed files with 273 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
<form action="{{ path('frontend.mollie.paypal-express.start', { }) }}" method="GET" >
<form id="molliePayPalExpressOffcanvasForm" action="{{ path('frontend.mollie.paypal-express.start', { }) }}" method="GET" >
<div class="mt-2 justify-content-end">
{% include '@MolliePayments/mollie/component/paypal-express-button.twig' %}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
<form action="{{ path('frontend.mollie.paypal-express.start') }}"
<form class="molliePayPalExpressProductListingForm" action="{{ path('frontend.mollie.paypal-express.start') }}"
data-form-csrf-handler="true"
method="POST">
<input type="hidden" name="productId" value="{{ product.id }}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

{% if mollie_paypalexpress_enabled and ('register' not in mollie_paypalexpress_restrictions) %}
{% block page_checkout_address_mollie_paypal_express_component %}
<form action="{{ path('frontend.mollie.paypal-express.start', { }) }}" method="GET">
<form id="molliePayPalExpressRegisterForm" action="{{ path('frontend.mollie.paypal-express.start', { }) }}" method="GET">
<div class="mt-3 mb-3">
{% include '@MolliePayments/mollie/component/paypal-express-button.twig' with {cols: 'col-5'} %}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

{% if mollie_paypalexpress_enabled and ('cart' not in mollie_paypalexpress_restrictions) %}
{% block page_checkout_aside_actions_mollie_paypal_express_component %}
<form action="{{ path('frontend.mollie.paypal-express.start', { }) }}" method="GET">
<form id="molliePayPalExpressCartForm" action="{{ path('frontend.mollie.paypal-express.start', { }) }}" method="GET">
<div class="mt-2">
{% include '@MolliePayments/mollie/component/paypal-express-button.twig' %}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@
<input
type="hidden"
name="quantity"
class="product-detail-quantity-input"
min="{{ product.minPurchase }}"
max="{{ product.calculatedMaxPurchase }}"
step="{{ product.purchaseSteps }}"
value="{{ product.minPurchase }}"
aria-label="{{ "component.product.quantitySelect.label"|trans|striptags }}"
/>
<div class="row g-2 form-row mt-2 justify-content-end">
{% include '@MolliePayments/mollie/component/paypal-express-button.twig' with {cols: 'col-8'} %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,[]);

})

Expand Down Expand Up @@ -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(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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');
})

})

});
Original file line number Diff line number Diff line change
Expand Up @@ -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('/');
Expand All @@ -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('/');
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class ShopConfigurationAction {

this.prepareShippingMethods();

this.setupPlugin(mollieFailureMode, creditCardComponents, applePayDirect, false);
this.setupPlugin(mollieFailureMode, creditCardComponents, applePayDirect, false,[]);

this._clearCache();
}
Expand All @@ -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
Expand All @@ -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);
});
});
}
Expand Down Expand Up @@ -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 = {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,9 +28,5 @@ export default class PDPAction {
} else {
repo.getQuantityDropdown().select(quantity + "");
}


repo.getAddToCartButton().click();
}

}
Loading

0 comments on commit 21d29dc

Please sign in to comment.