File: D:/HostingSpaces/SBogers10/shop.komma.nl/tests/Cypress/integration/site/customer_details.spec.js
/// <reference types="Cypress" />
import PagesInfo from "../../support/pagesInfo";
const pagesInfo = new PagesInfo();
import faker from 'faker';
describe('Customer details', function() {
describe('Change cart link', function() {
it('Should send you to the cart page', function() {
cy.clearCookies();
cy.request('GET', '/testapi/v1/cart/addToCart', {
items: [
{'productable_type' : 'product', 'id' : 2, 'quantity': 2}, //Hammer
]
}).then(function(response) {
cy.visit(pagesInfo.getByName('customer_details').locations.nl)
cy.get('[data-test="change-cart"]').click()
cy.url().should('contain', pagesInfo.getByName('cart').locations.nl);
})
});
});
describe('Contact details', function() {
it('Should be possible to enter contact details', function() {
cy.clearCookies();
cy.request('GET', '/testapi/v1/cart/addToCart', {
items: [
{'productable_type' : 'product', 'id' : 2, 'quantity': 2}, //Hammer
]
}).then(function(response) {
const contactDetails = {
firstName: faker.name.firstName(),
lastNamePrefix: faker.random.arrayElement(['van de', 'de', 'aan', 'aan de', 'ten', 'over den']),
lastName: faker.name.lastName(),
email: faker.internet.email(),
phone: faker.phone.phoneNumberFormat()
}
cy.visit(pagesInfo.getByName('customer_details').locations.nl)
cy.get('[data-test="first_name"]').should('have.value', '');
cy.get('[data-test="first_name"]').type(contactDetails.firstName)
cy.get('[data-test="first_name"]').should('have.value', contactDetails.firstName);
cy.get('[data-test="last_name_prefix"]').should('have.value', '');
cy.get('[data-test="last_name_prefix"]').type(contactDetails.lastNamePrefix)
cy.get('[data-test="last_name_prefix"]').should('have.value', contactDetails.lastNamePrefix);
cy.get('[data-test="last_name"]').should('have.value', '');
cy.get('[data-test="last_name"]').type(contactDetails.lastName)
cy.get('[data-test="last_name"]').should('have.value', contactDetails.lastName);
cy.get('[data-test="email"]').should('have.value', '');
cy.get('[data-test="email"]').type(contactDetails.email)
cy.get('[data-test="email"]').should('have.value', contactDetails.email);
cy.get('[data-test="phone"]').should('have.value', '');
cy.get('[data-test="phone"]').type(contactDetails.phone)
cy.get('[data-test="phone"]').should('have.value', contactDetails.phone);
});
})
});
describe('Should be possible to enter invoice details', function() {
it('Should be possible to enter invoice detail text fields', function() {
cy.clearCookies();
cy.request('GET', '/testapi/v1/cart/addToCart', {
items: [
{'productable_type' : 'product', 'id' : 2, 'quantity': 2}, //Hammer
]
}).then(function(response) {
const invoiceDetails = {
postalCode: faker.address.zipCode(),
city: faker.address.city(),
streetName: faker.address.streetName(),
houseNumber: faker.address.streetAddress(),
}
cy.visit(pagesInfo.getByName('customer_details').locations.nl)
cy.get('[data-test="invoice_street"]').should('have.value', '');
cy.get('[data-test="invoice_street"]').type(invoiceDetails.streetName)
cy.get('[data-test="invoice_street"]').should('have.value', invoiceDetails.streetName);
cy.get('[data-test="invoice_house_number"]').should('have.value', '');
cy.get('[data-test="invoice_house_number"]').type(invoiceDetails.houseNumber)
cy.get('[data-test="invoice_house_number"]').should('have.value', invoiceDetails.houseNumber);
cy.get('[data-test="invoice_postal_code"]').should('have.value', '');
cy.get('[data-test="invoice_postal_code"]').type(invoiceDetails.postalCode)
cy.get('[data-test="invoice_postal_code"]').should('have.value', invoiceDetails.postalCode);
cy.get('[data-test="invoice_city"]').should('have.value', '');
cy.get('[data-test="invoice_city"]').type(invoiceDetails.city)
cy.get('[data-test="invoice_city"]').should('have.value', invoiceDetails.city);
});
})
it('Country select initially shows the same value as given on the cart page', function() {
cy.clearCookies();
cy.request('GET', '/testapi/v1/cart/addToCart', {
items: [
{'productable_type' : 'product', 'id' : 2, 'quantity': 2}, //Hammer
]
}) //This request is ran first...
//Change the country to United kingdom in the cart and checkout
cy.visit(pagesInfo.getByName('cart').locations.nl)
cy.get('[data-test="shipping-country"]').select('GBR');
cy.get('[data-test="checkout"]').click();
//...Then verify that the country select for invoice is set to that value too
cy.get('[data-test="invoice_country"]').should('have.value', 'GBR')
})
it('Shipping address is the same as Invoice address checkbox is checked by default', function() {
cy.clearCookies();
cy.request('GET', '/testapi/v1/cart/addToCart', {
items: [
{'productable_type' : 'product', 'id' : 2, 'quantity': 2}, //Hammer
]
}) //This request is ran first...
cy.visit(pagesInfo.getByName('customer_details').locations.nl)
cy.get('[data-test="shipping-address-equals"]').should('be.checked');
})
});
describe('Should be possible to enter shipping details', function() {
it('Should be possible to enter shipping detail text fields', function() {
cy.clearCookies();
cy.request('GET', '/testapi/v1/cart/addToCart', {
items: [
{'productable_type' : 'product', 'id' : 2, 'quantity': 2}, //Hammer
]
}).then(function(response) {
const shippingDetails = {
postalCode: faker.address.zipCode(),
city: faker.address.city(),
streetName: faker.address.streetName(),
houseNumber: faker.address.streetAddress(),
}
cy.visit(pagesInfo.getByName('customer_details').locations.nl)
cy.get('[data-test="shipping-address-equals"]').should('be.checked');
cy.get('[data-test="shipping_street"]').should('not.be.visible');
cy.get('[data-test="shipping-address-equals"]').uncheck();
cy.get('[data-test="shipping_street"]').should('have.value', '');
cy.get('[data-test="shipping_street"]').type(shippingDetails.streetName)
cy.get('[data-test="shipping_street"]').should('have.value', shippingDetails.streetName);
cy.get('[data-test="shipping_house_number"]').should('have.value', '');
cy.get('[data-test="shipping_house_number"]').type(shippingDetails.houseNumber)
cy.get('[data-test="shipping_house_number"]').should('have.value', shippingDetails.houseNumber);
cy.get('[data-test="shipping_postal_code"]').should('have.value', '');
cy.get('[data-test="shipping_postal_code"]').type(shippingDetails.postalCode)
cy.get('[data-test="shipping_postal_code"]').should('have.value', shippingDetails.postalCode);
cy.get('[data-test="shipping_city"]').should('have.value', '');
cy.get('[data-test="shipping_city"]').type(shippingDetails.city)
cy.get('[data-test="shipping_city"]').should('have.value', shippingDetails.city);
});
})
it('Country select initially shows the same value as given on the cart page', function() {
cy.clearCookies();
cy.request('GET', '/testapi/v1/cart/addToCart', {
items: [
{'productable_type' : 'product', 'id' : 2, 'quantity': 2}, //Hammer
]
}) //This request is ran first...
//Change the country to United kingdom in the cart and checkout
cy.visit(pagesInfo.getByName('cart').locations.nl)
cy.get('[data-test="shipping-country"]').select('GBR');
cy.get('[data-test="checkout"]').click();
//...Then verify that the country select for shipping is set to that value too
cy.get('[data-test="shipping-address-equals"]').uncheck();
cy.get('[data-test="shipping_country"]').should('have.value', 'GBR')
})
});
describe('Continue button', function() {
it('Should show field errors when clicking it when form is invalid', function() {
cy.clearCookies();
cy.request('GET', '/testapi/v1/cart/addToCart', {
items: [
{'productable_type' : 'product', 'id' : 2, 'quantity': 2}, //Hammer
]
}) //This request is ran first...
cy.visit(pagesInfo.getByName('customer_details').locations.nl)
cy.get('[data-test="first_name-error"]').should('not.be.visible')
cy.get('[data-test="last_name-error"]').should('not.be.visible')
cy.get('[data-test="email-error"]').should('not.be.visible')
cy.get('[data-test="invoice_street-error"]').should('not.be.visible')
cy.get('[data-test="invoice_house_number-error"]').should('not.be.visible')
cy.get('[data-test="invoice_postal_code-error"]').should('not.be.visible')
cy.get('[data-test="invoice_city-error"]').should('not.be.visible')
cy.get('[data-test="shipping-address-equals"]').uncheck();
cy.get('[data-test="continue"]').click({force: true})
cy.get('[data-test="first_name-error"]').should('be.visible')
cy.get('[data-test="last_name-error"]').should('be.visible')
cy.get('[data-test="email-error"]').should('be.visible')
cy.get('[data-test="invoice_street-error"]').should('be.visible')
cy.get('[data-test="invoice_house_number-error"]').should('be.visible')
cy.get('[data-test="invoice_postal_code-error"]').should('be.visible')
cy.get('[data-test="invoice_city-error"]').should('be.visible')
});
it('Should continue to the confirmation page when form is valid', function() {
cy.clearCookies();
cy.request('GET', '/testapi/v1/cart/addToCart', {
items: [
{'productable_type' : 'product', 'id' : 2, 'quantity': 2}, //Hammer
]
}).then(function(response) {
const contactDetails = {
firstName: faker.name.firstName(),
lastNamePrefix: faker.random.arrayElement(['van de', 'de', 'aan', 'aan de', 'ten', 'over den']),
lastName: faker.name.lastName(),
email: faker.internet.email(),
phone: faker.phone.phoneNumberFormat()
}
const invoiceDetails = {
postalCode: faker.address.zipCode(),
city: faker.address.city(),
streetName: faker.address.streetName(),
houseNumber: faker.address.streetAddress(),
}
const shippingDetails = {
postalCode: faker.address.zipCode(),
city: faker.address.city(),
streetName: faker.address.streetName(),
houseNumber: faker.address.streetAddress(),
}
cy.visit(pagesInfo.getByName('customer_details').locations.nl)
cy.get('[data-test="first_name"]').type(contactDetails.firstName)
cy.get('[data-test="last_name_prefix"]').type(contactDetails.lastNamePrefix)
cy.get('[data-test="last_name"]').type(contactDetails.lastName)
cy.get('[data-test="email"]').type(contactDetails.email)
cy.get('[data-test="phone"]').type(contactDetails.phone)
cy.get('[data-test="invoice_street"]').type(invoiceDetails.streetName)
cy.get('[data-test="invoice_house_number"]').type(invoiceDetails.houseNumber)
cy.get('[data-test="invoice_postal_code"]').type(invoiceDetails.postalCode)
cy.get('[data-test="invoice_city"]').type(invoiceDetails.city)
cy.get('[data-test="shipping-address-equals"]').uncheck();
cy.get('[data-test="shipping_street"]').type(shippingDetails.streetName)
cy.get('[data-test="shipping_house_number"]').type(shippingDetails.houseNumber)
cy.get('[data-test="shipping_postal_code"]').type(shippingDetails.postalCode)
cy.get('[data-test="shipping_city"]').type(shippingDetails.city)
cy.get('[data-test="continue"]').click({force: true})
});
});
});
});