Skip to content

Commit

Permalink
add bonus 48
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Jun 9, 2023
1 parent bbb16ba commit 8eb4291
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 37 deletions.
37 changes: 0 additions & 37 deletions cypress/e2e/inventory/inventory.cy.ts

This file was deleted.

40 changes: 40 additions & 0 deletions cypress/e2e/inventory/logs-add-to-cart.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { LoginPage } from '@support/pages/login.page'

describe('Inventory list', { viewportHeight: 1600 }, () => {
// create a small type on the fly using jsdoc comment
// just to help type check help us
/** @type {{username: string, password: string}} */
const user = Cypress.env('users').standard

// before each test, quickly login the user
// or restore the previous user session
beforeEach(() => {
LoginPage.login(user.username, user.password)
cy.visit('/inventory.html')
cy.location('pathname').should('equal', '/inventory.html')
})

it('calls the console.log method', () => {
// spy on the application's window "console.log" method
// https://on.cypress.io/window
// https://on.cypress.io/its
// https://on.cypress.io/spy
// give the spy an alias "log"
//
// there should be more than 1 inventory item on the page
//
// grab the 3rd inventory item
// https://on.cypress.io/eq
//
// and click on the button with the text "Add to cart"
// https://on.cypress.io/contains
// https://on.cypress.io/click

// the third item on the page should have id 1
const itemId = 1
// get the alias to the "log" spy and confirm:
// - it was called once
// - it was called once with exact parameters
// - it was called once with a string plus item id
})
})
1 change: 1 addition & 0 deletions src/components/InventoryListItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const InventoryListItem = (props) => {
}
}

console.log('add to cart item %d', itemId)
ShoppingCart.addItem(itemId)
setItemInCart(true)
dataLayer.push({ event: 'addToCart', itemId })
Expand Down

0 comments on commit 8eb4291

Please sign in to comment.