From 994fcceaced4ccc68fb6038f0ce8d23df566e8ff Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 1 Jul 2015 12:03:34 +0100 Subject: [PATCH] Add another storeRoom test. Add stub tests for WebStorage. --- lib/store/webstorage.js | 6 ++-- spec/unit/webstorage.spec.js | 63 +++++++++++++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/lib/store/webstorage.js b/lib/store/webstorage.js index 8f1d81618..6ab2bd72e 100644 --- a/lib/store/webstorage.js +++ b/lib/store/webstorage.js @@ -282,7 +282,7 @@ function SerialisedRoom(roomId) { */ SerialisedRoom.fromRoom = function(room, batchSize) { var self = new SerialisedRoom(room.roomId); - var i, ptr; + var ptr; self.state.pagination_token = room.oldState.paginationToken; // [room_$ROOMID_state] downcast to POJO from MatrixEvent utils.forEach(utils.keys(room.currentState.events), function(eventType) { @@ -303,7 +303,7 @@ SerialisedRoom.fromRoom = function(room, batchSize) { self.timeline[ptr] = room.timeline.slice( ptr * batchSize, (ptr + 1) * batchSize ); - self.timeline[ptr] = utils.map(self.timeline[ptr][i], function(me) { + self.timeline[ptr] = utils.map(self.timeline[ptr], function(me) { // use POJO not MatrixEvent return me.event; }); @@ -363,7 +363,7 @@ function loadRoom(store, roomId, numEvents) { function persist(store, serRoom) { store.setItem(keyName(serRoom.roomId, "state"), serRoom.state); - utils.keys(serRoom.timeline, function(index) { + utils.forEach(utils.keys(serRoom.timeline), function(index) { store.setItem( keyName(serRoom.roomId, "timeline", index), serRoom.timeline[index] diff --git a/spec/unit/webstorage.spec.js b/spec/unit/webstorage.spec.js index bd1c8c916..9b96996c4 100644 --- a/spec/unit/webstorage.spec.js +++ b/spec/unit/webstorage.spec.js @@ -49,6 +49,22 @@ describe("WebStorageStore", function() { room = new Room(roomId); }); + describe("getSyncToken", function() { + it("should return the token from the store", function() { + + }); + it("should return null if the token does not exist", function() { + + }); + }); + + describe("setSyncToken", function() { + it("should store the token in the store, which is retrievable from " + + "getSyncToken", function() { + + }); + }); + describe("storeRoom", function() { it("should persist the room state correctly", function() { var stateEvents = [ @@ -70,7 +86,52 @@ describe("WebStorageStore", function() { expect(storedEvents["m.room.create"][""]).toEqual(stateEvents[0].event); }); - xit("should persist timeline events correctly", function() { + it("should persist timeline events correctly", function() { + var prefix = "room_" + roomId + "_timeline_"; + var timelineEvents = []; + var entries = batchNum + batchNum - 1; + var i = 0; + for (i = 0; i < entries; i++) { + timelineEvents.push( + utils.mkMessage({room: roomId, user: userId, event: true}) + ); + } + room.timeline = timelineEvents; + store.storeRoom(room); + expect(mockStorageApi.getItem(prefix + "-1")).toBe(null); + expect(mockStorageApi.getItem(prefix + "2")).toBe(null); + expect(mockStorageApi.getItem(prefix + "live")).toBe(null); + var timeline0 = mockStorageApi.getItem(prefix + "0"); + var timeline1 = mockStorageApi.getItem(prefix + "1"); + expect(timeline0.length).toEqual(batchNum); + expect(timeline1.length).toEqual(batchNum - 1); + for (i = 0; i < batchNum; i++) { + expect(timeline0[i]).toEqual(timelineEvents[i].event); + if ((i + batchNum) < timelineEvents.length) { + expect(timeline1[i]).toEqual(timelineEvents[i + batchNum].event); + } + } + }); + }); + + describe("getRoom", function() { + it("should reconstruct room state", function() { + + }); + it("should reconstruct the room timeline", function() { + + }); + it("should sync the timeline for any 'live' events", function() { + + }); + it("should be able to reconstruct the timeline with negative indices", + function() { + + }); + it("should return null if the room doesn't exist", function() { + + }); + it("should assign a storageToken to the Room", function() { }); });