map_controller_spec.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* global ngMap, google */
  2. describe('MapController', function() {
  3. var scope, ctrl;
  4. var el = document.body;
  5. beforeEach( function() {
  6. inject( function($controller, $rootScope){
  7. scope = $rootScope;
  8. ctrl = $controller(ngMap.MapController, {$scope: scope, 'NavigatorGeolocation': {}, 'GeoCoder': {} });
  9. });
  10. });
  11. describe('addMarker', function() {
  12. it('should add a marker to the existing map', function() {
  13. ctrl.map = new google.maps.Map(el, {}); //each method require ctrl.map;
  14. ctrl.map.markers = {};
  15. var marker = new google.maps.Marker({
  16. position: new google.maps.LatLng(1,1),
  17. centered: true
  18. });
  19. ctrl.addMarker(marker);
  20. // set map for this marker
  21. expect(marker.getMap()).toBe(ctrl.map);
  22. // set center of the map with this marker
  23. expect(marker.getPosition()).toBe(ctrl.map.getCenter());
  24. // ctrl.map.markers
  25. expect(Object.keys(ctrl.map.markers).length).toEqual(1);
  26. });
  27. it('should add a marker to ctrl._objects when ctrl.map is not init', function() {
  28. ctrl._objects = [];
  29. var marker = new google.maps.Marker({position: new google.maps.LatLng(1,1)});
  30. ctrl.addMarker(marker);
  31. expect(ctrl._objects[0]).toBe(marker);
  32. });
  33. });
  34. describe('addShape', function() {
  35. it('should add a shape to ctrl._objects when ctrl.map is not init', function() {
  36. ctrl._objects = [];
  37. var circle = new google.maps.Circle({center: new google.maps.LatLng(1,1)});
  38. ctrl.addShape(circle);
  39. expect(ctrl._objects[0]).toBe(circle);
  40. });
  41. it('should add a shape to the existing map', function() {
  42. ctrl.map = new google.maps.Map(el, {}); //each method require ctrl.map;
  43. ctrl.map.shapes = {};
  44. var circle = new google.maps.Circle({center: new google.maps.LatLng(1,1)});
  45. ctrl.addShape(circle);
  46. expect(ctrl.map.shapes[0]).toBe(circle);
  47. expect(ctrl.map.shapes[0].getMap()).toBe(ctrl.map);
  48. });
  49. });
  50. describe('addObjects', function() {
  51. it('should add objects; markers and shapes when map is init', function() {
  52. var marker = new google.maps.Marker({position: new google.maps.LatLng(1,1)});
  53. var circle = new google.maps.Circle({center: new google.maps.LatLng(1,1)});
  54. var objects = [marker, circle];
  55. ctrl.map = new google.maps.Map(el, {}); //each method require ctrl.map;
  56. ctrl.addObjects(objects);
  57. expect(marker.getMap()).toBe(ctrl.map);
  58. expect(circle.getMap()).toBe(ctrl.map);
  59. });
  60. });
  61. });