From 7b180cd01b84f582408317c2ef7073fb36cd1945 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 21 Apr 2016 17:10:54 -0400 Subject: [PATCH] commits e2e test --- examples/commits/app.js | 19 ------------------- test/e2e/custom-assertions/checked.js | 18 ++++++++++++++++++ test/e2e/specs/commits.js | 18 ++++++++++++++++++ 3 files changed, 36 insertions(+), 19 deletions(-) create mode 100644 test/e2e/custom-assertions/checked.js create mode 100644 test/e2e/specs/commits.js diff --git a/examples/commits/app.js b/examples/commits/app.js index b5e8299c..7b1f03d3 100644 --- a/examples/commits/app.js +++ b/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) diff --git a/test/e2e/custom-assertions/checked.js b/test/e2e/custom-assertions/checked.js new file mode 100644 index 00000000..732e1491 --- /dev/null +++ b/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) + }) + } +} diff --git a/test/e2e/specs/commits.js b/test/e2e/specs/commits.js new file mode 100644 index 00000000..ecf3216c --- /dev/null +++ b/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() + } +}