diff --git a/resources/static/shared/storage.js b/resources/static/shared/storage.js index 16cd8cd13cb75acb2267d993da3cc477099fe727..f87cff94401569a58f25c75d168abbdd0583b5de 100644 --- a/resources/static/shared/storage.js +++ b/resources/static/shared/storage.js @@ -505,30 +505,31 @@ BrowserID.Storage = (function() { interactionData: { /** - * add a data interaction blob to localstorage + * add a new interaction blob to localstorage, this will *push* any stored + * blobs to the 'completed' backlog, and happens when a new dialog interaction + * begins. * @param {object} data - an object to push onto the queue * @method interactionData.push() * @returns nada */ push: pushInteractionData, /** - * read the current interaction data blob (the one on the top of the - * stack) + * read the interaction data blob associated with the current interaction * @method interactionData.current() * @returns a JSON object containing the latest interaction data blob */ current: currentInteractionData, /** - * overwrite the current interaction data blob (the one on the top of the - * stack) + * overwrite the interaction data blob associated with the current interaction * @param {object} data - the object to overwrite current with * @method interactionData.setCurrent() */ setCurrent: setCurrentInteractionData, /** - * get all the saved interaction data (returned as a JSON array) + * get all past saved interaction data (returned as a JSON array), excluding + * the "current" data (that which is being collected now). * @method interactionData.get() - * @returns an array, possibly of length zero if no interaction data is + * @returns an array, possibly of length zero if no past interaction data is * available */ get: getAllInteractionData, diff --git a/resources/static/test/cases/shared/storage.js b/resources/static/test/cases/shared/storage.js index d9852da0983718c199364536ca752b4a71b7c65e..5bab4b78ed7d0164c80d29957d29a63da4da76ba 100644 --- a/resources/static/test/cases/shared/storage.js +++ b/resources/static/test/cases/shared/storage.js @@ -164,5 +164,40 @@ storage.signInEmail.remove(); equal(typeof storage.signInEmail.get(), "undefined", "after remove, signInEmail is empty"); }); + + test("push interaction data and get current", function() { + storage.interactionData.push({ foo: "bar" }); + equal(storage.interactionData.current().foo, "bar", + "after pushing new interaction data, it's returned from .current()"); + }); + + test("set interaction data overwrites current", function() { + storage.interactionData.clear(); + storage.interactionData.push({ foo: "bar" }); + storage.interactionData.setCurrent({ foo: "baz" }); + equal(storage.interactionData.current().foo, "baz", + "overwriting current interaction data works"); + equal(storage.interactionData.get().length, 1, + "overwriting doesn't append"); + }); + + test("clear interaction data", function() { + storage.interactionData.push({ foo: "bar" }); + storage.interactionData.push({ foo: "bar" }); + storage.interactionData.clear(); + equal(storage.interactionData.get().length, 0, + "after clearing, interaction data is zero length"); + }); + + test("get interaction data returns everything except current (in-progress) data", function() { + storage.interactionData.push({ foo: "old2" }); + storage.interactionData.clear(); + storage.interactionData.push({ foo: "old1" }); + storage.interactionData.push({ foo: "current" }); + var d = storage.interactionData.get(); + equal(d.length, 2, "get() returns complete unpublished data blobs"); + equal(d[0].foo, 'old1', "get() returns complete unpublished data blobs"); + equal(d[1].foo, 'old2', "get() returns complete unpublished data blobs"); + }); }());