Bug 1171940: introduce unit tests for the new room context flows inside the Hello conversation window. r=Standard8, a=ritu
authorMike de Boer <mdeboer@mozilla.com>
Thu, 16 Jul 2015 16:39:20 +0200
changeset 268866 b411cef27c22022133234a38aee6261c57ca43e8
parent 268865 0c8e3181f2f6fc51af1404122b73f3398f1a43d0
child 268867 f1d848ebdac5f8b3a9cf5af0e4f657bbb0b16b97
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-esr52@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8, ritu
bugs1171940
milestone41.0a2
Bug 1171940: introduce unit tests for the new room context flows inside the Hello conversation window. r=Standard8, a=ritu
browser/components/loop/test/desktop-local/roomViews_test.js
browser/components/loop/test/shared/textChatStore_test.js
browser/components/loop/test/shared/textChatView_test.js
--- a/browser/components/loop/test/desktop-local/roomViews_test.js
+++ b/browser/components/loop/test/desktop-local/roomViews_test.js
@@ -249,16 +249,49 @@ describe("loop.roomViews", function () {
         var shareBtn = view.getDOMNode().querySelector(".btn-share");
 
         React.addons.TestUtils.Simulate.click(shareBtn);
 
         expect(view.state.showMenu).to.eql(true);
         expect(view.refs.menu.props.show).to.eql(true);
       });
     });
+
+    describe("Edit Context", function() {
+      it("should show the 'Add some context' link", function() {
+        view = mountTestComponent();
+
+        expect(view.getDOMNode().querySelector(".room-invitation-addcontext")).
+          to.not.eql(null);
+      });
+
+      it("should call a callback when the link is clicked", function() {
+        var onAddContextClick = sinon.stub();
+        view = mountTestComponent({
+          onAddContextClick: onAddContextClick
+        });
+
+        var node = view.getDOMNode();
+        expect(node.querySelector(".room-context")).to.eql(null);
+
+        var addLink = node.querySelector(".room-invitation-addcontext");
+
+        React.addons.TestUtils.Simulate.click(addLink);
+
+        sinon.assert.calledOnce(onAddContextClick);
+      });
+
+      it("should show the edit context view", function() {
+        view = mountTestComponent({
+          showEditContext: true
+        });
+
+        expect(view.getDOMNode().querySelector(".room-context")).to.not.eql(null);
+      });
+    });
   });
 
   describe("DesktopRoomConversationView", function() {
     var view;
 
     beforeEach(function() {
       loop.store.StoreMixin.register({
         feedbackStore: new loop.store.FeedbackStore(dispatcher, {
@@ -579,16 +612,42 @@ describe("loop.roomViews", function () {
           });
 
           view = mountTestComponent();
 
           expect(view.getDOMNode().querySelector(".local-stream-audio"))
             .not.eql(null);
         });
     });
+
+    describe("Edit Context", function() {
+      it("should show the form when the edit button is clicked", function() {
+        view = mountTestComponent();
+        var node = view.getDOMNode();
+
+        expect(node.querySelector(".room-context")).to.eql(null);
+
+        var editButton = node.querySelector(".btn-mute-edit");
+        React.addons.TestUtils.Simulate.click(editButton);
+
+        expect(view.getDOMNode().querySelector(".room-context")).to.not.eql(null);
+      });
+
+      it("should hide the form when the edit button is clicked again", function() {
+        view = mountTestComponent();
+
+        var editButton = view.getDOMNode().querySelector(".btn-mute-edit");
+        React.addons.TestUtils.Simulate.click(editButton);
+
+        // Click again.
+        React.addons.TestUtils.Simulate.click(editButton);
+
+        expect(view.getDOMNode().querySelector(".room-context")).to.eql(null);
+      });
+    });
   });
 
   describe("SocialShareDropdown", function() {
     var view, fakeProvider;
 
     beforeEach(function() {
       sandbox.stub(dispatcher, "dispatch");
 
--- a/browser/components/loop/test/shared/textChatStore_test.js
+++ b/browser/components/loop/test/shared/textChatStore_test.js
@@ -199,16 +199,62 @@ describe("loop.store.TextChatStore", fun
           extraData: {
             location: "http://wonderful.invalid",
             thumbnail: "fake"
           }
         }
       ]);
     });
 
+    it("should not add more than one context message", function() {
+      store.updateRoomInfo(new sharedActions.UpdateRoomInfo({
+        roomOwner: "Mark",
+        roomUrl: "fake",
+        urls: [{
+          description: "A wonderful event",
+          location: "http://wonderful.invalid",
+          thumbnail: "fake"
+        }]
+      }));
+
+      expect(store.getStoreState("messageList")).eql([{
+        type: CHAT_MESSAGE_TYPES.SPECIAL,
+        contentType: CHAT_CONTENT_TYPES.CONTEXT,
+        message: "A wonderful event",
+        sentTimestamp: undefined,
+        receivedTimestamp: undefined,
+        extraData: {
+          location: "http://wonderful.invalid",
+          thumbnail: "fake"
+        }
+      }]);
+
+      store.updateRoomInfo(new sharedActions.UpdateRoomInfo({
+        roomOwner: "Mark",
+        roomUrl: "fake",
+        urls: [{
+          description: "A wonderful event2",
+          location: "http://wonderful.invalid2",
+          thumbnail: "fake2"
+        }]
+      }));
+
+      expect(store.getStoreState("messageList")).eql([{
+        type: CHAT_MESSAGE_TYPES.SPECIAL,
+        contentType: CHAT_CONTENT_TYPES.CONTEXT,
+        message: "A wonderful event2",
+        sentTimestamp: undefined,
+        receivedTimestamp: undefined,
+        extraData: {
+          location: "http://wonderful.invalid2",
+          thumbnail: "fake2"
+        }
+      }]);
+    });
+
     it("should not dispatch a LoopChatMessageAppended event", function() {
       store.updateRoomInfo(new sharedActions.UpdateRoomInfo({
         roomName: "Let's share!",
         roomOwner: "Mark",
         roomUrl: "fake"
       }));
 
       sinon.assert.notCalled(window.dispatchEvent);
--- a/browser/components/loop/test/shared/textChatView_test.js
+++ b/browser/components/loop/test/shared/textChatView_test.js
@@ -394,19 +394,17 @@ describe("loop.shared.views.TextChatView
 
       var entries = node.querySelectorAll(".text-chat-entry");
       expect(entries.length).eql(1);
       expect(entries[0].classList.contains("special")).eql(true);
       expect(entries[0].classList.contains("room-name")).eql(true);
     });
 
     it("should render a special entry for the context url", function() {
-      view = mountTestComponent({
-        showRoomName: true
-      });
+      view = mountTestComponent();
 
       store.updateRoomInfo(new sharedActions.UpdateRoomInfo({
         roomName: "A Very Long Conversation Name",
         roomOwner: "fake",
         roomUrl: "http://showcase",
         urls: [{
           description: "A wonderful page!",
           location: "http://wonderful.invalid"