Skip to content
This repository was archived by the owner on Nov 30, 2018. It is now read-only.

Commit a1909ad

Browse files
committed
adding more specs
1 parent af84fd8 commit a1909ad

File tree

9 files changed

+218
-135
lines changed

9 files changed

+218
-135
lines changed

Gruntfile.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ module.exports = function (grunt) {
4848
'tmp/spec/js/oo/oo.spec.js': 'spec/coffee/oo/*.spec.coffee',
4949

5050
'tmp/spec/js/directives/api/models/child/children.spec.js': 'spec/coffee/directives/api/models/child/*.spec.coffee',
51+
'tmp/spec/js/directives/api/models/parent/parents.spec.js': 'spec/coffee/directives/api/models/parent/*.spec.coffee',
5152
'tmp/spec/js/directives/api/utils/async-processor.spec.js': 'spec/coffee/directives/api/utils/async-processor.spec.coffee'
5253
}
5354
}
@@ -76,8 +77,8 @@ module.exports = function (grunt) {
7677
dest: 'tmp/output.js'
7778
},
7879
example: {
79-
//src: ['dist/angular-google-maps.js'],
80-
src: ['dist/angular-google-maps.min.js'], //use min for release, otherwise other for testing
80+
src: ['dist/angular-google-maps.js'],
81+
// src: ['dist/angular-google-maps.min.js'], //use min for release, otherwise other for testing
8182
dest: 'example/<%= pkg.name %>.js'
8283
}
8384
},
@@ -149,17 +150,17 @@ module.exports = function (grunt) {
149150
taskName: {
150151
src: ['dist/angular-google-maps.js'],
151152
options: {
152-
keepRunner: false,
153+
keepRunner: true,
153154
vendor: ['http://maps.googleapis.com/maps/api/js?sensor=false&language=en', 'lib/*.js', 'dist/angular-google-maps.js'],
154155
specs: ['spec/*.spec.js', 'spec/**/*.spec.js', 'spec/**/**/*-spec.js', 'spec/**/**/**/*.spec.js',
155156
'tmp/spec/js/*/spec.js', 'tmp/spec/**/*.spec.js', 'tmp/spec/**/**/*-spec.js', 'tmp/spec/**/**/**/*.spec.js'
156157
],
157158
helpers: ['tmp/spec/js/helpers/helpers.js'],
158-
template: require('grunt-template-jasmine-istanbul',
159+
template: require(//'grunt-template-jasmine-istanbul',
159160
'grunt-template-jasmine-requirejs', 'spec/templates/angular-google-maps.html'),
160161
templateOptions: {
161-
coverage: 'spec/coverage/coverage.json',
162-
report: 'spec/coverage',
162+
// coverage: 'spec/coverage/coverage.json',
163+
// report: 'spec/coverage',
163164
thresholds: {
164165
lines: 75,
165166
statements: 75,

dist/angular-google-maps.js

+33-9
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
})();;(function() {
5252
this.ngGmapModule = function(names, fn) {
5353
var space, _name;
54+
if (fn == null) {
55+
fn = function() {};
56+
}
5457
if (typeof names === 'string') {
5558
names = names.split('.');
5659
}
@@ -417,19 +420,30 @@
417420

418421
(function() {
419422
this.ngGmapModule("directives.api.utils", function() {
420-
return this.Logger = {
423+
var logger;
424+
this.Logger = {
421425
logger: void 0,
422426
doLog: false,
423427
info: function(msg) {
424-
if (directives.api.utils.Logger.doLog) {
425-
if (directives.api.utils.Logger.logger != null) {
426-
return directives.api.utils.Logger.logger.info(msg);
428+
if (logger.doLog) {
429+
if (logger.logger != null) {
430+
return logger.logger.info(msg);
427431
} else {
428432
return console.info(msg);
429433
}
430434
}
435+
},
436+
error: function(msg) {
437+
if (logger.doLog) {
438+
if (logger.logger != null) {
439+
return logger.logger.error(msg);
440+
} else {
441+
return console.error(msg);
442+
}
443+
}
431444
}
432445
};
446+
return logger = this.Logger;
433447
});
434448

435449
}).call(this);
@@ -900,14 +914,14 @@
900914
_this = this;
901915
self = this;
902916
this.scope = scope;
917+
this.$log = directives.api.utils.Logger;
903918
this.element = element;
904919
this.attrs = attrs;
905-
if (this.validateScope(scope)) {
920+
if (!this.validateScope(scope)) {
906921
return;
907922
}
908923
this.doClick = angular.isDefined(attrs.click);
909924
this.mapCtrl = mapCtrl;
910-
this.$log = directives.api.utils.Logger;
911925
this.$timeout = $timeout;
912926
if (scope.options != null) {
913927
this.DEFAULTS = scope.options;
@@ -927,8 +941,11 @@
927941

928942
IMarkerParentModel.prototype.validateScope = function(scope) {
929943
var ret;
930-
ret = angular.isUndefined(scope.coords) || scope.coords === void 0;
931-
if (ret) {
944+
if (scope == null) {
945+
return false;
946+
}
947+
ret = scope.coords != null;
948+
if (!ret) {
932949
this.$log.error(this.constructor.name + ": no valid coords attribute found");
933950
}
934951
return ret;
@@ -1112,7 +1129,14 @@
11121129
}
11131130

11141131
MarkerParentModel.prototype.validateScope = function(scope) {
1115-
return MarkerParentModel.__super__.validateScope.call(this, scope) || angular.isUndefined(scope.coords.latitude) || angular.isUndefined(scope.coords.longitude);
1132+
if (scope == null) {
1133+
return false;
1134+
}
1135+
if (scope.coords != null) {
1136+
return MarkerParentModel.__super__.validateScope.call(this, scope) && (scope.coords.latitude != null) && (scope.coords.longitude != null);
1137+
} else {
1138+
return MarkerParentModel.__super__.validateScope.call(this, scope);
1139+
}
11161140
};
11171141

11181142
MarkerParentModel.prototype.onWatch = function(propNameToWatch, scope) {

dist/angular-google-maps.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
describe "MarkerParentModel", ->
2+
beforeEach( ->
3+
#comparison variables
4+
@index = 0
5+
@scope=
6+
icon:'icon.png'
7+
coords:
8+
latitude:90
9+
longitude:90
10+
options:
11+
animation:google.maps.Animation.BOUNCE
12+
13+
#define / inject values into the item we are testing... not a controller but it allows us to inject
14+
angular.module('mockModule',[])
15+
.value('mapCtrl',
16+
getMap:()->
17+
document.gMap)
18+
.value('element',{})
19+
.value('attrs',{})
20+
.value('model',{})
21+
.value('scope',@scope)
22+
.controller 'subject', (scope, element, attrs, mapCtrl, $timeout) =>
23+
@subject = new directives.api.models.parent.MarkerParentModel(scope, element, attrs, mapCtrl, $timeout)
24+
angular.mock.module('mockModule')
25+
inject ($timeout,$rootScope,$log,$controller) =>
26+
directives.api.utils.Logger.logger = $log
27+
scope = $rootScope.$new()
28+
@scope = _.extend @scope,scope
29+
$controller 'subject',
30+
scope : scope
31+
)
32+
it 'constructor exist', ->
33+
test = directives.api.models.parent.MarkerParentModel?
34+
expect(test).toEqual(true)
35+
36+
it 'can be created', ->
37+
expect(@subject?).toEqual(true)
38+
describe "validateScope", ->
39+
it 'returns fals with scope undefined', ->
40+
expect(@subject.validateScope(undefined)).toEqual(false)
41+
it 'returns fals with scope.coords undefined', ->
42+
expect(@subject.validateScope({coords:undefined})).toEqual(false)
43+
it 'returns fals with scope.coords,latitude undefined', ->
44+
expect(@subject.validateScope({coords:{latitude:undefined,longitude:{}}})).toEqual(false)
45+
it 'returns fals with scope.coords.longtitude undefined', ->
46+
expect(@subject.validateScope({coords:{latitude:{},longitude:undefined }})).toEqual(false)

spec/coffee/ng-gmap-module.spec.coffee

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ describe "ngGmapModule", ->
66
@ngGmapModule "test", ->
77
hidden = 10
88
@open = hidden
9+
@ngGmapModule "testWithoutFn"
10+
911
describe "ngGmapModule - creation tests", ->
1012
it "has no hidden", ->
1113
expect(test.hidden?).toEqual(false)
1214

1315
it "has open", ->
14-
expect(test.open?).toEqual(true)
16+
expect(test.open?).toEqual(true)
17+
it "ng-module created without function", ->
18+
expect(testWithoutFn?).toEqual(true)

src/coffee/directives/api/models/parent/i-marker-parent-model.coffee

+49-51
Original file line numberDiff line numberDiff line change
@@ -5,62 +5,60 @@
55
- coords
66
- icon
77
- implementation needed on watches
8-
###
8+
###
99
@ngGmapModule "directives.api.models.parent", ->
10-
class @IMarkerParentModel extends oo.BaseObject
11-
DEFAULTS: {}
12-
13-
# Check if a value is literally false
14-
# @param value the value to test
15-
# @returns {boolean} true if value is literally false, false otherwise
16-
isFalse: (value) ->
17-
['false', 'FALSE', 0, 'n', 'N', 'no', 'NO'].indexOf(value) != -1
10+
class @IMarkerParentModel extends oo.BaseObject
11+
DEFAULTS: {}
1812

19-
constructor: (scope, element, attrs, mapCtrl,$timeout) ->
20-
self = @
21-
@scope = scope
22-
@element = element
23-
@attrs = attrs
24-
# Validate required properties
25-
if (@validateScope(scope))
26-
return
27-
@doClick = angular.isDefined(attrs.click)
28-
@mapCtrl = mapCtrl
29-
@$log = directives.api.utils.Logger
30-
@$timeout = $timeout
31-
if scope.options?
32-
@DEFAULTS = scope.options
33-
# Wrap marker initialization inside a $timeout() call to make sure the map is created already
34-
@$timeout( =>
35-
@watch('coords',scope)
36-
@watch('icon',scope)
37-
@watch('options',scope)
38-
@onTimeOut(scope)
39-
scope.$on("$destroy", =>
40-
@onDestroy(scope)
41-
)
42-
)
13+
# Check if a value is literally false
14+
# @param value the value to test
15+
# @returns {boolean} true if value is literally false, false otherwise
16+
isFalse: (value) ->
17+
['false', 'FALSE', 0, 'n', 'N', 'no', 'NO'].indexOf(value) != -1
4318

44-
onTimeOut:(scope)=>
19+
constructor: (scope, element, attrs, mapCtrl, $timeout) ->
20+
self = @
21+
@scope = scope
22+
@$log = directives.api.utils.Logger
23+
@element = element
24+
@attrs = attrs
25+
# Validate required properties
26+
return unless @validateScope scope
27+
@doClick = angular.isDefined attrs.click
28+
@mapCtrl = mapCtrl
29+
@$timeout = $timeout
30+
if scope.options?
31+
@DEFAULTS = scope.options
32+
# Wrap marker initialization inside a $timeout() call to make sure the map is created already
33+
@$timeout(=>
34+
@watch('coords', scope)
35+
@watch('icon', scope)
36+
@watch('options', scope)
37+
@onTimeOut(scope)
38+
scope.$on("$destroy", =>
39+
@onDestroy(scope)
40+
)
41+
)
4542

46-
validateScope:(scope)=>
47-
ret = angular.isUndefined(scope.coords) or
48-
scope.coords == undefined
49-
if(ret)
50-
@$log.error(@constructor.name + ": no valid coords attribute found")
51-
ret
43+
onTimeOut: (scope)=>
44+
validateScope: (scope)=>
45+
return false unless scope?
46+
ret = scope.coords?
47+
unless ret
48+
@$log.error(@constructor.name + ": no valid coords attribute found")
49+
ret
5250

53-
watch:(propNameToWatch,scope) =>
54-
scope.$watch(propNameToWatch, (newValue, oldValue) =>
55-
if (newValue != oldValue)
56-
@onWatch(propNameToWatch,scope,newValue,oldValue)
57-
, true)
51+
watch: (propNameToWatch, scope) =>
52+
scope.$watch(propNameToWatch, (newValue, oldValue) =>
53+
if (newValue != oldValue)
54+
@onWatch(propNameToWatch, scope, newValue, oldValue)
55+
, true)
5856

59-
onWatch:(propNameToWatch,scope,newValue,oldValue) =>
60-
throw new Exception("Not Implemented!!")
57+
onWatch: (propNameToWatch, scope, newValue, oldValue) =>
58+
throw new Exception("Not Implemented!!")
6159

62-
onDestroy:(scope) =>
63-
throw new Exception("Not Implemented!!")
60+
onDestroy: (scope) =>
61+
throw new Exception("Not Implemented!!")
6462

65-
linkInit:(element,mapCtrl,scope,animate)=>
66-
throw new Exception("Not Implemented!!")
63+
linkInit: (element, mapCtrl, scope, animate)=>
64+
throw new Exception("Not Implemented!!")

0 commit comments

Comments
 (0)