cart.spec.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { setupPuppeteer, E2E_TIMEOUT } from 'test/helpers'
  2. describe('e2e/cart', () => {
  3. const { page, text, count, click, sleep } = setupPuppeteer()
  4. async function testCart (url) {
  5. await page().goto(url)
  6. await sleep(120) // api simulation
  7. expect(await count('li')).toBe(3)
  8. expect(await count('.cart button[disabled]')).toBe(1)
  9. expect(await text('li:nth-child(1)')).toContain('iPad 4 Mini')
  10. expect(await text('.cart')).toContain('Please add some products to cart')
  11. expect(await text('.cart')).toContain('Total: $0.00')
  12. await click('li:nth-child(1) button')
  13. expect(await text('.cart')).toContain('iPad 4 Mini - $500.01 x 1')
  14. expect(await text('.cart')).toContain('Total: $500.01')
  15. await click('li:nth-child(1) button')
  16. expect(await text('.cart')).toContain('iPad 4 Mini - $500.01 x 2')
  17. expect(await text('.cart')).toContain('Total: $1,000.02')
  18. expect(await count('li:nth-child(1) button[disabled]')).toBe(1)
  19. await click('li:nth-child(2) button')
  20. expect(await text('.cart')).toContain('H&M T-Shirt White - $10.99 x 1')
  21. expect(await text('.cart')).toContain('Total: $1,011.01')
  22. await click('.cart button')
  23. await sleep(200)
  24. expect(await text('.cart')).toContain('Please add some products to cart')
  25. expect(await text('.cart')).toContain('Total: $0.00')
  26. expect(await text('.cart')).toContain('Checkout successful')
  27. expect(await count('.cart button[disabled]')).toBe(1)
  28. }
  29. test('classic', async () => {
  30. await testCart('http://localhost:8080/classic/shopping-cart/')
  31. }, E2E_TIMEOUT)
  32. test('composition', async () => {
  33. await testCart('http://localhost:8080/composition/shopping-cart/')
  34. }, E2E_TIMEOUT)
  35. })