mirror of
https://github.com/Esri/offline-editor-js.git
synced 2025-12-15 15:20:05 +00:00
getEditsStoreSizeBytes() works also when the localStorage is not initialized (our keys don't exist)
This commit is contained in:
parent
1f2c10e0ea
commit
0f35c55f7b
@ -180,9 +180,11 @@ define(["esri/graphic"], function(Graphic)
|
||||
|
||||
getEditsStoreSizeBytes: function()
|
||||
{
|
||||
return EDITS_QUEUE_KEY.length + window.localStorage.getItem(EDITS_QUEUE_KEY).length +
|
||||
REDO_STACK_KEY.length + window.localStorage.getItem(REDO_STACK_KEY).length;
|
||||
var editsQueueValue = window.localStorage.getItem(EDITS_QUEUE_KEY);
|
||||
var redoStackValue = window.localStorage.getItem(REDO_STACK_KEY);
|
||||
|
||||
return (editsQueueValue? EDITS_QUEUE_KEY.length + editsQueueValue.length : 0) +
|
||||
(redoStackValue? REDO_STACK_KEY.length + redoStackValue.length : 0);
|
||||
},
|
||||
|
||||
getLocalStorageSizeBytes: function()
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
"use strict"
|
||||
"use strict";
|
||||
|
||||
var KEY_PREFIX = "__LOCAL_STORAGE_TEST__";
|
||||
var EDITS_QUEUE_KEY = "esriEditsQueue";
|
||||
var REDO_STACK_KEY = "esriRedoStack";
|
||||
|
||||
var EXECUTE_LONG_TESTS = true;
|
||||
|
||||
describe("Internal Methods", function()
|
||||
@ -445,7 +448,7 @@ describe("Public Interface", function()
|
||||
it("report edit store size", function()
|
||||
{
|
||||
usedBytes = g_editsStore.getEditsStoreSizeBytes();
|
||||
expect(usedBytes).toBe(705);
|
||||
expect(usedBytes).toBe(692);
|
||||
});
|
||||
|
||||
it("report total local storage size", function()
|
||||
@ -454,6 +457,14 @@ describe("Public Interface", function()
|
||||
expect(usedBytes).not.toBeGreaterThan(totalBytes);
|
||||
});
|
||||
|
||||
it("report edit store size when uninitalized", function()
|
||||
{
|
||||
window.localStorage.removeItem( EDITS_QUEUE_KEY );
|
||||
window.localStorage.removeItem( REDO_STACK_KEY );
|
||||
var usedBytes = g_editsStore.getEditsStoreSizeBytes();
|
||||
expect(usedBytes).toBe(0);
|
||||
});
|
||||
|
||||
it("exhaust localStorage capacity", function()
|
||||
{
|
||||
if( EXECUTE_LONG_TESTS )
|
||||
@ -461,6 +472,13 @@ describe("Public Interface", function()
|
||||
console.log("this will take some time");
|
||||
|
||||
var sizeBefore = g_editsStore.getLocalStorageSizeBytes();
|
||||
if( sizeBefore == 0)
|
||||
{
|
||||
// if not initialized, create the empty elements
|
||||
window.localStorage.setItem( EDITS_QUEUE_KEY, "");
|
||||
window.localStorage.setItem( REDO_STACK_KEY, "");
|
||||
sizeBefore = g_editsStore.getLocalStorageSizeBytes();
|
||||
}
|
||||
|
||||
// first, fill localStorage up to max capacity
|
||||
try
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user