1
0
Evan You 9 жил өмнө
parent
commit
024518b3b5

+ 3 - 1
examples/shopping-cart/api/shop.js

@@ -15,7 +15,9 @@ export default {
   buyProducts (products, cb, errorCb) {
     setTimeout(() => {
       // simulate random checkout failure.
-      Math.random() > 0.5 ? cb() : errorCb()
+      (Math.random() > 0.5 || navigator.userAgent.indexOf('PhantomJS') > -1)
+        ? cb()
+        : errorCb()
     }, 100)
   }
 }

+ 2 - 1
examples/shopping-cart/vuex/store.js

@@ -2,6 +2,7 @@ import Vue from 'vue'
 import Vuex from '../../../src'
 import cart from './modules/cart'
 import products from './modules/products'
+import createLogger from '../../../src/middlewares/logger'
 
 Vue.use(Vuex)
 Vue.config.debug = true
@@ -14,5 +15,5 @@ export default new Vuex.Store({
     products
   },
   strict: debug,
-  middlewares: debug ? [Vuex.createLogger()] : []
+  middlewares: debug ? [createLogger()] : []
 })

+ 36 - 0
test/e2e/cart.js

@@ -0,0 +1,36 @@
+casper.test.begin('shopping-cart', 16, function (test) {
+  casper
+  .start('examples/shopping-cart/index.html')
+  .wait(120) // api simulation
+  .then(function () {
+    test.assertElementCount('li', 3)
+    test.assertElementCount('.cart button[disabled]', 1)
+    test.assertSelectorHasText('li:nth-child(1)', 'iPad 4 Mini')
+    test.assertSelectorHasText('.cart', 'Please add some products to cart')
+    test.assertSelectorHasText('.cart', 'Total: $0.00')
+  })
+  .thenClick('li:nth-child(1) button', function () {
+    test.assertSelectorHasText('.cart', 'iPad 4 Mini - $500.01 x 1')
+    test.assertSelectorHasText('.cart', 'Total: $500.01')
+  })
+  .thenClick('li:nth-child(1) button', function () {
+    test.assertSelectorHasText('.cart', 'iPad 4 Mini - $500.01 x 2')
+    test.assertSelectorHasText('.cart', 'Total: $1,000.02')
+    test.assertElementCount('li:nth-child(1) button[disabled]', 1)
+  })
+  .thenClick('li:nth-child(2) button', function () {
+    test.assertSelectorHasText('.cart', 'H&M T-Shirt White - $10.99 x 1')
+    test.assertSelectorHasText('.cart', 'Total: $1,011.01')
+  })
+  .thenClick('.cart button')
+  .wait(120)
+  .then(function () {
+    test.assertSelectorHasText('.cart', 'Please add some products to cart')
+    test.assertSelectorHasText('.cart', 'Total: $0.00')
+    test.assertSelectorHasText('.cart', 'Checkout successful')
+    test.assertElementCount('.cart button[disabled]', 1)
+  })
+  .run(function () {
+    test.done()
+  })
+})