cesium/packages/engine/Specs/DataSources/CustomDataSourceSpec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

80 lines
2.6 KiB
JavaScript
Raw Permalink Normal View History

2022-07-22 05:32:08 +08:00
import {
Event,
CustomDataSource,
DataSourceClock,
EntityCollection,
2022-11-02 03:39:57 +08:00
} from "../../index.js";
2020-04-17 08:31:36 +08:00
describe("DataSources/CustomDataSource", function () {
2015-01-08 06:54:23 +08:00
it("constructor has expected defaults", function () {
const dataSource = new CustomDataSource();
expect(dataSource.name).toBeUndefined();
expect(dataSource.clock).toBeUndefined();
expect(dataSource.entities).toBeInstanceOf(EntityCollection);
expect(dataSource.isLoading).toBe(false);
expect(dataSource.changedEvent).toBeInstanceOf(Event);
expect(dataSource.errorEvent).toBeInstanceOf(Event);
expect(dataSource.loadingEvent).toBeInstanceOf(Event);
expect(dataSource.show).toBe(true);
});
2020-04-17 08:31:36 +08:00
it("show sets underlying entity collection show.", function () {
const dataSource = new CustomDataSource();
2020-04-17 08:31:36 +08:00
dataSource.show = false;
expect(dataSource.show).toBe(false);
expect(dataSource.show).toEqual(dataSource.entities.show);
2020-04-17 08:31:36 +08:00
dataSource.show = true;
expect(dataSource.show).toBe(true);
expect(dataSource.show).toEqual(dataSource.entities.show);
2015-01-08 06:54:23 +08:00
});
2020-04-17 08:31:36 +08:00
2015-01-08 06:54:23 +08:00
it("setting name raises changed event", function () {
const dataSource = new CustomDataSource();
2020-04-17 08:31:36 +08:00
2015-01-08 06:54:23 +08:00
const spy = jasmine.createSpy("changedEvent");
dataSource.changedEvent.addEventListener(spy);
2020-04-17 08:31:36 +08:00
2015-01-08 06:54:23 +08:00
const newName = "chester";
dataSource.name = newName;
expect(dataSource.name).toEqual(newName);
expect(spy.calls.count()).toEqual(1);
2015-01-08 06:54:23 +08:00
expect(spy).toHaveBeenCalledWith(dataSource);
});
2020-04-17 08:31:36 +08:00
2015-01-08 06:54:23 +08:00
it("setting clock raises changed event", function () {
const dataSource = new CustomDataSource();
2020-04-17 08:31:36 +08:00
2015-01-08 06:54:23 +08:00
const spy = jasmine.createSpy("changedEvent");
dataSource.changedEvent.addEventListener(spy);
2020-04-17 08:31:36 +08:00
2015-01-08 06:54:23 +08:00
const newClock = new DataSourceClock();
dataSource.clock = newClock;
expect(dataSource.clock).toBe(newClock);
expect(spy.calls.count()).toEqual(1);
2015-01-08 06:54:23 +08:00
expect(spy).toHaveBeenCalledWith(dataSource);
});
2020-04-17 08:31:36 +08:00
2015-01-08 06:54:23 +08:00
it("setting isLoading raises loading event", function () {
const dataSource = new CustomDataSource();
2020-04-17 08:31:36 +08:00
2015-01-08 06:54:23 +08:00
const spy = jasmine.createSpy("loadingEvent");
dataSource.loadingEvent.addEventListener(spy);
2020-04-17 08:31:36 +08:00
2015-01-08 06:54:23 +08:00
dataSource.isLoading = true;
expect(spy.calls.count()).toEqual(1);
2015-01-08 06:54:23 +08:00
expect(spy).toHaveBeenCalledWith(dataSource, true);
2020-04-17 08:31:36 +08:00
2015-01-08 06:54:23 +08:00
dataSource.isLoading = false;
expect(spy.calls.count()).toEqual(2);
2015-01-08 06:54:23 +08:00
expect(spy).toHaveBeenCalledWith(dataSource, false);
});
2020-04-17 08:31:36 +08:00
it("has entity collection with link to data source", function () {
const dataSource = new CustomDataSource();
const entityCollection = dataSource.entities;
expect(entityCollection.owner).toEqual(dataSource);
});
});