diff --git a/app/components/Settings/ConnectButton/ConnectButton.react.js b/app/components/Settings/ConnectButton/ConnectButton.react.js index d8038b37a..58c3cd355 100644 --- a/app/components/Settings/ConnectButton/ConnectButton.react.js +++ b/app/components/Settings/ConnectButton/ConnectButton.react.js @@ -23,10 +23,10 @@ export default class ConnectButton extends Component { } /** - * @returns {boolean} true if waiting for a response to a connection request - */ - isConnecting() { - return this.props.connectRequest.status === 'loading'; + * @returns {boolean} true if waiting for a response to a connection request + */ + isConnecting() { + return this.props.connectRequest.status === 'loading'; } /** @@ -34,7 +34,7 @@ export default class ConnectButton extends Component { */ isConnected() { const status = Number(this.props.connectRequest.status); - return (status >= 200 || status < 300); + return (status >= 200 && status < 300); } /** @@ -56,7 +56,7 @@ export default class ConnectButton extends Component { */ isSaved() { const status = Number(this.props.saveConnectionsRequest.status); - return (status >= 200 || status < 300); + return (status >= 200 && status < 300); } /** @@ -89,18 +89,19 @@ export default class ConnectButton extends Component { buttonClick = connect; const connectErrorMessage = pathOr( - null, ['content', 'error'], connectRequest + null, ['content', 'error', 'message'], connectRequest ); const saveErrorMessage = pathOr( null, ['content', 'error', 'message'], saveConnectionsRequest ); const genericErrorMessage = 'Hm... had trouble connecting.'; - const errorMessage = connectErrorMessage || saveErrorMessage || genericErrorMessage; + const errorMessage = String(connectErrorMessage || saveErrorMessage || genericErrorMessage); error =
{errorMessage}
; } else if (this.isConnected() && this.isSaved()) { buttonText = 'Save changes'; buttonClick = connect; + } else { buttonText = 'Connect'; buttonClick = connect; diff --git a/test/app/components/Settings/ConnectButton/ConnectButton.test.js b/test/app/components/Settings/ConnectButton/ConnectButton.test.js index 1646d2045..3476df133 100644 --- a/test/app/components/Settings/ConnectButton/ConnectButton.test.js +++ b/test/app/components/Settings/ConnectButton/ConnectButton.test.js @@ -10,6 +10,66 @@ describe('Connect Button Test', () => { configure({ adapter: new Adapter() }); }); + it('should handle malformatted Connection Request Error', () => { + const connect = function() {}; + const connectRequest = { + status: 500, + content: {error: {message: {}}} + }; + const saveConnectionsRequest = { + }; + const editMode = true; + + const button = mount(); + + expect(button.find('.errorMessage').length).toBe(1); + }); + + it('should handle malformatted Save Connections Request Error', () => { + const connect = function() {}; + const connectRequest = { + status: 200 + }; + const saveConnectionsRequest = { + status: 500, + content: {error: {message: {}}} + }; + const editMode = true; + + const button = mount(); + + expect(button.find('.errorMessage').length).toBe(1); + }); + + it('should handle Connection Request Error Status 500', () => { + const connect = function() {}; + const connectRequest = { + status: 500 + }; + const saveConnectionsRequest = { + }; + const editMode = true; + + const button = mount(); + + expect(button.instance().connectionFailed()).toBe(true); + }); + it('should verify Connection Request Error', () => { const connect = function() {}; const connectRequest = {