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
import { FeatureDetection } from "../../../Source/Cesium.js";
import DomEventSimulator from "../../DomEventSimulator.js";
import { NavigationHelpButton } from "../../../Source/Cesium.js";
 
describe("Widgets/NavigationHelpButton/NavigationHelpButton", function () {
  it("can create and destroy", function () {
    var container = document.createElement("span");
    container.id = "testContainer";
    document.body.appendChild(container);
 
    var widget = new NavigationHelpButton({
      container: "testContainer",
    });
    expect(widget.container.id).toBe(container.id);
    expect(widget.isDestroyed()).toEqual(false);
 
    widget.destroy();
    expect(widget.isDestroyed()).toEqual(true);
 
    document.body.removeChild(container);
  });
 
  it("does not show instructions by default", function () {
    var widget = new NavigationHelpButton({
      container: document.body,
    });
    expect(widget.viewModel.showInstructions).toBe(false);
    widget.destroy();
  });
 
  it("shows instructions by default if told to do so in the constructor", function () {
    var widget = new NavigationHelpButton({
      container: document.body,
      instructionsInitiallyVisible: true,
    });
    expect(widget.viewModel.showInstructions).toBe(true);
    widget.destroy();
  });
 
  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 NavigationHelpButton({
          container: "testContainer",
        });
 
        widget.viewModel.showInstructions = true;
        func(document.body);
        expect(widget.viewModel.showInstructions).toEqual(false);
 
        widget.viewModel.showInstructions = true;
        func(container.firstChild);
        expect(widget.viewModel.showInstructions).toEqual(true);
 
        widget.destroy();
        document.body.removeChild(container);
      }
    );
  }
 
  if (FeatureDetection.supportsPointerEvents()) {
    addCloseOnInputSpec("pointerDown", DomEventSimulator.firePointerDown);
  } else {
    addCloseOnInputSpec("mousedown", DomEventSimulator.fireMouseDown);
    addCloseOnInputSpec("touchstart", DomEventSimulator.fireTouchStart);
  }
 
  it("throws if container is undefined", function () {
    expect(function () {
      return new NavigationHelpButton({
        container: undefined,
      });
    }).toThrowDeveloperError();
  });
 
  it("throws if options is undefined", function () {
    expect(function () {
      return new NavigationHelpButton(undefined);
    }).toThrowDeveloperError();
  });
 
  it("throws if options.container is undefined", function () {
    expect(function () {
      return new NavigationHelpButton({
        container: undefined,
      });
    }).toThrowDeveloperError();
  });
 
  it("constructor throws with string element that does not exist", function () {
    expect(function () {
      return new NavigationHelpButton({
        container: "does not exist",
      });
    }).toThrowDeveloperError();
  });
});