diff --git a/lib/edit/editsStore.js b/lib/edit/editsStore.js index a43bde1..1b7806b 100644 --- a/lib/edit/editsStore.js +++ b/lib/edit/editsStore.js @@ -425,7 +425,17 @@ O.esri.Edit.EditStore = function () { }; /** - * Removes some phantom graphics from database + * Removes some phantom graphics from database. + * The responseObject contains {id,layer,tempId,addResults,updateResults,deleteResults}. + * IF there are no results.success then nothing will be deleted. + * + * WARNING: Can generate false positives. IndexedDB will always return success + * even if you attempt to delete a non-existent id. + * + * CAUTION: This should always be used in conjunction with deleting the phantom graphic's + * associated edit entry in the database. + * + * @param responseObject * @param callback boolean */ this.resetLimitedPhantomGraphicsQueue = function (responseObject, callback) { @@ -454,30 +464,18 @@ O.esri.Edit.EditStore = function () { // CAUTION: // TO-DO we do NOT match the edit.id with edit's objectId - if (edit.updateResults.length > 0) { - if (edit.updateResults[0].success) { - objectStore.delete(id); - } - } - if (edit.deleteResults.length > 0) { - if (edit.deleteResults[0].success) { - objectStore.delete(id); - } - } - if (edit.addResults.length > 0) { - if (edit.addResults[0].success) { + // If we have an add, update or delete success then delete the entry, otherwise we skip it. + if (edit.updateResults.length > 0 || edit.deleteResults.length > 0 || edit.addResults.length > 0) { + if (edit.updateResults[0].success || edit.deleteResults[0].success || edit.addResults[0].success) { objectStore.delete(id); } } } } - callback(true); - } else { callback(true); } - }; diff --git a/test/spec/offlineFeaturesManagerSpec.js b/test/spec/offlineFeaturesManagerSpec.js index f470c50..bb5a90b 100644 --- a/test/spec/offlineFeaturesManagerSpec.js +++ b/test/spec/offlineFeaturesManagerSpec.js @@ -580,7 +580,7 @@ describe("Offline Editing", function() // //TO-DO //}); - describe("Test PhantomGraphicsLayer", function() + describe("Test PhantomGraphicsLayer using editsStore directly", function() { async.it("Get PhantomLayerGraphics array via editsStore", function(done){ g_editsStore.getPhantomGraphicsArray(function(results,errors){ @@ -721,6 +721,54 @@ describe("Offline Editing", function() // }); //}); + async.it("Delete one of the phantom graphics using resetLimitedPhantomGraphicsQueue()", function(done){ + var responseObject = { + 0:{ + "id":-1, + "updateResults":[ + { + "success":false + } + ], + "addResults":[ + { + "success":true + } + ], + "deleteResults":[ + { + "success":false + } + ] + } + }; + + g_editsStore.resetLimitedPhantomGraphicsQueue(responseObject,function(success){ + expect(success).toBe(true); + done(); + }); + }); + + async.it("Reverify total number of phantom graphics", function(done){ + g_editsStore._getPhantomGraphicsArraySimple(function(results,errors){ + + // We remove one graphic from the previous result and should now be @ 9 + expect(results.length).toBe(9); + //expect(results[0]).toBe("phantom-layer|@|-1"); + expect(results[0]).toBe("phantom-layer|@|-3"); + expect((results[1]).indexOf(g_editsStore.PHANTOM_GRAPHIC_PREFIX)).toBe(0); + expect((results[2]).indexOf(g_editsStore.PHANTOM_GRAPHIC_PREFIX)).toBe(0); + expect((results[3]).indexOf(g_editsStore.PHANTOM_GRAPHIC_PREFIX)).toBe(0); + expect((results[4]).indexOf(g_editsStore.PHANTOM_GRAPHIC_PREFIX)).toBe(0); + expect((results[5]).indexOf(g_editsStore.PHANTOM_GRAPHIC_PREFIX)).toBe(0); + expect((results[6]).indexOf(g_editsStore.PHANTOM_GRAPHIC_PREFIX)).toBe(0); + expect(results[7]).toBe("phantom-layer|@|test002"); + expect(results[8]).toBe("phantom-layer|@|test003"); + expect(errors).toBe("end"); + done(); + }) + }); + async.it("Delete all PhantomLayerGraphics", function(done){ g_editsStore.resetPhantomGraphicsQueue(function(result){ @@ -751,7 +799,7 @@ describe("Offline Editing", function() }) }); - async.it("store FeatureLayerJSON data", function(done){ + async.it("store FeatureLayerJSON data using editsStore directly", function(done){ var dataObject = { graphics: {test:1}, renderer: {test:2}