This commit is contained in:
2025-01-01 15:16:24 +01:00
parent a9bf3781e0
commit 14cdc06de5
18 changed files with 1636 additions and 46 deletions

View File

@@ -0,0 +1,57 @@
const login = require("../../fixtures/login");
context("Login and buy stuff", () => {
before(() => {
cy.visit('/');
});
describe("Attempt to sign in", () => {
it('should have link to sign in', () => {
cy.get('[data-cy=signInBtn]').click();
});
it("Type data and submit form", () => {
cy.get('[data-cy=email]')
.type(login.email)
.should("have.value", login.email);
cy.get('[data-cy=password]')
.type(login.password)
.should("have.value", login.password);
cy.get('[data-cy=submit]').click();
});
});
describe("Buy stuff process", () => {
it('url should be /shop', () => {
cy.url().should("include", "/shop");
});
it('check the cart to be zero', () => {
cy.get('[data-cy=cart]').contains(0);
})
it('click on stuff 2', () => {
cy.get('[data-cy=stuff-1]').contains('Add');
cy.get('[data-cy=stuff-1]').click();
});
it('increment the cart', () => {
cy.get('[data-cy=cart]').contains(1);
})
it('click on cart', () => {
cy.get('[data-cy=cart]').click();
});
it('redirect to cart view', () => {
cy.url().should("include", "/cart");
});
it('purchase stuff and see confirm message', () => {
cy.get('[data-cy=submit]').contains('PURCHASE');
cy.get('[data-cy=submit]').click();
cy.get('[data-cy=success]').contains('Thank you for your purchase');
});
})
});

View File

@@ -0,0 +1,13 @@
describe('AppComponent', () => {
beforeEach(() => {
cy.visit('http://localhost:4200')
})
it('should display title', () => {
cy.get('h1').should('contain', 'pokedemo!')
})
it('should load the page', () => {
cy.get('app-root').should('exist')
})
})

View File

@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}

View File

@@ -0,0 +1,37 @@
/// <reference types="cypress" />
// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }

17
cypress/support/e2e.ts Normal file
View File

@@ -0,0 +1,17 @@
// ***********************************************************
// This example support/e2e.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************
// Import commands.js using ES2015 syntax:
import './commands'