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
import { defined } from "../../../Source/Cesium.js";
import pollToPromise from "../../pollToPromise.js";
import { InfoBox } from "../../../Source/Cesium.js";
 
describe("Widgets/InfoBox/InfoBox", function () {
  var testContainer;
  var infoBox;
  beforeEach(function () {
    testContainer = document.createElement("span");
    testContainer.id = "testContainer";
    document.body.appendChild(testContainer);
  });
 
  afterEach(function () {
    if (defined(infoBox) && !infoBox.isDestroyed()) {
      infoBox = infoBox.destroy();
    }
    document.body.removeChild(testContainer);
  });
 
  it("constructor sets expected values", function () {
    infoBox = new InfoBox(testContainer);
    expect(infoBox.container).toBe(testContainer);
    expect(infoBox.viewModel).toBeDefined();
    expect(infoBox.isDestroyed()).toEqual(false);
    infoBox.destroy();
    expect(infoBox.isDestroyed()).toEqual(true);
  });
 
  it("can set description body", function () {
    var infoBox = new InfoBox(testContainer);
    var node;
 
    var infoElement = testContainer.firstChild;
 
    infoBox.viewModel.description = "Please do not crash";
    return pollToPromise(function () {
      node = infoBox.frame.contentDocument.body.firstChild;
      return node !== null;
    })
      .then(function () {
        expect(infoElement.style["background-color"]).toEqual("");
        return pollToPromise(function () {
          return node.innerHTML === infoBox.viewModel.description;
        });
      })
      .then(function () {
        infoBox.viewModel.description =
          '<div style="background-color: rgb(255, 255, 255);">Please do not crash</div>';
        expect(infoElement.style["background-color"]).toEqual(
          "rgb(255, 255, 255)"
        );
        return pollToPromise(function () {
          return node.innerHTML === infoBox.viewModel.description;
        });
      })
      .then(function () {
        expect(infoElement["background-color"]).toBeUndefined();
      });
  });
 
  it("constructor works with string id container", function () {
    infoBox = new InfoBox("testContainer");
    expect(infoBox.container.id).toBe(testContainer.id);
  });
 
  it("throws if container is undefined", function () {
    expect(function () {
      return new InfoBox(undefined);
    }).toThrowDeveloperError();
  });
 
  it("throws if container string is undefined", function () {
    expect(function () {
      return new InfoBox("foo");
    }).toThrowDeveloperError();
  });
});