@@ -740,13 +740,15 @@ describe("TerraDrawPolygonMode", () => {
740
740
let polygonMode : TerraDrawPolygonMode ;
741
741
let store : TerraDrawGeoJSONStore ;
742
742
let onChange : jest . Mock ;
743
+ let onFinish : jest . Mock ;
743
744
744
745
beforeEach ( ( ) => {
745
746
store = new GeoJSONStore ( ) ;
746
747
polygonMode = new TerraDrawPolygonMode ( ) ;
747
748
const mockConfig = MockModeConfig ( polygonMode . mode ) ;
748
749
749
750
store = mockConfig . store ;
751
+ onFinish = mockConfig . onFinish ;
750
752
onChange = mockConfig . onChange ;
751
753
polygonMode . register ( mockConfig ) ;
752
754
polygonMode . start ( ) ;
@@ -763,8 +765,6 @@ describe("TerraDrawPolygonMode", () => {
763
765
764
766
polygonMode . onMouseMove ( MockCursorEvent ( { lng : 1 , lat : 1 } ) ) ;
765
767
766
- // expect(onChange).toHaveBeenCalledTimes(2);
767
-
768
768
const features = store . copyAll ( ) ;
769
769
expect ( features . length ) . toBe ( 1 ) ;
770
770
@@ -787,11 +787,11 @@ describe("TerraDrawPolygonMode", () => {
787
787
788
788
polygonMode . onMouseMove ( MockCursorEvent ( { lng : 2 , lat : 2 } ) ) ;
789
789
790
- expect ( onChange ) . toHaveBeenCalledTimes ( 4 ) ;
791
-
792
790
const features = store . copyAll ( ) ;
793
791
expect ( features . length ) . toBe ( 1 ) ;
794
792
793
+ expect ( onFinish ) . not . toHaveBeenCalled ( ) ;
794
+
795
795
expect ( features [ 0 ] . geometry . coordinates ) . toStrictEqual ( [
796
796
[
797
797
[ 0 , 0 ] ,
@@ -816,8 +816,6 @@ describe("TerraDrawPolygonMode", () => {
816
816
// Snapping branch
817
817
polygonMode . onMouseMove ( MockCursorEvent ( { lng : 2.5 , lat : 2.5 } ) ) ;
818
818
819
- expect ( onChange ) . toHaveBeenCalledTimes ( 7 ) ;
820
-
821
819
// 1 times for the polygon
822
820
// 2 times for the closing points
823
821
let features = store . copyAll ( ) ;
@@ -836,6 +834,8 @@ describe("TerraDrawPolygonMode", () => {
836
834
// No snapping branch
837
835
polygonMode . onMouseMove ( MockCursorEvent ( { lng : 4 , lat : 4 } ) ) ;
838
836
837
+ expect ( onFinish ) . not . toHaveBeenCalled ( ) ;
838
+
839
839
features = store . copyAll ( ) ;
840
840
841
841
expect ( features [ 0 ] . geometry . coordinates ) . toStrictEqual ( [
@@ -1264,19 +1264,10 @@ describe("TerraDrawPolygonMode", () => {
1264
1264
expect ( features . length ) . toBe ( 1 ) ;
1265
1265
1266
1266
expect ( onFinish ) . toHaveBeenCalledTimes ( 1 ) ;
1267
- // Extra call because of the right hand rule fixing
1268
- expect ( onChange ) . toHaveBeenCalledTimes ( 14 ) ;
1269
1267
1270
1268
// Delete a coordinate
1271
1269
polygonMode . onClick ( MockCursorEvent ( { lng : 1 , lat : 1 , button : "right" } ) ) ;
1272
1270
1273
- expect ( onChange ) . toHaveBeenNthCalledWith (
1274
- 14 ,
1275
- [ expect . any ( String ) , expect . any ( String ) ] ,
1276
- "delete" ,
1277
- undefined ,
1278
- ) ;
1279
-
1280
1271
const featuresAfter = store . copyAll ( ) ;
1281
1272
expect ( featuresAfter . length ) . toBe ( 1 ) ;
1282
1273
expect ( featuresAfter [ 0 ] . geometry . coordinates [ 0 ] ) . not . toEqual (
@@ -1315,8 +1306,6 @@ describe("TerraDrawPolygonMode", () => {
1315
1306
expect ( features . length ) . toBe ( 1 ) ;
1316
1307
1317
1308
expect ( onFinish ) . toHaveBeenCalledTimes ( 1 ) ;
1318
- // Extra call because of the right hand rule fixing
1319
- expect ( onChange ) . toHaveBeenCalledTimes ( 14 ) ;
1320
1309
1321
1310
// Delete a coordinate
1322
1311
polygonMode . onClick (
@@ -1328,13 +1317,6 @@ describe("TerraDrawPolygonMode", () => {
1328
1317
} ) ,
1329
1318
) ;
1330
1319
1331
- expect ( onChange ) . toHaveBeenNthCalledWith (
1332
- 14 ,
1333
- [ expect . any ( String ) , expect . any ( String ) ] ,
1334
- "delete" ,
1335
- undefined ,
1336
- ) ;
1337
-
1338
1320
const featuresAfter = store . copyAll ( ) ;
1339
1321
expect ( featuresAfter . length ) . toBe ( 1 ) ;
1340
1322
expect ( featuresAfter [ 0 ] . geometry . coordinates [ 0 ] ) . not . toEqual (
@@ -1437,6 +1419,61 @@ describe("TerraDrawPolygonMode", () => {
1437
1419
expect ( features [ 3 ] . geometry . type ) . toBe ( "Point" ) ;
1438
1420
} ) ;
1439
1421
1422
+ it ( "updates the properties for committed coordinate count and provisional coordinate counts" , ( ) => {
1423
+ polygonMode . onMouseMove ( MockCursorEvent ( { lng : 0 , lat : 0 } ) ) ;
1424
+ polygonMode . onClick ( MockCursorEvent ( { lng : 0 , lat : 0 } ) ) ;
1425
+
1426
+ let features = store . copyAll ( ) ;
1427
+ expect ( features . length ) . toBe ( 1 ) ;
1428
+ expect (
1429
+ features [ 0 ] . properties [ COMMON_PROPERTIES . COMMITTED_COORDINATE_COUNT ] ,
1430
+ ) . toBe ( 1 ) ;
1431
+ expect (
1432
+ features [ 0 ] . properties [ COMMON_PROPERTIES . PROVISIONAL_COORDINATE_COUNT ] ,
1433
+ ) . toBe ( 1 ) ;
1434
+
1435
+ polygonMode . onMouseMove ( MockCursorEvent ( { lng : 3 , lat : 3 } ) ) ;
1436
+ polygonMode . onClick ( MockCursorEvent ( { lng : 3 , lat : 3 } ) ) ;
1437
+
1438
+ features = store . copyAll ( ) ;
1439
+ expect ( features . length ) . toBe ( 1 ) ;
1440
+ expect (
1441
+ features [ 0 ] . properties [ COMMON_PROPERTIES . COMMITTED_COORDINATE_COUNT ] ,
1442
+ ) . toBe ( 2 ) ;
1443
+ expect (
1444
+ features [ 0 ] . properties [ COMMON_PROPERTIES . PROVISIONAL_COORDINATE_COUNT ] ,
1445
+ ) . toBe ( 2 ) ;
1446
+
1447
+ polygonMode . onMouseMove ( MockCursorEvent ( { lng : 2 , lat : 2 } ) ) ;
1448
+ polygonMode . onClick ( MockCursorEvent ( { lng : 2 , lat : 2 } ) ) ;
1449
+
1450
+ features = store . copyAll ( ) ;
1451
+ expect ( features . length ) . toBe ( 3 ) ; // 2 closing points are created
1452
+ expect (
1453
+ features [ 0 ] . properties [ COMMON_PROPERTIES . COMMITTED_COORDINATE_COUNT ] ,
1454
+ ) . toBe ( 3 ) ;
1455
+ expect (
1456
+ features [ 0 ] . properties [ COMMON_PROPERTIES . PROVISIONAL_COORDINATE_COUNT ] ,
1457
+ ) . toBe ( 3 ) ;
1458
+
1459
+ expect ( onFinish ) . toHaveBeenCalledTimes ( 0 ) ;
1460
+
1461
+ // Close the polygon
1462
+ polygonMode . onMouseMove ( MockCursorEvent ( { lng : 0 , lat : 0 } ) ) ;
1463
+ polygonMode . onClick ( MockCursorEvent ( { lng : 0 , lat : 0 } ) ) ;
1464
+
1465
+ features = store . copyAll ( ) ;
1466
+ expect ( features . length ) . toBe ( 1 ) ;
1467
+ expect (
1468
+ features [ 0 ] . properties [ COMMON_PROPERTIES . COMMITTED_COORDINATE_COUNT ] ,
1469
+ ) . toBe ( undefined ) ;
1470
+ expect (
1471
+ features [ 0 ] . properties [ COMMON_PROPERTIES . PROVISIONAL_COORDINATE_COUNT ] ,
1472
+ ) . toBe ( undefined ) ;
1473
+
1474
+ expect ( onFinish ) . toHaveBeenCalledTimes ( 1 ) ;
1475
+ } ) ;
1476
+
1440
1477
describe ( "with leftClick pointer event set to false" , ( ) => {
1441
1478
beforeEach ( ( ) => {
1442
1479
polygonMode = new TerraDrawPolygonMode ( {
0 commit comments