Skip to content

Commit

Permalink
Fix ArcGisMapServerCatalogItem test failures.
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Aug 13, 2023
1 parent 9b0d70d commit c5f4177
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 48 deletions.
36 changes: 24 additions & 12 deletions src/Models/Catalog/Esri/ArcGisMapServerCatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,10 @@ export default class ArcGisMapServerCatalogItem extends UrlMixin(
}

override _protected_forceLoadMapItems(): Promise<void> {
return this._protected_forceLoadMetadata();
return Promise.all([
this._private_currentImageryPromise,
this._private_nextImageryPromise
]).then(() => {});
}

@override
Expand Down Expand Up @@ -397,14 +400,19 @@ export default class ArcGisMapServerCatalogItem extends UrlMixin(
}

@computed
get _private_currentImageryParts(): ImageryParts | undefined {
get _private_currentImageryPromise() {
const dateAsUnix: string | undefined =
this.currentDiscreteTimeTag === undefined
? undefined
: new Date(this.currentDiscreteTimeTag).getTime().toString();

return this._private_createImageryProvider(dateAsUnix);
}

@computed
get _private_currentImageryParts(): ImageryParts | undefined {
const imageryProviderObservablePromise =
this._private_createImageryProvider(dateAsUnix);
this._private_currentImageryPromise;

// Return an ImageryPart when the the promise is fulfilled with a valid imageryProvider
const imageryPart =
Expand All @@ -424,16 +432,23 @@ export default class ArcGisMapServerCatalogItem extends UrlMixin(
}

@computed
get _private_nextImageryParts(): ImageryParts | undefined {
get _private_nextImageryPromise() {
if (
this.terria.timelineStack.contains(this) &&
!this.isPaused &&
this.nextDiscreteTimeTag
) {
const dateAsUnix: number = new Date(this.nextDiscreteTimeTag).getTime();
const imageryProviderObservablePromise =
this._private_createImageryProvider(dateAsUnix.toString());
return this._private_createImageryProvider(dateAsUnix.toString());
} else {
return undefined;
}
}

@computed
get _private_nextImageryParts(): ImageryParts | undefined {
const imageryProviderObservablePromise = this._private_nextImageryPromise;
if (isDefined(imageryProviderObservablePromise)) {
imageryProviderObservablePromise.case({
fulfilled: (imageryProvider) => {
// Disable feature picking for the next imagery layer
Expand Down Expand Up @@ -492,17 +507,14 @@ export default class ArcGisMapServerCatalogItem extends UrlMixin(
maximumLevel: maximumLevel,
tileHeight: this.tileHeight,
tileWidth: this.tileWidth,
// TODO: bring over parameters option from terriajs-cesium
//parameters: params,
parameters: params,

Check failure on line 510 in src/Models/Catalog/Esri/ArcGisMapServerCatalogItem.ts

View workflow job for this annotation

GitHub Actions / build

Argument of type '{ layers: string; tilingScheme: WebMercatorTilingScheme; maximumLevel: number | undefined; tileHeight: number; tileWidth: number; parameters: any; enablePickFeatures: boolean; usePreCachedTilesIfAvailable: boolean; mapServerData: MapServer; token: string | undefined; credit: string | undefined; }' is not assignable to parameter of type 'ConstructorOptions'.

Check failure on line 510 in src/Models/Catalog/Esri/ArcGisMapServerCatalogItem.ts

View workflow job for this annotation

GitHub Actions / deploy

Argument of type '{ layers: string; tilingScheme: WebMercatorTilingScheme; maximumLevel: number | undefined; tileHeight: number; tileWidth: number; parameters: any; enablePickFeatures: boolean; usePreCachedTilesIfAvailable: boolean; mapServerData: MapServer; token: string | undefined; credit: string | undefined; }' is not assignable to parameter of type 'ConstructorOptions'.
enablePickFeatures: this.allowFeaturePicking,
/** Only used "pre-cached" tiles if we aren't requesting any specific layers
* If the `layersArray` property is specified, we request individual dynamic layers and ignore the fused map cache.
*/
usePreCachedTilesIfAvailable: this.layersArray.length == 0,
// TODO: bring over mapServerData option from terriajs-cesium
//mapServerData: stratum.mapServer,
// TODO: add missing token parameter to Cesium's typescript definitions
//token: stratum.token,
mapServerData: stratum.mapServer,
token: stratum.token,
credit: this.attribution
}
);
Expand Down
36 changes: 0 additions & 36 deletions test/Models/Catalog/esri/ArcGisMapServerCatalogItemSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ describe("ArcGisMapServerCatalogItem", function () {
});

describe("when tokenUrl is set", function () {
let disposeReaction: IReactionDisposer;

beforeEach(() => {
runInAction(() => {
item = new ArcGisMapServerCatalogItem("test", new Terria());
Expand All @@ -145,22 +143,6 @@ describe("ArcGisMapServerCatalogItem", function () {
"http://example.com/token"
);
});

// We need to create a reaction that watches the mapItems to prevent
// `mobx` from suspending the computed value for `mapItems`. If the
// value gets suspended each access to `.mapItems` will create a new
// `ArcGisMapServerImageryProvider`. `ArcGisMapServerImageryProvider`
// creation is asynchronous, so `mapItems` will return an empty array
// until the imagery provider is available and will break our specs
// breaking.
disposeReaction = reaction(
() => item.mapItems,
() => {}
);
});

afterEach(function () {
disposeReaction();
});

it("fetches the token", async function () {
Expand All @@ -187,33 +169,15 @@ describe("ArcGisMapServerCatalogItem", function () {
});

describe("after loading", function () {
let disposeReaction: IReactionDisposer;

beforeEach(async function () {
runInAction(() => {
item = new ArcGisMapServerCatalogItem("test", new Terria());
item.setTrait(CommonStrata.definition, "url", mapServerUrl);
});
await item.loadMapItems();

// We need to create a reaction that watches the mapItems to prevent
// `mobx` from suspending the computed value for `mapItems`. If the
// value gets suspended each access to `.mapItems` will create a new
// `ArcGisMapServerImageryProvider`. `ArcGisMapServerImageryProvider`
// creation is asynchronous, so `mapItems` will return an empty array
// until the imagery provider is available and will break our specs
// breaking.
disposeReaction = reaction(
() => item.mapItems,
() => {}
);
await when(() => item.mapItems.length > 0);
});

afterEach(function () {
disposeReaction();
});

it("returns exactly one mapItems", function () {
expect(item.mapItems.length).toBe(1);
});
Expand Down

0 comments on commit c5f4177

Please sign in to comment.