Skip to content

Commit

Permalink
geoloc e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jbouzekri committed Aug 8, 2017
1 parent 6a87ec6 commit 0446cb1
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/GmaltGeoloc.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<button type="button" class="btn" @click="geolocalize()" :disabled="disabled">
<button id="geoloc-button" type="button" class="btn" @click="geolocalize()" :disabled="disabled">
<i class="fa fa-crosshairs" aria-hidden="true"></i> Use your position
</button>
</template>
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = {
browser
.waitForElementVisible('.vue-map-container .gm-style', 8000)
.execute(this.loadSinon(`
let stubedFetch = sinon.stub(window, 'fetch', function() {
let stubedFetch = sinon.stub(window, 'fetch', function() {
return Promise.resolve({status: 200, json: function() { return {alt: ${altitude}} }})
});
Expand Down
76 changes: 76 additions & 0 deletions test/e2e/specs/GmaltGeoloc.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
let helper = require('../helper')

module.exports = {
'click on geoloc button updates result on success': function (browser) {
const devServer = browser.globals.devServerURL

browser
.url(devServer)
.waitForElementVisible('.vue-map-container .gm-style', 8000)
.execute(helper.loadSinon(`
let stubedGeoloc = sinon.stub(navigator.geolocation, 'getCurrentPosition', function(success, error) {
success({coords: {latitude: 48.857868, longitude: 2.250452}})
});
let stubedFetch = sinon.stub(window, 'fetch', function() {
return Promise.resolve({status: 200, json: function() { return {alt: 789} }})
});
let sinonLoaded = document.createElement('div')
sinonLoaded.style.visibility = 'hidden'
sinonLoaded.id = 'sinonLoaded'
document.head.appendChild(sinonLoaded)
`))
.waitForElementPresent('#sinonLoaded', 3000)

browser
.click('#geoloc-button')

browser
.waitForElementPresent('.card .card-item:nth-child(1) strong', 3000)
.waitForElementPresent('.card .card-item:nth-child(2) strong', 3000)
.waitForElementPresent('.card .card-item:nth-child(3) strong', 3000)
.waitForElementPresent('.card .card-item:nth-child(4) strong', 3000)

browser
.assert.value('#form-latitude', '48.857868')
.assert.value('#form-longitude', '2.250452')
.assert.containsText('.card .card-item:nth-child(1) strong', '48.857868')
.assert.containsText('.card .card-item:nth-child(2) strong', '2.250452')
.assert.containsText('.card .card-item:nth-child(3) strong', 'Avenue de l\'Hippodrome, 75016 Paris, France')
.assert.containsText('.card .card-item:nth-child(4) strong', '789 m')
.end()
},

'click on geoloc disable button on error': function (browser) {
const devServer = browser.globals.devServerURL

browser
.url(devServer)
.waitForElementVisible('.vue-map-container .gm-style', 8000)
.execute(helper.loadSinon(`
let stubedGeoloc = sinon.stub(navigator.geolocation, 'getCurrentPosition', function(success, error) {
error()
});
let sinonLoaded = document.createElement('div')
sinonLoaded.style.visibility = 'hidden'
sinonLoaded.id = 'sinonLoaded'
document.head.appendChild(sinonLoaded)
`))
.waitForElementPresent('#sinonLoaded', 3000)

browser
.click('#geoloc-button')

browser
.assert.attributeEquals('#geoloc-button', 'disabled', 'true')
.assert.value('#form-latitude', '')
.assert.value('#form-longitude', '')
.assert.containsText('.card .card-item:nth-child(1) .card-item-value span', 'No value')
.assert.containsText('.card .card-item:nth-child(2) .card-item-value span', 'No value')
.assert.containsText('.card .card-item:nth-child(3) .card-item-value span', 'No value')
.assert.containsText('.card .card-item:nth-child(4) .card-item-value span', 'No value')
.end()
}
}
2 changes: 1 addition & 1 deletion test/e2e/specs/GmaltMap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = {
.setValue('#map-content input[type="text"]', '31 rue de rome Paris')
.waitForElementVisible('.pac-container .pac-item:first-child', 3000)
.execute(helper.loadSinon(`
let stubedFetch = sinon.stub(window, 'fetch', function() {
let stubedFetch = sinon.stub(window, 'fetch', function() {
return Promise.resolve({status: 200, json: function() { return {alt: 345} }})
});
Expand Down

0 comments on commit 0446cb1

Please sign in to comment.