Bug 1110155 - Added minimal Loop room name validation. r=mikedeboer
This commit is contained in:
@@ -94,15 +94,10 @@ loop.roomViews = (function(mozL10n) {
|
||||
handleFormSubmit: function(event) {
|
||||
event.preventDefault();
|
||||
|
||||
var newRoomName = this.state.newRoomName;
|
||||
|
||||
if (newRoomName && this.state.roomName != newRoomName) {
|
||||
this.props.dispatcher.dispatch(
|
||||
new sharedActions.RenameRoom({
|
||||
roomToken: this.state.roomToken,
|
||||
newRoomName: newRoomName
|
||||
}));
|
||||
}
|
||||
this.props.dispatcher.dispatch(new sharedActions.RenameRoom({
|
||||
roomToken: this.state.roomToken,
|
||||
newRoomName: this.state.newRoomName
|
||||
}));
|
||||
},
|
||||
|
||||
handleEmailButtonClick: function(event) {
|
||||
|
||||
@@ -94,15 +94,10 @@ loop.roomViews = (function(mozL10n) {
|
||||
handleFormSubmit: function(event) {
|
||||
event.preventDefault();
|
||||
|
||||
var newRoomName = this.state.newRoomName;
|
||||
|
||||
if (newRoomName && this.state.roomName != newRoomName) {
|
||||
this.props.dispatcher.dispatch(
|
||||
new sharedActions.RenameRoom({
|
||||
roomToken: this.state.roomToken,
|
||||
newRoomName: newRoomName
|
||||
}));
|
||||
}
|
||||
this.props.dispatcher.dispatch(new sharedActions.RenameRoom({
|
||||
roomToken: this.state.roomToken,
|
||||
newRoomName: this.state.newRoomName
|
||||
}));
|
||||
},
|
||||
|
||||
handleEmailButtonClick: function(event) {
|
||||
|
||||
@@ -423,8 +423,15 @@ loop.store = loop.store || {};
|
||||
* @param {sharedActions.RenameRoom} actionData
|
||||
*/
|
||||
renameRoom: function(actionData) {
|
||||
var newRoomName = actionData.newRoomName.trim();
|
||||
|
||||
// Skip update if name is unchanged or empty.
|
||||
if (!newRoomName || this.getStoreState("roomName") === newRoomName) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setStoreState({error: null});
|
||||
this._mozLoop.rooms.rename(actionData.roomToken, actionData.newRoomName,
|
||||
this._mozLoop.rooms.rename(actionData.roomToken, newRoomName,
|
||||
function(err) {
|
||||
if (err) {
|
||||
this.dispatchAction(new sharedActions.RenameRoomError({error: err}));
|
||||
|
||||
@@ -128,14 +128,14 @@ describe("loop.roomViews", function () {
|
||||
});
|
||||
|
||||
roomNameBox = view.getDOMNode().querySelector('.input-room-name');
|
||||
|
||||
React.addons.TestUtils.Simulate.change(roomNameBox, { target: {
|
||||
value: "reallyFake"
|
||||
}});
|
||||
});
|
||||
|
||||
it("should dispatch a RenameRoom action when the focus is lost",
|
||||
function() {
|
||||
React.addons.TestUtils.Simulate.change(roomNameBox, { target: {
|
||||
value: "reallyFake"
|
||||
}});
|
||||
|
||||
React.addons.TestUtils.Simulate.blur(roomNameBox);
|
||||
|
||||
sinon.assert.calledOnce(dispatcher.dispatch);
|
||||
@@ -148,6 +148,10 @@ describe("loop.roomViews", function () {
|
||||
|
||||
it("should dispatch a RenameRoom action when Enter key is pressed",
|
||||
function() {
|
||||
React.addons.TestUtils.Simulate.change(roomNameBox, { target: {
|
||||
value: "reallyFake"
|
||||
}});
|
||||
|
||||
TestUtils.Simulate.keyDown(roomNameBox, {key: "Enter", which: 13});
|
||||
|
||||
sinon.assert.calledOnce(dispatcher.dispatch);
|
||||
|
||||
@@ -550,5 +550,16 @@ describe("loop.store.RoomStore", function () {
|
||||
|
||||
expect(store.getStoreState().error).eql(err);
|
||||
});
|
||||
|
||||
it("should ensure only submitting a non-empty room name", function() {
|
||||
fakeMozLoop.rooms.rename = sinon.spy();
|
||||
|
||||
dispatcher.dispatch(new sharedActions.RenameRoom({
|
||||
roomToken: "42abc",
|
||||
newRoomName: " \t \t "
|
||||
}));
|
||||
|
||||
sinon.assert.notCalled(fakeMozLoop.rooms.rename);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user