Browse Source

commits e2e test

dev
Evan You 9 years ago
parent
commit
7b180cd01b
  1. 19
      examples/commits/app.js
  2. 18
      test/e2e/custom-assertions/checked.js
  3. 18
      test/e2e/specs/commits.js

19
examples/commits/app.js

@ -1,18 +1,4 @@
var apiURL = 'https://api.github.com/repos/vuejs/vue/commits?per_page=3&sha='
var isPhantom = navigator.userAgent.indexOf('PhantomJS') > -1
/**
* Test mocks
*/
var mocks = {
master: [{sha:'111111111111', commit: {message:'one', author:{name:'Evan',date:'2014-10-15T13:52:58Z'}}},{sha:'111111111111', commit: {message:'hi', author:{name:'Evan',date:'2014-10-15T13:52:58Z'}}},{sha:'111111111111', commit: {message:'hi', author:{name:'Evan',date:'2014-10-15T13:52:58Z'}}}],
dev: [{sha:'222222222222', commit: {message:'two', author:{name:'Evan',date:'2014-10-15T13:52:58Z'}}},{sha:'111111111111', commit: {message:'hi', author:{name:'Evan',date:'2014-10-15T13:52:58Z'}}},{sha:'111111111111', commit: {message:'hi', author:{name:'Evan',date:'2014-10-15T13:52:58Z'}}}]
}
function mockData () {
this.commits = mocks[this.currentBranch]
}
/**
* Actual demo
@ -45,11 +31,6 @@ var demo = new Vue({
return v.replace(/T|Z/g, ' ')
},
fetchData: function () {
// CasperJS fails at cross-domain XHR even with
// --web-security=no, have to mock data here.
if (isPhantom) {
return mockData.call(this)
}
var xhr = new XMLHttpRequest()
var self = this
xhr.open('GET', apiURL + self.currentBranch)

18
test/e2e/custom-assertions/checked.js

@ -0,0 +1,18 @@
exports.assertion = function (selector, expected) {
this.message = 'Testing if element <' + selector + '> is checked.'
this.expected = expected !== false
this.value = function (res) {
return res.value
}
this.pass = function (val) {
return val === this.expected
}
this.command = function (cb) {
var self = this
return this.api.execute(function (selector) {
return document.querySelector(selector).checked
}, [selector], function (res) {
cb.call(self, res)
})
}
}

18
test/e2e/specs/commits.js

@ -0,0 +1,18 @@
module.exports = {
'commits': function (browser) {
browser
.url('http://localhost:8080/examples/commits/')
.waitForElementVisible('li', 1000)
.assert.elementCount('input', 2)
.assert.elementCount('label', 2)
.assert.containsText('label[for="master"]', 'master')
.assert.containsText('label[for="dev"]', 'dev')
.assert.checked('#master')
.assert.checked('#dev', false)
.assert.containsText('p', 'vuejs/vue@master')
.assert.elementCount('li', 3)
.assert.elementCount('li .commit', 3)
.assert.elementCount('li .message', 3)
.end()
}
}
Loading…
Cancel
Save