@@ -11,12 +11,19 @@ import { createSandboxFromDefaultPreferences } from 'compass-preferences-model';
1111import { createNoopLogger } from '@mongodb-js/compass-logging/provider' ;
1212import type { FieldStoreService } from '@mongodb-js/compass-field-store' ;
1313import { createNoopTrack } from '@mongodb-js/compass-telemetry/provider' ;
14- import { startAnalysis , stopAnalysis } from './schema-analysis-reducer' ;
14+ import {
15+ geoLayerAdded ,
16+ geoLayersDeleted ,
17+ geoLayersEdited ,
18+ startAnalysis ,
19+ stopAnalysis ,
20+ } from './schema-analysis-reducer' ;
1521import Sinon from 'sinon' ;
1622import {
1723 changeExportSchemaFormat ,
1824 openExportSchema ,
1925} from './schema-export-reducer' ;
26+ import { Circle , LayerGroup , Polygon } from 'leaflet' ;
2027
2128const dummyLogger = createNoopLogger ( 'TEST' ) ;
2229const dummyTrack = createNoopTrack ( ) ;
@@ -154,6 +161,62 @@ describe('Schema Store', function () {
154161 expect ( store . getState ( ) . schemaAnalysis . analysisState ) . to . equal ( 'initial' ) ;
155162 } ) ;
156163
164+ describe ( 'geoLayers' , function ( ) {
165+ it ( 'geoLayerAdded, geoLayersEdited, geoLayersDeleted: calls the onChange callback' , async function ( ) {
166+ const layer = new Circle ( [ 1 , 2 ] , {
167+ radius : 1000 ,
168+ } ) ;
169+ const onChangeSpy = sandbox . spy ( ) ;
170+ await store . dispatch ( geoLayerAdded ( 'coordinates' , layer , onChangeSpy ) ) ;
171+ expect ( onChangeSpy ) . to . have . been . calledOnceWith ( {
172+ coordinates : {
173+ $geoWithin : {
174+ $centerSphere : Sinon . match . array ,
175+ } ,
176+ } ,
177+ } ) ;
178+ } ) ;
179+
180+ it ( 'geoLayersEdited: calls the onChange callback' , async function ( ) {
181+ const layersGroup = new LayerGroup ( ) ;
182+ layersGroup . addLayer (
183+ new Polygon ( [
184+ [ 1 , 2 ] ,
185+ [ 3 , 4 ] ,
186+ [ 5 , 6 ] ,
187+ ] )
188+ ) ;
189+ const onChangeSpy = sandbox . spy ( ) ;
190+ await store . dispatch (
191+ geoLayersEdited ( 'coordinates' , layersGroup , onChangeSpy )
192+ ) ;
193+ expect ( onChangeSpy ) . to . have . been . calledOnceWith ( {
194+ coordinates : {
195+ $geoWithin : {
196+ $geometry : {
197+ type : 'Polygon' ,
198+ coordinates : Sinon . match . array ,
199+ } ,
200+ } ,
201+ } ,
202+ } ) ;
203+ } ) ;
204+
205+ it ( 'geoLayersDeleted: calls the onChange callback' , async function ( ) {
206+ const layersGroup = new LayerGroup ( ) ;
207+ layersGroup . addLayer (
208+ new Polygon ( [
209+ [ 1 , 2 ] ,
210+ [ 3 , 4 ] ,
211+ [ 5 , 6 ] ,
212+ ] )
213+ ) ;
214+ const onChangeSpy = sandbox . spy ( ) ;
215+ await store . dispatch ( geoLayersDeleted ( layersGroup , onChangeSpy ) ) ;
216+ expect ( onChangeSpy ) . to . have . been . calledOnceWith ( { $or : [ ] } ) ;
217+ } ) ;
218+ } ) ;
219+
157220 describe ( 'schema export' , function ( ) {
158221 describe ( 'with an analyzed schema' , function ( ) {
159222 beforeEach ( async function ( ) {
0 commit comments