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

Bug 1274179 - Store table of contents pages in Firebase #477

Merged
merged 1 commit into from Jun 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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