ClockViewModelSpec.js 3.82 KB
Newer Older
Manggar Mahardhika's avatar
Manggar Mahardhika committed
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
import { Clock } from "../../Source/Cesium.js";
import { ClockRange } from "../../Source/Cesium.js";
import { ClockStep } from "../../Source/Cesium.js";
import { JulianDate } from "../../Source/Cesium.js";
import { ClockViewModel } from "../../Source/Cesium.js";

describe("Widgets/ClockViewModel", function () {
  it("default constructor creates a clock", function () {
    var clockViewModel = new ClockViewModel();
    expect(clockViewModel.clock).toBeDefined();
  });

  it("constructor sets expected properties", function () {
    var clock = new Clock();
    clock.startTime = JulianDate.fromIso8601("2012-01-01T00:00:00");
    clock.stopTime = JulianDate.fromIso8601("2012-01-02T00:00:00");
    clock.currentTime = JulianDate.fromIso8601("2012-01-01T12:00:00");
    clock.multiplier = 1;
    clock.clockStep = ClockStep.TICK_DEPENDENT;
    clock.clockRange = ClockRange.UNBOUNDED;
    clock.shouldAnimate = false;

    var clockViewModel = new ClockViewModel(clock);
    expect(clockViewModel.clock).toBe(clock);
    expect(clockViewModel.startTime).toEqual(clock.startTime);
    expect(clockViewModel.stopTime).toEqual(clock.stopTime);
    expect(clockViewModel.currentTime).toEqual(clock.currentTime);
    expect(clockViewModel.multiplier).toEqual(clock.multiplier);
    expect(clockViewModel.clockStep).toEqual(clock.clockStep);
    expect(clockViewModel.clockRange).toEqual(clock.clockRange);
    expect(clockViewModel.systemTime).toBeDefined();
    expect(clockViewModel.shouldAnimate).toEqual(false);
  });

  it("observables are updated from the clock", function () {
    var clock = new Clock();
    clock.startTime = JulianDate.fromIso8601("2012-01-01T00:00:00");
    clock.stopTime = JulianDate.fromIso8601("2012-01-02T00:00:00");
    clock.currentTime = JulianDate.fromIso8601("2012-01-01T12:00:00");
    clock.multiplier = 1;
    clock.clockStep = ClockStep.TICK_DEPENDENT;
    clock.clockRange = ClockRange.UNBOUNDED;
    clock.shouldAnimate = false;

    var clockViewModel = new ClockViewModel(clock);
    expect(clockViewModel.clock).toBe(clock);
    expect(clockViewModel.startTime).toEqual(clock.startTime);
    expect(clockViewModel.stopTime).toEqual(clock.stopTime);
    expect(clockViewModel.currentTime).toEqual(clock.currentTime);
    expect(clockViewModel.multiplier).toEqual(clock.multiplier);
    expect(clockViewModel.clockStep).toEqual(clock.clockStep);
    expect(clockViewModel.clockRange).toEqual(clock.clockRange);
    expect(clockViewModel.shouldAnimate).toEqual(clock.shouldAnimate);
    expect(clockViewModel.systemTime).toBeDefined();

    clock.startTime = JulianDate.fromIso8601("2013-01-01T00:00:00");
    clock.stopTime = JulianDate.fromIso8601("2013-01-02T00:00:00");
    clock.currentTime = JulianDate.fromIso8601("2013-01-01T12:00:00");
    clock.multiplier = 2;
    clock.clockStep = ClockStep.SYSTEM_CLOCK_MULTIPLIER;
    clock.clockRange = ClockRange.CLAMPED;
    clock.shouldAnimate = true;

    expect(clockViewModel.startTime).not.toEqual(clock.startTime);
    expect(clockViewModel.stopTime).not.toEqual(clock.stopTime);
    expect(clockViewModel.currentTime).not.toEqual(clock.currentTime);
    expect(clockViewModel.multiplier).not.toEqual(clock.multiplier);
    expect(clockViewModel.clockStep).not.toEqual(clock.clockStep);
    expect(clockViewModel.clockRange).not.toEqual(clock.clockRange);
    expect(clockViewModel.shouldAnimate).not.toEqual(clock.shouldAnimate);

    clock.tick();

    expect(clockViewModel.startTime).toEqual(clock.startTime);
    expect(clockViewModel.stopTime).toEqual(clock.stopTime);
    expect(clockViewModel.currentTime).toEqual(clock.currentTime);
    expect(clockViewModel.multiplier).toEqual(clock.multiplier);
    expect(clockViewModel.clockStep).toEqual(clock.clockStep);
    expect(clockViewModel.clockRange).toEqual(clock.clockRange);
    expect(clockViewModel.shouldAnimate).toEqual(clock.shouldAnimate);
  });
});