15832144755
2022-01-06 7b4c8991dca9cf2a809a95e239d144697d3afb56
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import { FeatureDetection } from "../../../Source/Cesium.js";
import createScene from "../../createScene.js";
import DomEventSimulator from "../../DomEventSimulator.js";
import { ProjectionPicker } from "../../../Source/Cesium.js";
 
describe(
  "Widgets/ProjectionPicker/ProjectionPicker",
  function () {
    var scene;
 
    beforeAll(function () {
      scene = createScene();
    });
 
    afterAll(function () {
      scene.destroyForSpecs();
    });
 
    it("can create and destroy", function () {
      var container = document.createElement("span");
      container.id = "testContainer";
      document.body.appendChild(container);
 
      var widget = new ProjectionPicker("testContainer", scene);
      expect(widget.container.id).toBe(container.id);
      expect(widget.isDestroyed()).toEqual(false);
 
      widget.destroy();
      expect(widget.isDestroyed()).toEqual(true);
 
      document.body.removeChild(container);
    });
 
    function addCloseOnInputSpec(name, func) {
      it(
        name + " event closes dropdown if target is not inside container",
        function () {
          var container = document.createElement("span");
          container.id = "testContainer";
          document.body.appendChild(container);
 
          var widget = new ProjectionPicker("testContainer", scene);
 
          widget.viewModel.dropDownVisible = true;
          func(document.body);
          expect(widget.viewModel.dropDownVisible).toEqual(false);
 
          widget.viewModel.dropDownVisible = true;
          func(container.firstChild);
          expect(widget.viewModel.dropDownVisible).toEqual(true);
 
          widget.destroy();
          document.body.removeChild(container);
        }
      );
    }
 
    function addDisabledDuringFlightSpec(name, func) {
      it(name + " event does nothing during camera flight", function () {
        var container = document.createElement("span");
        container.id = "testContainer";
        document.body.appendChild(container);
 
        var widget = new ProjectionPicker("testContainer", scene);
 
        scene.camera.flyHome(100.0);
 
        func(container.firstChild);
        expect(widget.viewModel.dropDownVisible).toEqual(false);
 
        scene.camera.cancelFlight();
 
        widget.destroy();
        document.body.removeChild(container);
      });
    }
 
    function addDisabledIn2DSpec(name, func) {
      it(name + " event does nothing in 2D", function () {
        var container = document.createElement("span");
        container.id = "testContainer";
        document.body.appendChild(container);
 
        var widget = new ProjectionPicker("testContainer", scene);
 
        scene.morphTo2D(0.0);
 
        func(container.firstChild);
        expect(widget.viewModel.dropDownVisible).toEqual(false);
 
        widget.destroy();
        document.body.removeChild(container);
      });
    }
 
    if (FeatureDetection.supportsPointerEvents()) {
      addCloseOnInputSpec("pointerDown", DomEventSimulator.firePointerDown);
      addDisabledDuringFlightSpec(
        "pointerDown",
        DomEventSimulator.firePointerDown
      );
      addDisabledIn2DSpec("pointerDown", DomEventSimulator.firePointerDown);
    } else {
      addCloseOnInputSpec("mousedown", DomEventSimulator.fireMouseDown);
      addCloseOnInputSpec("touchstart", DomEventSimulator.fireTouchStart);
      addDisabledDuringFlightSpec("mousedown", DomEventSimulator.fireMouseDown);
      addDisabledDuringFlightSpec(
        "touchstart",
        DomEventSimulator.fireTouchStart
      );
      addDisabledIn2DSpec("mousedown", DomEventSimulator.fireMouseDown);
      addDisabledIn2DSpec("touchstart", DomEventSimulator.fireTouchStart);
    }
 
    it("constructor throws with no scene", function () {
      expect(function () {
        return new ProjectionPicker(document.body, undefined);
      }).toThrowDeveloperError();
    });
 
    it("constructor throws with no element", function () {
      expect(function () {
        return new ProjectionPicker(undefined, scene);
      }).toThrowDeveloperError();
    });
 
    it("constructor throws with string element that does not exist", function () {
      expect(function () {
        return new ProjectionPicker("does not exist", scene);
      }).toThrowDeveloperError();
    });
  },
  "WebGL"
);