Skip to content

Commit 024518b

Browse files
committed
e2e tests for cart
1 parent 793d52c commit 024518b

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

examples/shopping-cart/api/shop.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ export default {
1515
buyProducts (products, cb, errorCb) {
1616
setTimeout(() => {
1717
// simulate random checkout failure.
18-
Math.random() > 0.5 ? cb() : errorCb()
18+
(Math.random() > 0.5 || navigator.userAgent.indexOf('PhantomJS') > -1)
19+
? cb()
20+
: errorCb()
1921
}, 100)
2022
}
2123
}

examples/shopping-cart/vuex/store.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Vue from 'vue'
22
import Vuex from '../../../src'
33
import cart from './modules/cart'
44
import products from './modules/products'
5+
import createLogger from '../../../src/middlewares/logger'
56

67
Vue.use(Vuex)
78
Vue.config.debug = true
@@ -14,5 +15,5 @@ export default new Vuex.Store({
1415
products
1516
},
1617
strict: debug,
17-
middlewares: debug ? [Vuex.createLogger()] : []
18+
middlewares: debug ? [createLogger()] : []
1819
})

test/e2e/cart.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
casper.test.begin('shopping-cart', 16, function (test) {
2+
casper
3+
.start('examples/shopping-cart/index.html')
4+
.wait(120) // api simulation
5+
.then(function () {
6+
test.assertElementCount('li', 3)
7+
test.assertElementCount('.cart button[disabled]', 1)
8+
test.assertSelectorHasText('li:nth-child(1)', 'iPad 4 Mini')
9+
test.assertSelectorHasText('.cart', 'Please add some products to cart')
10+
test.assertSelectorHasText('.cart', 'Total: $0.00')
11+
})
12+
.thenClick('li:nth-child(1) button', function () {
13+
test.assertSelectorHasText('.cart', 'iPad 4 Mini - $500.01 x 1')
14+
test.assertSelectorHasText('.cart', 'Total: $500.01')
15+
})
16+
.thenClick('li:nth-child(1) button', function () {
17+
test.assertSelectorHasText('.cart', 'iPad 4 Mini - $500.01 x 2')
18+
test.assertSelectorHasText('.cart', 'Total: $1,000.02')
19+
test.assertElementCount('li:nth-child(1) button[disabled]', 1)
20+
})
21+
.thenClick('li:nth-child(2) button', function () {
22+
test.assertSelectorHasText('.cart', 'H&M T-Shirt White - $10.99 x 1')
23+
test.assertSelectorHasText('.cart', 'Total: $1,011.01')
24+
})
25+
.thenClick('.cart button')
26+
.wait(120)
27+
.then(function () {
28+
test.assertSelectorHasText('.cart', 'Please add some products to cart')
29+
test.assertSelectorHasText('.cart', 'Total: $0.00')
30+
test.assertSelectorHasText('.cart', 'Checkout successful')
31+
test.assertElementCount('.cart button[disabled]', 1)
32+
})
33+
.run(function () {
34+
test.done()
35+
})
36+
})

0 commit comments

Comments
 (0)