terra-draw 1.0.0-beta.3 → 1.0.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -43,6 +43,7 @@
43
43
  <button id="rectangle">Rectangle</button>
44
44
  <button id="angled-rectangle">Angled Rectangle</button>
45
45
  <button id="sector">Sector</button>
46
+ <button id="sensor">Sensor</button>
46
47
  <button id="circle">Circle</button>
47
48
  <button id="clear">Clear</button>
48
49
  </div>
@@ -530,6 +530,187 @@ test.describe("sector mode", () => {
530
530
  });
531
531
  });
532
532
 
533
+ test.describe("sensor mode", () => {
534
+ const mode = "sensor";
535
+
536
+ test("mode can set and creates center point on first click", async ({
537
+ page,
538
+ }) => {
539
+ const mapDiv = await setupMap({ page });
540
+ await changeMode({ page, mode });
541
+
542
+ await page.mouse.click(mapDiv.width / 2, mapDiv.height / 2);
543
+
544
+ await expectPaths({ page, count: 1 });
545
+
546
+ await expectPathDimensions({ page, width: 12, height: 12 });
547
+ });
548
+
549
+ test("mode can set and but won't close if the mouse goes behind the initial arc", async ({
550
+ page,
551
+ }) => {
552
+ const mapDiv = await setupMap({ page });
553
+ await changeMode({ page, mode });
554
+
555
+ await page.mouse.click(mapDiv.width / 2, mapDiv.height / 2);
556
+ await page.mouse.move(mapDiv.width / 3, mapDiv.height / 2, { steps: 30 });
557
+ await page.mouse.click(mapDiv.width / 3, mapDiv.height / 2);
558
+ await page.mouse.move(mapDiv.width / 3, mapDiv.height / 3, { steps: 30 });
559
+ await page.mouse.click(mapDiv.width / 3, mapDiv.height / 3);
560
+
561
+ // The cursor is now behind the initial arc and so wont close the sensor
562
+ await page.mouse.move(mapDiv.width / 1, mapDiv.height / 3, { steps: 30 });
563
+ await page.mouse.click(mapDiv.width / 1, mapDiv.height / 3);
564
+
565
+ // We expect the count to be 2 because the sensor polygon is not finished
566
+ // and we are left with the center point and the arc line
567
+ await expectPaths({ page, count: 2 });
568
+
569
+ await expectPathDimensions({ page, width: 12, height: 12, item: 0 });
570
+ await expectPathDimensions({ page, width: 31, height: 109, item: 1 });
571
+ });
572
+
573
+ test("mode can set and used to create a sensor less than 90 degrees (clockwise)", async ({
574
+ page,
575
+ }) => {
576
+ const mapDiv = await setupMap({ page });
577
+ await changeMode({ page, mode });
578
+
579
+ await page.mouse.click(mapDiv.width / 2, mapDiv.height / 2);
580
+ await page.mouse.move(mapDiv.width / 3, mapDiv.height / 2, { steps: 30 });
581
+ await page.mouse.click(mapDiv.width / 3, mapDiv.height / 2);
582
+ await page.mouse.move(mapDiv.width / 3, mapDiv.height / 3, { steps: 30 });
583
+ await page.mouse.click(mapDiv.width / 3, mapDiv.height / 3);
584
+
585
+ // Finalise the sensor polygon
586
+ await page.mouse.move(mapDiv.width / 5, mapDiv.height / 3, { steps: 30 });
587
+ await page.mouse.click(mapDiv.width / 5, mapDiv.height / 3);
588
+
589
+ await expectPaths({ page, count: 1 });
590
+
591
+ await expectPathDimensions({ page, width: 220, height: 201 });
592
+ });
593
+
594
+ test("mode can set and used to create a sensor more than 90 degrees (clockwise)", async ({
595
+ page,
596
+ }) => {
597
+ const mapDiv = await setupMap({ page });
598
+ await changeMode({ page, mode });
599
+
600
+ await page.mouse.click(mapDiv.width / 2, mapDiv.height / 2);
601
+ await page.mouse.move(mapDiv.width / 3, mapDiv.height / 2, { steps: 30 });
602
+ await page.mouse.click(mapDiv.width / 3, mapDiv.height / 2);
603
+ await page.mouse.move(mapDiv.width * 0.75, mapDiv.height / 2.5, {
604
+ steps: 30,
605
+ });
606
+ await page.mouse.click(mapDiv.width * 0.75, mapDiv.height / 2.5);
607
+
608
+ // Finalise the sensor polygon
609
+ await page.mouse.move(mapDiv.width * 0.75, mapDiv.height / 5, {
610
+ steps: 30,
611
+ });
612
+ await page.mouse.click(mapDiv.width * 0.75, mapDiv.height / 5);
613
+
614
+ await expectPathDimensions({ page, width: 767, height: 390 });
615
+ });
616
+
617
+ test("mode can set and used to create a sensor more than 180 degrees (clockwise)", async ({
618
+ page,
619
+ }) => {
620
+ const mapDiv = await setupMap({ page });
621
+ await changeMode({ page, mode });
622
+
623
+ await page.mouse.click(mapDiv.width / 2, mapDiv.height / 2);
624
+ await page.mouse.move(mapDiv.width / 3, mapDiv.height / 2, { steps: 30 });
625
+ await page.mouse.click(mapDiv.width / 3, mapDiv.height / 2);
626
+ await page.mouse.move(mapDiv.width * 0.75, mapDiv.height / 3, {
627
+ steps: 10,
628
+ });
629
+ await page.mouse.move(mapDiv.width * 0.4, mapDiv.height / 1.5, {
630
+ steps: 10,
631
+ });
632
+ await page.mouse.click(mapDiv.width * 0.4, mapDiv.height / 1.5);
633
+
634
+ // Finalise the sensor polygon
635
+ await page.mouse.move(mapDiv.width * 0.4, mapDiv.height / 1.25);
636
+ await page.mouse.click(mapDiv.width * 0.4, mapDiv.height / 1.25);
637
+
638
+ await expectPaths({ page, count: 1 });
639
+
640
+ await expectPathDimensions({ page, width: 506, height: 506 });
641
+ });
642
+
643
+ test("mode can set and used to create a sensor less than 90 degrees (anticlockwise)", async ({
644
+ page,
645
+ }) => {
646
+ const mapDiv = await setupMap({ page });
647
+ await changeMode({ page, mode });
648
+
649
+ await page.mouse.click(mapDiv.width / 2, mapDiv.height / 2);
650
+ await page.mouse.move(mapDiv.width / 3, mapDiv.height / 2, { steps: 30 });
651
+ await page.mouse.click(mapDiv.width / 3, mapDiv.height / 2);
652
+ await page.mouse.move(mapDiv.width * 0.4, mapDiv.height / 1.5, {
653
+ steps: 30,
654
+ });
655
+ await page.mouse.click(mapDiv.width * 0.4, mapDiv.height / 1.5);
656
+
657
+ // Finalise the sensor polygon
658
+ await page.mouse.move(mapDiv.width * 0.3, mapDiv.height / 1.25);
659
+ await page.mouse.click(mapDiv.width * 0.3, mapDiv.height / 1.25);
660
+
661
+ await expectPaths({ page, count: 1 });
662
+
663
+ await expectPathDimensions({ page, width: 183, height: 233 });
664
+ });
665
+
666
+ test("mode can set and used to create a sensor more than 90 degrees (anticlockwise)", async ({
667
+ page,
668
+ }) => {
669
+ const mapDiv = await setupMap({ page });
670
+ await changeMode({ page, mode });
671
+
672
+ await page.mouse.click(mapDiv.width / 2, mapDiv.height / 2);
673
+ await page.mouse.move(mapDiv.width / 3, mapDiv.height / 2, { steps: 30 });
674
+ await page.mouse.click(mapDiv.width / 3, mapDiv.height / 2);
675
+ await page.mouse.move(mapDiv.width * 0.75, mapDiv.height / 1.5, {
676
+ steps: 30,
677
+ });
678
+ await page.mouse.click(mapDiv.width * 0.75, mapDiv.height / 1.5);
679
+
680
+ // Finalise the sensor polygon
681
+ await page.mouse.move(mapDiv.width * 0.75, mapDiv.height / 1.3);
682
+ await page.mouse.click(mapDiv.width * 0.75, mapDiv.height / 1.3);
683
+
684
+ await expectPathDimensions({ page, width: 728, height: 378 });
685
+ });
686
+
687
+ test("mode can set and used to create a sensor more than 180 degrees (anticlockwise)", async ({
688
+ page,
689
+ }) => {
690
+ const mapDiv = await setupMap({ page });
691
+ await changeMode({ page, mode });
692
+
693
+ await page.mouse.click(mapDiv.width / 2, mapDiv.height / 2);
694
+ await page.mouse.move(mapDiv.width / 3, mapDiv.height / 2, { steps: 30 });
695
+ await page.mouse.click(mapDiv.width / 3, mapDiv.height / 2);
696
+ await page.mouse.move(mapDiv.width * 0.75, mapDiv.height / 1.5, {
697
+ steps: 30,
698
+ });
699
+ await page.mouse.move(mapDiv.width * 0.75, mapDiv.height / 3, {
700
+ steps: 30,
701
+ });
702
+ await page.mouse.click(mapDiv.width * 0.75, mapDiv.height / 3);
703
+
704
+ // Finalise the sensor polygon
705
+ await page.mouse.move(mapDiv.width * 0.8, mapDiv.height / 3, { steps: 30 });
706
+ await page.mouse.click(mapDiv.width * 0.8, mapDiv.height / 3);
707
+
708
+ await expectPaths({ page, count: 1 });
709
+
710
+ await expectPathDimensions({ page, width: 808, height: 547 });
711
+ });
712
+ });
713
+
533
714
  test.describe("circle mode", () => {
534
715
  const mode = "circle";
535
716
 
@@ -61,7 +61,8 @@ export const changeMode = async ({
61
61
  | "rectangle"
62
62
  | "circle"
63
63
  | "angled-rectangle"
64
- | "sector";
64
+ | "sector"
65
+ | "sensor";
65
66
  }) => {
66
67
  let modeText = mode.charAt(0).toUpperCase() + mode.slice(1);
67
68
 
@@ -103,7 +104,10 @@ export const expectPaths = async ({
103
104
  await page.waitForSelector(selector);
104
105
  expect(await page.locator(selector).count()).toBe(count);
105
106
  } else {
106
- await expect(await page.locator(selector).count()).toBe(0);
107
+ await expect(
108
+ await page.locator(selector).count(),
109
+ `locator count should be greater than 0 for selector ${selector}`,
110
+ ).toBe(0);
107
111
  }
108
112
  };
109
113
 
@@ -111,14 +115,16 @@ export const expectPathDimensions = async ({
111
115
  page,
112
116
  width,
113
117
  height,
118
+ item = 0,
114
119
  }: {
115
120
  page: Page;
116
121
  width: number;
117
122
  height: number;
123
+ item?: number;
118
124
  }) => {
119
125
  const selector = "svg > g > path";
120
126
 
121
- const boundingBox = await page.locator(selector).boundingBox();
127
+ const boundingBox = await page.locator(selector).nth(item).boundingBox();
122
128
 
123
129
  expect(boundingBox?.width).toBe(width);
124
130
  expect(boundingBox?.height).toBe(height);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "terra-draw",
3
- "version": "1.0.0-beta.3",
3
+ "version": "1.0.0-beta.5",
4
4
  "description": "Frictionless map drawing across mapping provider",
5
5
  "scripts": {
6
6
  "docs": "typedoc",