diff --git a/test/jasmine/spec/offlineEnablerSpec.js b/test/jasmine/spec/offlineEnablerSpec.js index 7dbb231..0870523 100644 --- a/test/jasmine/spec/offlineEnablerSpec.js +++ b/test/jasmine/spec/offlineEnablerSpec.js @@ -41,20 +41,26 @@ describe("offline enabler library", function() { waitsFor(function(){ return initCompleted; }); - expect(g_basemapLayer.goOffline).toEqual(jasmine.any(Function)); - expect(g_basemapLayer.offline.online).toEqual(true); - g_basemapLayer.goOffline(); - expect(g_basemapLayer.offline.online).toEqual(false); + runs(function() + { + expect(g_basemapLayer.goOffline).toEqual(jasmine.any(Function)); + expect(g_basemapLayer.offline.online).toEqual(true); + g_basemapLayer.goOffline(); + expect(g_basemapLayer.offline.online).toEqual(false); + }); }); it("can go online", function() { waitsFor(function(){ return initCompleted; }); - expect(g_basemapLayer.goOffline).toEqual(jasmine.any(Function)); - expect(g_basemapLayer.offline.online).toEqual(false); - g_basemapLayer.goOnline(); - expect(g_basemapLayer.offline.online).toEqual(true); + runs(function() + { + expect(g_basemapLayer.goOffline).toEqual(jasmine.any(Function)); + expect(g_basemapLayer.offline.online).toEqual(false); + g_basemapLayer.goOnline(); + expect(g_basemapLayer.offline.online).toEqual(true); + }); }) it("delete all tiles", function() @@ -78,19 +84,81 @@ describe("offline enabler library", function() { waitsFor(function(){ return initCompleted; }); - g_basemapLayer.getOfflineUsage(function(usage) - { - expect(usage.tileCount).toEqual(0); - g_basemapLayer.storeTile(14,6177,8023, function(success) + runs(function() + { + g_basemapLayer.getOfflineUsage(function(usage) { - expect(success).toEqual(true); - g_basemapLayer.getOfflineUsage(function(usage) + expect(usage.tileCount).toEqual(0); + g_basemapLayer.storeTile(14,6177,8023, function(success) { - expect(usage.tileCount).toEqual(1); + expect(success).toEqual(true); + g_basemapLayer.getOfflineUsage(function(usage) + { + expect(usage.tileCount).toEqual(1); + }); }); }); + }) + }); + + it("gets level estimation", function() + { + waitsFor(function(){ return initCompleted; }); + + runs(function() + { + require(["esri/geometry/Extent"],function(Extent) + { + var extent = new Extent({"xmin":-822542.2830377579,"ymin":4580841.761960262,"xmax":94702.05638410954,"ymax":5131188.365613382,"spatialReference":{"wkid":102100}}); + var tileSize = g_basemapLayer.estimateTileSize(); + var estimation = g_basemapLayer.getLevelEstimation(extent,10); + expect(estimation.tileCount).toEqual(375); + expect(estimation.sizeBytes).toEqual(estimation.tileCount * tileSize); + var estimation = g_basemapLayer.getLevelEstimation(extent,8); + expect(estimation.tileCount).toEqual(28); + expect(estimation.sizeBytes).toEqual(estimation.tileCount * tileSize); + var estimation = g_basemapLayer.getLevelEstimation(extent,2); + expect(estimation.tileCount).toEqual(2); + expect(estimation.sizeBytes).toEqual(estimation.tileCount * tileSize); + }); }); }); - + /* + it("prepares the layer for offline usage", function() + { + var finished = false; + + runs(function() + { + require(["esri/geometry/Extent"], function(Extent) + { + g_basemapLayer.deleteAllTiles(function(success) + { + var extent = new Extent({"xmin":-822542.2830377579,"ymin":4580841.761960262,"xmax":94702.05638410954,"ymax":5131188.365613382,"spatialReference":{"wkid":102100}}); + var reportProgress = jasmine.createSpy(); + var finishedDownloading = function(err) + { + console.log("finishedDownloading"); + expect(err).not.toBeTruthy(); + expect(reportProgress).toHaveBeenCalled(); + expect(reportProgress.callCount).toEqual(21); // 28 + + g_basemapLayer.getOfflineUsage(function(usage) + { + expect(usage.tileCount).toEqual(28); + finished = true; + }); + } + + console.log("preparing"); + g_basemapLayer.prepareForOffline(8,8,extent,reportProgress, finishedDownloading); + console.log("prepared"); + }); + }); + }); + + waitsFor(function(){ return finished; }); + }); + */ }); \ No newline at end of file