@@ -345,35 +345,85 @@ describe('ImageCollectionService', () => {
345345 service.getItemByID('featureId');
346346 });
347347
348- it('should call getItemByID parameter wrong', function (done) {
349- var getFeatureProcessFailed = (res) => {
350- try {
351- expect(res.error.description).not.toBeNull();
352- expect(res.error.code).toEqual(400);
353- service.destroy();
354- expect(service.EVENT_TYPES).toBeNull();
355- expect(service.events).toBeNull();
356- done();
357- } catch (exception) {
358- expect(false).toBeTruthy();
359- console.log('ImageCollectionService' + exception.name + ':' + exception.message);
360- service.destroy();
361- done();
362- }
363- };
364- service = new ImageCollectionService(requestUrl, {
365- collectionId: 'wrongId',
366- eventListeners: {
367- processFailed: getFeatureProcessFailed
368- }
369- });
370- spyOn(FetchRequest, 'get').and.callFake((url) => {
371- expect(url).toEqual(requestUrl + '/collections/wrongId/items/wrongId');
372- return Promise.resolve(
373- new Response(`{"succeed":false,"error":{"code":400,"description":"not found in resources."}}`)
374- );
375- });
376- service.getItemByID('wrongId');
348+ it('should call getTileInfo getStatistics getLegend', function (done) {
349+ var queryParams = {
350+ renderingRule: new ImageRenderingRule({ displayMode: 'Composite' })
351+ };
352+ service = new ImageCollectionService(requestUrl, { collectionId: 'collectionId' });
353+ spyOn(FetchRequest, 'get').and.callFake((url) => {
354+ if(url.includes('tileInfo')) {
355+ expect(url).toEqual(requestUrl + '/collections/collectionId/tileInfo');
356+ return Promise.resolve(new Response(JSON.stringify(getCollectionTileInfoJson)));
357+ }
358+ if(url.includes('statistics')) {
359+ expect(url).toEqual(requestUrl + '/collections/collectionId/statistics');
360+ return Promise.resolve(new Response(JSON.stringify(getCollectionStatisticsJson)));
361+ }
362+ if(url.includes('legend')) {
363+ expect(url).toEqual(requestUrl + '/collections/collectionId/legend');
364+ return Promise.resolve(new Response(JSON.stringify(getCollectionLegendJson)));
365+ }
366+ if(url.includes('items')) {
367+ expect(url).toEqual(requestUrl + '/collections/collectionId/items/wrongId');
368+ return Promise.resolve(
369+ new Response(`{"succeed":false,"error":{"code":400,"description":"not found in resources."}}`)
370+ );
371+ }
372+ });
373+ service.getTileInfo((res) => {
374+ try {
375+ var result = res.result;
376+ expect(result).not.toBeNull();
377+ expect(result.origin).not.toBeNull();
378+ expect(result.levels[0]).not.toBeNull();
379+ expect(result.format).toEqual('string');
380+ expect(result.crs).toEqual('string');
381+ expect(result.width).toEqual(0);
382+ expect(result.height).toEqual(0);
383+ expect(result.dpi).toEqual(0);
384+ } catch (exception) {
385+ expect(false).toBeTruthy();
386+ console.log('ImageCollectionService' + exception.name + ':' + exception.message);
387+ }
388+ });
389+ service.getStatistics((res) => {
390+ try {
391+ var result = res.result;
392+ expect(result).not.toBeNull();
393+ expect(result.extent).not.toBeNull();
394+ expect(result.storageType[0]).toEqual('Local');
395+ expect(result.collectionId).toEqual('string');
396+ expect(result.pixelType).toEqual('UNKNOWN');
397+ expect(result.bandCount).toEqual(0);
398+ } catch (exception) {
399+ expect(false).toBeTruthy();
400+ console.log('ImageCollectionService' + exception.name + ':' + exception.message);
401+ }
402+ });
403+ service.getLegend(queryParams, (res) => {
404+ try {
405+ var result = res.result;
406+ expect(result).not.toBeNull();
407+ expect(result.layerId).toEqual(0);
408+ expect(result.layerName).toEqual('DLTB');
409+ expect(result.legendType).toEqual('Unique Values');
410+ expect(result.legendCells.length).toEqual(1);
411+ } catch (exception) {
412+ expect(false).toBeTruthy();
413+ console.log('ImageCollectionService' + exception.name + ':' + exception.message);
414+ }
415+ });
416+ service.getItemByID('wrongId', (res) => {
417+ try {
418+ expect(res.error.description).not.toBeNull();
419+ expect(res.error.code).toEqual(400);
420+ } catch (exception) {
421+ expect(false).toBeTruthy();
422+ console.log('ImageCollectionService' + exception.name + ':' + exception.message);
423+ } finally {
424+ done();
425+ }
426+ });
377427 });
378428
379429 xit('should call patchFeature successfully', function (done) {
0 commit comments