Skip to content

Commit 2791a45

Browse files
committed
reworked tests
1 parent 328d8e6 commit 2791a45

3 files changed

Lines changed: 74 additions & 70 deletions

File tree

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@
5656
"lint": "eslint src/ tests/",
5757
"version": "(npm run test && git add -A) || git checkout .",
5858
"server": "http-server ./ -p 8089 -s",
59-
"buildTests": "concurrently \"g4u-buildTests node_modules/guide4you tests\" \"npm run dist\"",
59+
"buildTests": "g4u-buildTests node_modules/guide4you/tests tests",
60+
"buildTestsAndEnv": "concurrently \"npm run buildTests\" \"npm run dist\"",
61+
"test": "npm run lint && npm run buildTestsAndEnv && npm run runTests && echo \"Tests completed successfully\"",
62+
"test:fast": "npm run buildTests && npm run runTests && echo \"Tests completed successfully\"",
6063
"runTests": "concurrently --kill-others --success first \"npm run server\" \"wait-on -l http-get://localhost:8089 && mocha build/tests/*\"",
61-
"test": "npm run lint && npm run buildTests && npm run runTests && echo \"Tests completed successfully\"",
6264
"doc": "esdoc -c esdoc.json"
6365
}
6466
}

tests/config.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
export default {
22
mochaTimeout: 10000,
3-
seleniumTimeout: 5000,
4-
testClient: 'http://localhost:8089/dist',
3+
testClient: 'http://localhost:8089/dist/',
54
testLayerIds: [ 0 ],
6-
testZoomBigger10: 16,
7-
testZoomSmaller10: 6,
5+
seleniumTimeouts: {
6+
script: 1000,
7+
implicit: 1000,
8+
pageLoad: 5000
9+
}
810
// testMiniMapConfigFile: 'conf/g4u-minimap.commented.json',
911
// testLayerConfigFile: 'conf/g4u-layer.uncommented.json',
10-
testVisibleCoordinate: [ 6.95333, 50.94479 ]
1112
}

tests/urlApi_spec.js

Lines changed: 64 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,62 @@
11
import { By, until } from 'selenium-webdriver'
2-
import phantomDriver from 'guide4you/tests/customPhantomDriver'
2+
import customDriver from 'guide4you/tests/customDriver'
33
import { describe, before, after, it } from 'selenium-webdriver/testing/'
44
import assert from 'selenium-webdriver/testing/assert'
55
import { waitUntilMapReady } from 'guide4you/tests/testUtils'
66

77
import config from './config.js'
88

99
// globals in browser
10-
var map, ol
11-
12-
function getMapCenter () {
13-
return ol.proj.transform(map.getView().getCenter(), 'EPSG:3857', 'EPSG:4326')
14-
}
10+
var map
1511

1612
describe('URLAPI', function () {
1713
this.timeout(config.mochaTimeout)
1814
let driver
1915

2016
before(function () {
21-
driver = phantomDriver()
17+
driver = customDriver()
2218
driver.manage().window().setSize(1200, 800)
23-
driver.manage().setTimeouts({
24-
script: config.seleniumTimeout,
25-
implicit: config.seleniumTimeout,
26-
pageLoad: config.seleniumTimeout
27-
})
19+
driver.manage().setTimeouts(config.seleniumTimeouts)
2820
})
2921

3022
after(function () {
3123
driver.quit()
3224
})
3325

3426
it('[lat, lon] should set the center of the map to the with lon and lat specified coordinates', function (done) {
35-
driver.get(config.testClient + '?lon=' + config.testVisibleCoordinate[0] + '&lat=' +
36-
config.testVisibleCoordinate[1]).then(() => {
27+
driver.get(config.testClient + '?lon=0&lat=0').then(() => {
3728
return waitUntilMapReady(driver)
3829
}).then(() => {
39-
return driver.executeScript(getMapCenter)
30+
return driver.executeScript(() => map.getView().getCenter())
4031
}).then(center => {
41-
assert(center[0]).closeTo(config.testVisibleCoordinate[0], 0.0001)
42-
assert(center[1]).closeTo(config.testVisibleCoordinate[1], 0.0001)
32+
assert(center[0]).closeTo(0, 0.0001)
33+
assert(center[1]).closeTo(0, 0.0001)
4334
done()
4435
})
4536
})
4637

4738
it('[lat, lon] if lon is missing it should not set the center of the map to the specified coordinates',
4839
function (done) {
49-
driver.get(config.testClient + '?lon=' + config.testVisibleCoordinate[0]).then(() => {
40+
driver.get(config.testClient + '?lon=0').then(() => {
5041
return waitUntilMapReady(driver)
5142
}).then(() => {
52-
return driver.executeScript(getMapCenter)
43+
return driver.executeScript(() => map.getView().getCenter())
5344
}).then(center => {
54-
assert(Math.abs(center[0] - config.testVisibleCoordinate[0])).atLeast(0.001)
55-
assert(Math.abs(center[1] - config.testVisibleCoordinate[1])).atLeast(0.001)
45+
assert(Math.abs(center[0])).atLeast(0.001)
46+
assert(Math.abs(center[1])).atLeast(0.001)
5647
done()
5748
})
5849
})
5950

6051
it('[lat, lon] if lat is missing it should not set the center of the map to the specified coordinates',
6152
function (done) {
62-
driver.get(config.testClient + '?lat=' + config.testVisibleCoordinate[1]).then(() => {
53+
driver.get(config.testClient + '?lat=0').then(() => {
6354
return waitUntilMapReady(driver)
6455
}).then(() => {
65-
return driver.executeScript(getMapCenter)
56+
return driver.executeScript(() => map.getView().getCenter())
6657
}).then(center => {
67-
assert(Math.abs(center[0] - config.testVisibleCoordinate[0])).atLeast(0.001)
68-
assert(Math.abs(center[1] - config.testVisibleCoordinate[1])).atLeast(0.001)
58+
assert(Math.abs(center[0])).atLeast(0.001)
59+
assert(Math.abs(center[1])).atLeast(0.001)
6960
done()
7061
})
7162
})
@@ -74,67 +65,78 @@ describe('URLAPI', function () {
7465
driver.get(config.testClient + '?rot=0.314').then(() => {
7566
return waitUntilMapReady(driver)
7667
}).then(() => {
77-
return driver.executeScript(function () {
78-
return map.getView().getRotation()
79-
})
68+
return driver.executeScript(() => map.getView().getRotation())
8069
}).then(rotation => {
8170
assert(rotation).closeTo(Math.PI * (0.314 / 180), 0.001)
8271
done()
8372
})
8473
})
8574

86-
it('[zoom] should zoom to the specified zoomfactor', function (done) {
87-
driver.get(config.testClient + '?zoom=' + config.testZoomBigger10).then(() => {
75+
it('[zoom] should zoom to 16', function (done) {
76+
driver.get(config.testClient + '?zoom=16').then(() => {
8877
return waitUntilMapReady(driver)
8978
}).then(() => {
90-
return driver.executeScript(function () {
91-
return window.map.getView().getZoom()
92-
})
79+
return driver.executeScript(() => window.map.getView().getZoom())
9380
}).then(zoom => {
94-
assert(zoom - 10).equalTo(config.testZoomSmaller10)
81+
assert(zoom).equalTo(16)
9582
done()
9683
})
9784
})
9885

99-
it('[marklat, marklon, marktext] should set the marker active if either marklat, marklon or marktext' +
100-
' are set to something', function (done) {
101-
function getMarkerActive () {
102-
return driver.executeScript(function () {
103-
return map.get('marker').getActive()
104-
})
105-
}
86+
it('[zoom] should zoom to 8', function (done) {
87+
driver.get(config.testClient + '?zoom=8').then(() => {
88+
return waitUntilMapReady(driver)
89+
}).then(() => {
90+
return driver.executeScript(() => window.map.getView().getZoom())
91+
}).then(zoom => {
92+
assert(zoom).equalTo(8)
93+
done()
94+
})
95+
})
10696

97+
it('[marktext] should set the marker active', function (done) {
10798
driver.get(config.testClient + '?marktext= text ').then(
10899
waitUntilMapReady(driver)
109100
).then(() => {
110-
return assert(getMarkerActive()).equalTo(true)
111-
}).then(() => {
112-
// Ist das so gewollt? Sollte das nicht analog zu lat/lon nur funktionieren, wenn beide gesetzt sind?
113-
return driver.get(config.testClient + '?marklon=' + config.testVisibleCoordinate[0]).then(
114-
waitUntilMapReady(driver)
115-
).then(() => {
116-
return assert(getMarkerActive()).equalTo(true)
117-
})
118-
}).then(() => {
119-
return driver.get(config.testClient + '?marklat=' + config.testVisibleCoordinate[1]).then(
120-
waitUntilMapReady(driver)
121-
).then(() => {
122-
return assert(getMarkerActive()).equalTo(true)
123-
})
124-
}).then(done)
101+
return driver.executeScript(() => map.get('marker').getActive())
102+
}).then(active => {
103+
assert(active).equalTo(true)
104+
done()
105+
})
106+
})
107+
108+
it('[marklat] should set the marker active', function (done) {
109+
driver.get(config.testClient + '?marklat=0').then(
110+
waitUntilMapReady(driver)
111+
).then(() => {
112+
return driver.executeScript(() => map.get('marker').getActive())
113+
}).then(active => {
114+
assert(active).equalTo(true)
115+
done()
116+
})
117+
})
118+
119+
it('[marklon] should set the marker active', function (done) {
120+
driver.get(config.testClient + '?marklon=0').then(
121+
waitUntilMapReady(driver)
122+
).then(() => {
123+
return driver.executeScript(() => map.get('marker').getActive())
124+
}).then(active => {
125+
assert(active).equalTo(true)
126+
done()
127+
})
125128
})
126129

127130
it('[marklat, marklon] should set the position of the marker to the specified coordinate', function (done) {
128-
driver.get(config.testClient + '?marklon=' + config.testVisibleCoordinate[0] + '&marklat=' +
129-
config.testVisibleCoordinate[1]).then(() => {
131+
driver.get(config.testClient + '?marklon=0&marklat=0').then(() => {
130132
return waitUntilMapReady(driver)
131133
}).then(() => {
132134
return driver.executeScript(function () {
133-
return ol.proj.transform(map.get('marker').getPosition(), 'EPSG:3857', 'EPSG:4326')
135+
return map.get('marker').getPosition() //, 'EPSG:3857', 'EPSG:4326')
134136
})
135137
}).then(markerPos => {
136-
assert(markerPos[0]).closeTo(config.testVisibleCoordinate[0], 0.0001)
137-
assert(markerPos[1]).closeTo(config.testVisibleCoordinate[1], 0.0001)
138+
assert(markerPos[0]).closeTo(0, 0.0001)
139+
assert(markerPos[1]).closeTo(0, 0.0001)
138140
done()
139141
})
140142
})
@@ -158,8 +160,7 @@ describe('URLAPI', function () {
158160
})
159161

160162
it('[markpop, marktext] should not show a feature popup if marktext is not set (1)', function (done) {
161-
driver.get(config.testClient + '?marklon=' + config.testVisibleCoordinate[0] + '&marklat=' +
162-
config.testVisibleCoordinate[1]).then(() => {
163+
driver.get(config.testClient + '?marklon=0&marklat=0').then(() => {
163164
return waitUntilMapReady(driver)
164165
}).then(() => {
165166
let featurePopup = driver.wait(until.elementLocated(By.className('g4u-featurepopup')))

0 commit comments

Comments
 (0)