Skip to content

Commit

Permalink
test: ensure the cart works
Browse files Browse the repository at this point in the history
  • Loading branch information
jottaveDev committed Oct 31, 2024
1 parent 4441666 commit 71aaf89
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
9 changes: 5 additions & 4 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { defineConfig } from "cypress";
import { defineConfig } from 'cypress'

export default defineConfig({
component: {
devServer: {
framework: "next",
bundler: "webpack",
framework: 'next',
bundler: 'webpack',
},
},

e2e: {
baseUrl: 'http://localhost:3000',
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
})
55 changes: 55 additions & 0 deletions cypress/e2e/add-product-to-cart.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
describe('Cart', () => {
beforeEach(() => {
cy.visit('http://localhost:3000')
})

it('should open cart modal', () => {
cy.get('a[href^="/product"]').first().click()
cy.location('pathname').should('include', '/product')

cy.contains('Cart').click()
cy.contains('Meu Carrinho').should('exist')
})

it('should close cart modal', () => {
cy.get('a[href^="/product"]').first().click()
cy.location('pathname').should('include', '/product')

cy.contains('Cart').click()
cy.get('button').first().click()
cy.contains('Meu Carrinho').should('not.exist')
})

it('should be able to navigate to the product page and it to the cart', () => {
cy.get('a[href^="/product"]').first().click()
cy.location('pathname').should('include', '/product')

cy.contains('GG').click()

cy.contains('Adicionar ao carrinho').click()
cy.contains('adicionado ao carrinho :)').should('exist')
})

it('should not add to cart without selecting size', () => {
cy.get('a[href^="/product"]').first().click()
cy.location('pathname').should('include', '/product')

cy.contains('Adicionar ao carrinho').click()
cy.contains('adicionado ao carrinho :)').should('not.exist')
cy.contains('selecione um tamanho antes de adicionar ao carrinho').should(
'exist',
)
})

it('should be able to search for a product and add it to the cart', () => {
cy.get('input[name=q]').type('moletom').parent('form').submit()

cy.get('a[href^="/product"]').first().click()
cy.location('pathname').should('include', '/product')

cy.contains('GG').click()

cy.contains('Adicionar ao carrinho').click()
cy.contains('adicionado ao carrinho :)').should('exist')
})
})

0 comments on commit 71aaf89

Please sign in to comment.