yzt
2023-05-05 4c558c77a6a9d23f057f094c4dc3e315eabef497
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
import { JulianDate } from "../../Source/Cesium.js";
import { CallbackProperty } from "../../Source/Cesium.js";
 
describe("DataSources/CallbackProperty", function () {
  var time = JulianDate.now();
 
  it("callback received proper parameters", function () {
    var result = {};
    var callback = jasmine.createSpy("callback");
    var property = new CallbackProperty(callback, true);
    property.getValue(time, result);
    expect(callback).toHaveBeenCalledWith(time, result);
  });
 
  it("getValue returns callback result", function () {
    var result = {};
    var callback = function (time, result) {
      return result;
    };
    var property = new CallbackProperty(callback, true);
    expect(property.getValue(time, result)).toBe(result);
  });
 
  it("isConstant returns correct value", function () {
    var property = new CallbackProperty(function () {}, true);
    expect(property.isConstant).toBe(true);
    property.setCallback(function () {}, false);
    expect(property.isConstant).toBe(false);
  });
 
  it("setCallback raises definitionChanged event", function () {
    var property = new CallbackProperty(function () {}, true);
    var listener = jasmine.createSpy("listener");
    property.definitionChanged.addEventListener(listener);
    property.setCallback(function () {}, false);
    expect(listener).toHaveBeenCalledWith(property);
  });
 
  it("constructor throws with undefined isConstant", function () {
    expect(function () {
      return new CallbackProperty(function () {}, undefined);
    }).toThrowDeveloperError();
  });
 
  it("constructor throws with undefined callback", function () {
    expect(function () {
      return new CallbackProperty(undefined, true);
    }).toThrowDeveloperError();
  });
 
  it("equals works", function () {
    var callback = function () {};
    var left = new CallbackProperty(callback, true);
    var right = new CallbackProperty(callback, true);
 
    expect(left.equals(right)).toEqual(true);
 
    right.setCallback(callback, false);
    expect(left.equals(right)).toEqual(false);
 
    right.setCallback(function () {
      return undefined;
    }, true);
    expect(left.equals(right)).toEqual(false);
  });
});