Bug 1107210 - Fixed room name update not correctly reflected in Loop panel. r=Standard8 a=sylvestre
authorNicolas Perriault <nperriault@mozilla.com>
Fri, 05 Dec 2014 09:39:09 -0800
changeset 242359 e8be247efd4c16b4dfc5449e61aa563a4d50b356
parent 242358 a408c98d4f5d219dab6c3fff8f3400d92e4c508a
child 242360 3c5c7200c6eb1590d93619b4589a7e66301c5dc8
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8, sylvestre
bugs1107210
milestone36.0a2
Bug 1107210 - Fixed room name update not correctly reflected in Loop panel. r=Standard8 a=sylvestre
browser/components/loop/content/js/panel.js
browser/components/loop/content/js/panel.jsx
browser/components/loop/content/shared/js/activeRoomStore.js
browser/components/loop/test/desktop-local/panel_test.js
--- a/browser/components/loop/content/js/panel.js
+++ b/browser/components/loop/content/js/panel.js
@@ -532,16 +532,22 @@ loop.panel = (function(_, mozL10n) {
     getDefaultProps: function() {
       return {text: ""};
     },
 
     getInitialState: function() {
       return {edit: false, text: this.props.text};
     },
 
+    componentWillReceiveProps: function(nextProps) {
+      if (nextProps.text !== this.props.text) {
+        this.setState({text: nextProps.text});
+      }
+    },
+
     handleTextClick: function(event) {
       event.stopPropagation();
       event.preventDefault();
       this.setState({edit: true}, function() {
         this.getDOMNode().querySelector("input").select();
       }.bind(this));
     },
 
--- a/browser/components/loop/content/js/panel.jsx
+++ b/browser/components/loop/content/js/panel.jsx
@@ -532,16 +532,22 @@ loop.panel = (function(_, mozL10n) {
     getDefaultProps: function() {
       return {text: ""};
     },
 
     getInitialState: function() {
       return {edit: false, text: this.props.text};
     },
 
+    componentWillReceiveProps: function(nextProps) {
+      if (nextProps.text !== this.props.text) {
+        this.setState({text: nextProps.text});
+      }
+    },
+
     handleTextClick: function(event) {
       event.stopPropagation();
       event.preventDefault();
       this.setState({edit: true}, function() {
         this.getDOMNode().querySelector("input").select();
       }.bind(this));
     },
 
--- a/browser/components/loop/content/shared/js/activeRoomStore.js
+++ b/browser/components/loop/content/shared/js/activeRoomStore.js
@@ -386,18 +386,17 @@ loop.store.ActiveRoomStore = (function()
 
     /**
      * Handles the window being unloaded. Ensures the room is left.
      */
     windowUnload: function() {
       this._leaveRoom(ROOM_STATES.CLOSING);
 
       // If we're closing the window, we can stop listening to updates.
-      this._mozLoop.rooms.off("update:" + this.getStoreState().roomToken,
-        this._handleRoomUpdate.bind(this));
+      this._mozLoop.rooms.off("update:" + this.getStoreState().roomToken);
     },
 
     /**
      * Handles a room being left.
      */
     leaveRoom: function() {
       this._leaveRoom();
     },
--- a/browser/components/loop/test/desktop-local/panel_test.js
+++ b/browser/components/loop/test/desktop-local/panel_test.js
@@ -852,16 +852,35 @@ describe("loop.panel", function() {
 
         TestUtils.Simulate.click(urlLink);
 
         sinon.assert.calledOnce(dispatcher.dispatch);
         sinon.assert.calledWithExactly(dispatcher.dispatch,
           new sharedActions.OpenRoom({roomToken: roomData.roomToken}));
       });
     });
+
+    describe("Room name updated", function() {
+      it("should update room name", function() {
+        var roomEntry = mountRoomEntry({
+          dispatcher: dispatcher,
+          room: new loop.store.Room(roomData)
+        });
+        var updatedRoom = new loop.store.Room(_.extend({}, roomData, {
+          roomName: "New room name",
+          ctime: new Date().getTime()
+        }));
+
+        roomEntry.setProps({room: updatedRoom});
+
+        expect(
+          roomEntry.getDOMNode().querySelector(".edit-in-place").textContent)
+        .eql("New room name");
+      });
+    });
   });
 
   describe("loop.panel.RoomList", function() {
     var roomStore, dispatcher, fakeEmail;
 
     beforeEach(function() {
       fakeEmail = "fakeEmail@example.com";
       dispatcher = new loop.Dispatcher();