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

Added test #292

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
54 changes: 51 additions & 3 deletions cypress/e2e/checkout.cy.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,59 @@
import { faker } from '@faker-js/faker';

/// <reference types='cypress' />

describe('', () => {
before(() => {
const categoryName = 'Laptops';
const product = 'Sony vaio i7';
const testMessage = 'Product added';
const cart = 'Cart';
const item = 'Sony vaio i7';

const user = {
name: `${faker.name.firstName()} ${faker.name.lastName()}`,
country: 'Canada',
city: 'Ottawa',
creditCard: {
number: faker.finance.creditCardNumber(),
expirationMonth: faker.date.month(),
expirationYear: faker.date.future({ years: 5 }).getFullYear()
Comment on lines +17 to +18

Choose a reason for hiding this comment

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

The method faker.date.future() does not accept any arguments. To get a future year, you might want to use faker.date.future().getFullYear() without passing an argument.

}
};

describe('Visit the home page', () => {
before(() => {
cy.visit('/');
});

it('', () => {
it('Should complete a flow', () => {
cy.contains(categoryName).click();
cy.contains(product).click();
cy.contains('Add to cart').click();

cy.on('window:alert', (str) => {
expect(str).to.equal(testMessage);
});

cy.contains(cart).click();
cy.get('tr').within(() => {
cy.get('td').contains(item).should('be.visible');
});

cy.contains('Place Order').click();


cy.get('#name').type(user.name);
cy.get('#country').type(user.country);
cy.get('#city').type(user.city);
cy.get('#card').type(user.creditCard.number);
cy.get('#month').type(user.creditCard.expirationMonth);
cy.get('#year').type(user.creditCard.expirationYear);
cy.contains('Purchase').click();


cy.get('.lead').should('include.text', user.name.split(' ')[0]);
cy.get('.lead').should('include.text', user.creditCard.number);
Comment on lines +53 to +54

Choose a reason for hiding this comment

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

Displaying the full credit card number in the UI might not be secure. Consider masking it or only showing the last few digits.



cy.get('button.confirm.btn.btn-lg.btn-primary').click();
});
});