@@ -4,4 +4,103 @@ import {shallow, mount, render} from 'enzyme';
44import { expect } from 'chai' ;
55import sinon from 'sinon' ;
66
7- import Marker from '../components/Marker' ;
7+ import Marker from '../../components/Marker' ;
8+
9+ // let google = {};
10+ // google.maps = {};
11+ // google.maps.LatLng = function(lat, lng, opt_noWrap) {};
12+
13+ describe ( 'Marker' , ( ) => {
14+ let map = null , google = null ;
15+ let sandbox ;
16+ let LatLng = null ;
17+ let location ;
18+
19+ beforeEach ( ( ) => {
20+ sandbox = sinon . sandbox . create ( ) ;
21+
22+ map = { }
23+ location = { lat : 37.759703 , lng : - 122.428093 }
24+
25+ google = {
26+ maps : {
27+ LatLng : function ( lat , lng ) {
28+ return {
29+ latitude : parseFloat ( lat ) ,
30+ longitude : parseFloat ( lng ) ,
31+
32+ lat : function ( ) { return this . latitude ; } ,
33+ lng : function ( ) { return this . longitude ; }
34+ } ;
35+ } ,
36+ LatLngBounds : function ( ne , sw ) {
37+ return {
38+ getSouthWest : function ( ) { return sw ; } ,
39+ getNorthEast : function ( ) { return ne ; }
40+ } ;
41+ } ,
42+ OverlayView : function ( ) {
43+ return { } ;
44+ } ,
45+ InfoWindow : function ( ) {
46+ return { } ;
47+ } ,
48+ Marker : function ( ) {
49+ return {
50+ addListener : function ( ) { }
51+ } ;
52+ } ,
53+ MarkerImage : function ( ) {
54+ return { } ;
55+ } ,
56+ Map : function ( ) {
57+ return { } ;
58+ } ,
59+ Point : function ( ) {
60+ return { } ;
61+ } ,
62+ Size : function ( ) {
63+ return { } ;
64+ }
65+ }
66+ } ;
67+
68+
69+ sandbox . stub ( google . maps , 'Map' ) . returns ( google . maps . Map ) ;
70+ // sandbox.stub(google.maps, 'Marker').returns(google.maps.Marker);
71+ } )
72+
73+ afterEach ( ( ) => {
74+ sandbox . restore ( ) ;
75+ } )
76+
77+ it ( 'accepts a `map` and a `google` prop' , ( ) => {
78+ const wrapper = mount ( < Marker google = { google } map = { map } /> ) ;
79+ expect ( wrapper . props ( ) . google ) . to . equal ( google ) ;
80+ expect ( wrapper . props ( ) . map ) . to . equal ( map ) ;
81+ } ) ;
82+
83+ describe ( 'LatLng' , ( ) => {
84+ let wrapper ;
85+ beforeEach ( ( ) => {
86+ sandbox . stub ( google . maps , 'LatLng' )
87+ . returns ( sinon . createStubInstance ( google . maps . LatLng ) ) ;
88+ sandbox . spy ( google . maps , 'Marker' )
89+ wrapper = mount ( < Marker google = { google }
90+ position = { location } /> ) ;
91+ } ) ;
92+
93+ it ( 'creates a location from the position prop' , ( ) => {
94+ wrapper . setProps ( { map : map } )
95+ sinon . assert
96+ . calledWith ( google . maps . LatLng , location . lat , location . lng )
97+ } ) ;
98+
99+ it ( 'creates a Marker from the position prop' , ( ) => {
100+ wrapper . setProps ( { map : map } )
101+ sinon . assert . called ( google . maps . Marker )
102+ } ) ;
103+
104+ } )
105+
106+ } )
0 commit comments