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) {
|
handleFormSubmit: function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
var newRoomName = this.state.newRoomName;
|
this.props.dispatcher.dispatch(new sharedActions.RenameRoom({
|
||||||
|
roomToken: this.state.roomToken,
|
||||||
if (newRoomName && this.state.roomName != newRoomName) {
|
newRoomName: this.state.newRoomName
|
||||||
this.props.dispatcher.dispatch(
|
}));
|
||||||
new sharedActions.RenameRoom({
|
|
||||||
roomToken: this.state.roomToken,
|
|
||||||
newRoomName: newRoomName
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
handleEmailButtonClick: function(event) {
|
handleEmailButtonClick: function(event) {
|
||||||
|
|||||||
@@ -94,15 +94,10 @@ loop.roomViews = (function(mozL10n) {
|
|||||||
handleFormSubmit: function(event) {
|
handleFormSubmit: function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
var newRoomName = this.state.newRoomName;
|
this.props.dispatcher.dispatch(new sharedActions.RenameRoom({
|
||||||
|
roomToken: this.state.roomToken,
|
||||||
if (newRoomName && this.state.roomName != newRoomName) {
|
newRoomName: this.state.newRoomName
|
||||||
this.props.dispatcher.dispatch(
|
}));
|
||||||
new sharedActions.RenameRoom({
|
|
||||||
roomToken: this.state.roomToken,
|
|
||||||
newRoomName: newRoomName
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
handleEmailButtonClick: function(event) {
|
handleEmailButtonClick: function(event) {
|
||||||
|
|||||||
@@ -423,8 +423,15 @@ loop.store = loop.store || {};
|
|||||||
* @param {sharedActions.RenameRoom} actionData
|
* @param {sharedActions.RenameRoom} actionData
|
||||||
*/
|
*/
|
||||||
renameRoom: function(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.setStoreState({error: null});
|
||||||
this._mozLoop.rooms.rename(actionData.roomToken, actionData.newRoomName,
|
this._mozLoop.rooms.rename(actionData.roomToken, newRoomName,
|
||||||
function(err) {
|
function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
this.dispatchAction(new sharedActions.RenameRoomError({error: err}));
|
this.dispatchAction(new sharedActions.RenameRoomError({error: err}));
|
||||||
|
|||||||
@@ -128,14 +128,14 @@ describe("loop.roomViews", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
roomNameBox = view.getDOMNode().querySelector('.input-room-name');
|
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",
|
it("should dispatch a RenameRoom action when the focus is lost",
|
||||||
function() {
|
function() {
|
||||||
|
React.addons.TestUtils.Simulate.change(roomNameBox, { target: {
|
||||||
|
value: "reallyFake"
|
||||||
|
}});
|
||||||
|
|
||||||
React.addons.TestUtils.Simulate.blur(roomNameBox);
|
React.addons.TestUtils.Simulate.blur(roomNameBox);
|
||||||
|
|
||||||
sinon.assert.calledOnce(dispatcher.dispatch);
|
sinon.assert.calledOnce(dispatcher.dispatch);
|
||||||
@@ -148,6 +148,10 @@ describe("loop.roomViews", function () {
|
|||||||
|
|
||||||
it("should dispatch a RenameRoom action when Enter key is pressed",
|
it("should dispatch a RenameRoom action when Enter key is pressed",
|
||||||
function() {
|
function() {
|
||||||
|
React.addons.TestUtils.Simulate.change(roomNameBox, { target: {
|
||||||
|
value: "reallyFake"
|
||||||
|
}});
|
||||||
|
|
||||||
TestUtils.Simulate.keyDown(roomNameBox, {key: "Enter", which: 13});
|
TestUtils.Simulate.keyDown(roomNameBox, {key: "Enter", which: 13});
|
||||||
|
|
||||||
sinon.assert.calledOnce(dispatcher.dispatch);
|
sinon.assert.calledOnce(dispatcher.dispatch);
|
||||||
|
|||||||
@@ -550,5 +550,16 @@ describe("loop.store.RoomStore", function () {
|
|||||||
|
|
||||||
expect(store.getStoreState().error).eql(err);
|
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