Skip to content
This repository has been archived by the owner on Dec 1, 2017. It is now read-only.

Commit

Permalink
Bug 1274179 - Store table of contents pages in Firebase
Browse files Browse the repository at this point in the history
  • Loading branch information
fzzzy committed Jun 6, 2016
1 parent 926459f commit 7950252
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
9 changes: 9 additions & 0 deletions shared/js/actions.js
Expand Up @@ -144,6 +144,15 @@ loop.shared.actions = (function() {
userId: String
}),

/**
* Notifies that a tile has been received from the other peer.
*/
AddedPage: Action.define("addedPage", {
title: String,
url: String
// metadata: Object (optional)
}),

/**
* Used to send cursor data to the other peer
*/
Expand Down
13 changes: 13 additions & 0 deletions shared/js/dataDriver.js
Expand Up @@ -84,6 +84,15 @@ loop.DataDriver = function() {
]);
}

/**
* Add a page to the room's table of contents.
*
* @param {Object} page The page object to add.
*/
addPage(page) {
this.update("page", this.makeId(), page);
}

/**
* Send a text chat message by storing in the database.
*
Expand Down Expand Up @@ -403,6 +412,10 @@ loop.DataDriver = function() {
};
break;

case "page":
dispatchAction = "AddedPage";
break;

case "participant":
dispatchAction = "UpdatedParticipant";
dispatchExtra = {
Expand Down
29 changes: 29 additions & 0 deletions shared/test/dataDriver_test.js
Expand Up @@ -68,6 +68,35 @@ describe("loop.DataDriver", () => {
});
});

describe("#addPage", () => {
it("should send page data by updating a page record", () => {
driver.addPage({
url: "http://example.com",
title: "cool page"
});

let { method, requestBody, url } = requests[0];
expect(method).eql("PUT");
expect(requestBody).eql('{"timestamp":{".sv":"timestamp"},"value":{"url":"http://example.com","title":"cool page"}}');
expect(url.match(/([^\/]+).{12}\.json$/)[1]).eql("page!00000000");
});

it("should dispatch a AddedPage action for a page record", () => {
let record = {
title: "cool page",
url: "http://example.com"
};
driver._processRecord("page!00000000", {
timestamp: 1234567890123,
value: record
});

sinon.assert.calledWithExactly(dispatcher.dispatch,
new actions.AddedPage(record)
);
});
});

describe("#sendTextChatMessage", () => {
it("should send a message by updating a chat record", () => {
driver.sendTextChatMessage({
Expand Down

0 comments on commit 7950252

Please sign in to comment.