Skip to content
This repository was archived by the owner on Sep 20, 2019. It is now read-only.

Commit 50a63c1

Browse files
committed
fix(test): fix some unit test for markers, geojson and leafletData, fix #347
1 parent 21266dd commit 50a63c1

8 files changed

+160
-102
lines changed

dist/ui-leaflet.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ui-leaflet.min.js

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ui-leaflet.min.no-header.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ui-leaflet_dev_mapped.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = (karma) => {
2424
}]
2525
},
2626

27-
reporters: ['mocha', 'coverage'],
27+
reporters: ['dots', 'coverage'],
2828

2929
coffeePreprocessor: {
3030
options: {

test/unit/leafletData/leafletDataService.DirectiveControlsSpec.coffee

Lines changed: 65 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -65,34 +65,40 @@ describe 'leafletData directiveControls', ->
6565

6666
element = angular.element markup
6767
element = $compile(element)($rootScope)
68+
element
6869

69-
$rootScope.$digest()
70-
71-
if Array.isArray id
72-
return $q.all id.map (anId) ->
73-
leafletData.getDirectiveControls(anId)
74-
75-
leafletData.getDirectiveControls(id)
7670

7771
['markers', 'geojson'].forEach (directiveName) ->
7872
describe "#{directiveName} controls", ->
7973
beforeEach ->
8074
@rootName = directiveName
81-
@controlsPromise = @testRunner()
75+
@element = @testRunner()
8276

83-
it 'root', () ->
84-
@controlsPromise
85-
.then (controls) =>
86-
expect(controls[@rootName]).toBeDefined()
87-
it 'create', ->
88-
@controlsPromise
89-
.then (controls) =>
90-
expect(controls[@rootName].create).toBeDefined()
91-
it 'clean', ->
92-
@controlsPromise
93-
.then (controls) =>
94-
expect(controls[@rootName].clean).toBeDefined()
77+
it 'root', (done) ->
78+
element = @element
79+
rootName = @rootName
80+
@digest $rootScope, ->
81+
leafletData.getDirectiveControls().then (controls) ->
82+
expect(controls[rootName]).toBeDefined()
83+
done()
84+
return
9585

86+
it 'create', (done) ->
87+
element = @element
88+
rootName = @rootName
89+
@digest $rootScope, ->
90+
leafletData.getDirectiveControls().then (controls) ->
91+
expect(controls[rootName].create).toBeDefined()
92+
done()
93+
return
94+
it 'clean', (done) ->
95+
element = @element
96+
rootName = @rootName
97+
@digest $rootScope, ->
98+
leafletData.getDirectiveControls().then (controls) ->
99+
expect(controls[rootName].clean).toBeDefined()
100+
done()
101+
return
96102

97103
describe "#{directiveName} MANY controls", ->
98104
beforeEach ->
@@ -101,21 +107,43 @@ describe 'leafletData directiveControls', ->
101107
<leaflet id="map1" markers='markers' geojson='geojson'></leaflet>
102108
<leaflet id="map2" markers='markers' geojson='geojson'></leaflet>
103109
"""
104-
@controlsPromise = @testRunner(markup, ['map1', 'map2'])
110+
@ids = ['map1', 'map2']
111+
@element = @testRunner(markup, @ids)
105112

106-
it 'root', ->
107-
@controlsPromise
108-
.then (controls) =>
109-
expect(controls.length).toBe(2)
110-
controls.forEach (c) =>
111-
expect(c[@rootName]).toBeDefined()
112-
it 'create', ->
113-
@controlsPromise
114-
.then (controls) =>
115-
controls.forEach (c) =>
116-
expect(c[@rootName].create).toBeDefined()
117-
it 'clean', ->
118-
@controlsPromise
119-
.then (controls) =>
120-
controls.forEach (c) =>
121-
expect(c[@rootName].clean).toBeDefined()
113+
it 'root', (done) ->
114+
element = @element
115+
rootName = @rootName
116+
ids = @ids
117+
@digest $rootScope, ->
118+
promise = $q.all ids.map (anId) ->
119+
leafletData.getDirectiveControls(anId)
120+
promise.then (controls) ->
121+
expect(controls.length).toBe(2)
122+
controls.forEach (c) =>
123+
expect(c[rootName]).toBeDefined()
124+
done()
125+
return
126+
it 'create', (done) ->
127+
element = @element
128+
rootName = @rootName
129+
ids = @ids
130+
@digest $rootScope, ->
131+
promise = $q.all ids.map (anId) ->
132+
leafletData.getDirectiveControls(anId)
133+
promise.then (controls) ->
134+
controls.forEach (c) =>
135+
expect(c[rootName].create).toBeDefined()
136+
done()
137+
return
138+
it 'clean', (done) ->
139+
element = @element
140+
rootName = @rootName
141+
ids = @ids
142+
@digest $rootScope, ->
143+
promise = $q.all ids.map (anId) ->
144+
leafletData.getDirectiveControls(anId)
145+
promise.then (controls) ->
146+
controls.forEach (c) =>
147+
expect(c[rootName].clean).toBeDefined()
148+
done()
149+
return

test/unit/leafletData/leafletDataSpec.coffee

Lines changed: 27 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,59 +11,42 @@ describe 'leafletData', ->
1111
$timeout = _$timeout_
1212
window.ngLeafLetTestGlobals.$timeout = $timeout
1313

14-
describe 'no mapId', ->
14+
describe 'markers no mapId', ->
1515
beforeEach ->
1616
@knownMarkers = [1,2,3]
17-
@knownGeoJSON = ['1','2','3']
18-
19-
@setPromise = $q.all [leafletData.setMarkers(@knownMarkers),
20-
leafletData.setGeoJSON(@knownGeoJSON)
21-
]
17+
leafletData.setMarkers(@knownMarkers)
2218

2319
it 'has unique data', (done)->
24-
_geoJSON = null
25-
_markers = null
26-
_allGet = null
27-
28-
@digest $rootScope, =>
29-
@setPromise.then ->
30-
_allGet = $q.all [
31-
leafletData.getMarkers().then (lObjs) ->
32-
_markers = lObjs
33-
,
34-
leafletData.getGeoJSON().then (lObjs) ->
35-
_geoJSON = lObjs
36-
]
37-
38-
@digest $rootScope, =>
39-
_allGet.then =>
40-
expect(@knownMarkers).toBe(_markers)
41-
expect(@knownGeoJSON).toBe(_geoJSON)
42-
expect(_geoJSON != _markers).toBeTruthy()
20+
knownMarkers = @knownMarkers
21+
@digest $rootScope, ->
22+
leafletData.getMarkers().then (markers) ->
23+
expect(knownMarkers).toBe(markers)
4324
done()
4425

45-
4626
it "modifying localScope modifies leafletData's version", (done) ->
47-
_geoJSON = null
48-
_markers = null
49-
_allGet = null
50-
#this proves you do not need to call set[Whatever] multiple times.
5127
@knownMarkers.push 4
52-
@knownGeoJSON.push "4"
53-
28+
knownMarkers = @knownMarkers
5429
@digest $rootScope, =>
55-
@setPromise.then ->
56-
_allGet = $q.all [
57-
leafletData.getMarkers().then (lObjs) ->
58-
_markers = lObjs
59-
,
60-
leafletData.getGeoJSON().then (lObjs) ->
61-
_geoJSON = lObjs
62-
]
30+
leafletData.getMarkers().then (markers) ->
31+
expect(knownMarkers).toBe(markers)
32+
done()
33+
34+
describe 'geojson no mapId', ->
35+
beforeEach ->
36+
@knownGeoJSON = ['1','2','3']
37+
leafletData.setGeoJSON(@knownGeoJSON)
6338

39+
it 'has unique data', (done) ->
40+
knownGeoJSON = @knownGeoJSON
41+
@digest $rootScope, ->
42+
leafletData.getGeoJSON().then (geoJSON) ->
43+
expect(knownGeoJSON).toBe(geoJSON)
44+
done()
45+
46+
it "modifying localScope modifies leafletData's version", (done) ->
47+
@knownGeoJSON.push '4'
48+
knownGeoJSON = @knownGeoJSON
6449
@digest $rootScope, =>
65-
_allGet.then =>
66-
expect(@knownMarkers).toBe(_markers)
67-
expect(@knownGeoJSON).toBe(_geoJSON)
68-
expect(_geoJSON != _markers).toBeTruthy()
50+
leafletData.getGeoJSON().then (geoJSON) ->
51+
expect(knownGeoJSON).toBe(geoJSON)
6952
done()

test/unit/markersDirectiveSpec.coffee

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ describe 'Directive: leaflet', ->
121121
element = $compile(element)($rootScope)
122122
@digest $rootScope, ->
123123
leafletData.getMarkers().then (leafletMarkers) ->
124-
console.log('leafletMarkers', leafletMarkers)
125124
leafletMainMarker = leafletMarkers.layer1.main_marker
126125
if postRunnerCb
127126
postRunnerCb main_marker, leafletMainMarker
@@ -153,11 +152,12 @@ describe 'Directive: leaflet', ->
153152
marker: marker
154153
element = angular.element('<leaflet markers="markers"></leaflet>')
155154
element = $compile(element)($rootScope)
156-
$rootScope.$digest()
157-
leafletData.getMarkers().then (leafletMarkers) ->
158-
leafletMainMarker = leafletMarkers.marker
159-
expect(leafletMainMarker._popup._content).toEqual 'this is paris'
160-
done()
155+
156+
@digest $rootScope, ->
157+
leafletData.getMarkers().then (leafletMarkers) ->
158+
leafletMainMarker = leafletMarkers.marker
159+
expect(leafletMainMarker._popup._content).toEqual 'this is paris'
160+
done()
161161

162162
it 'message should be compiled if angular template is given', ->
163163
marker =
@@ -206,7 +206,7 @@ describe 'Directive: leaflet', ->
206206
@digest $rootScope
207207
expect(leafletMainMarker._popup._contentNode.innerHTML).toEqual '<p class="ng-binding">angular</p>'
208208

209-
it 'should bind label to main marker if message is given', ->
209+
it 'should bind label to main marker if message is given', (done) ->
210210
spyOn(leafletHelpers.LabelPlugin, 'isLoaded').and.returnValue true
211211
L.Label = L.Class.extend(includes: L.Mixin.Events)
212212
L.BaseMarkerMethods =
@@ -236,23 +236,25 @@ describe 'Directive: leaflet', ->
236236
expect(leafletMainMarker.label._content).toEqual 'original'
237237

238238
marker.label.message = 'new'
239-
$rootScope.$digest()
240-
leafletData.getMarkers().then (leafletMarkers) ->
241-
leafletMainMarker = leafletMarkers.marker
242-
expect(leafletMainMarker.label._content).toEqual 'new'
239+
240+
@digest $rootScope, ->
241+
leafletData.getMarkers().then (leafletMarkers) ->
242+
leafletMainMarker = leafletMarkers.marker
243+
expect(leafletMainMarker.label._content).toEqual 'new'
244+
done()
243245

244246
# Markers
245247
it 'should create markers on the map', (done) ->
246248
angular.extend $rootScope, markers: mainMarkers
247249
element = angular.element('<leaflet markers="markers"></leaflet>')
248250
element = $compile(element)($rootScope)
249-
$rootScope.$digest()
250-
leafletData.getMarkers().then (leafletMarkers) ->
251-
expect(leafletMarkers.paris.getLatLng().lat).toBeCloseTo 0.966
252-
expect(leafletMarkers.paris.getLatLng().lng).toBeCloseTo 2.02
253-
expect(leafletMarkers.madrid.getLatLng().lat).toBeCloseTo 2.02
254-
expect(leafletMarkers.madrid.getLatLng().lng).toBeCloseTo 4.04
255-
done()
251+
@digest $rootScope, ->
252+
leafletData.getMarkers().then (leafletMarkers) ->
253+
expect(leafletMarkers.paris.getLatLng().lat).toBeCloseTo 0.966
254+
expect(leafletMarkers.paris.getLatLng().lng).toBeCloseTo 2.02
255+
expect(leafletMarkers.madrid.getLatLng().lat).toBeCloseTo 2.02
256+
expect(leafletMarkers.madrid.getLatLng().lng).toBeCloseTo 4.04
257+
done()
256258

257259
describe 'when a marker is updated', ->
258260
describe 'detecting errors in lat-lng', ->

0 commit comments

Comments
 (0)