From c0e45f9098875136459321fabc702ccf3aa81901 Mon Sep 17 00:00:00 2001 From: Kanagaraj M Date: Fri, 23 Mar 2018 00:55:56 +0530 Subject: [PATCH] Fix failing unit tests in browser (#5688) * format js files using prettier Used the following command to format the files prettier --write "browser/app/js/**/*.js" * fix failing unit tests in browser --- browser/app/js/__tests__/App.test.js | 8 +- browser/app/js/__tests__/jsonrpc-test.js | 4 +- browser/app/js/alert/AlertContainer.js | 4 +- browser/app/js/alert/__tests___/Alert.test.js | 6 +- .../alert/__tests___/AlertContainer.test.js | 6 +- .../app/js/alert/__tests___/actions.test.js | 28 +-- .../app/js/alert/__tests___/reducer.test.js | 44 ++-- browser/app/js/alert/actions.js | 10 +- browser/app/js/alert/reducer.js | 4 +- browser/app/js/browser/BrowserDropdown.js | 14 +- browser/app/js/browser/ChangePasswordModal.js | 30 +-- browser/app/js/browser/ConfirmModal.js | 2 +- browser/app/js/browser/Header.js | 4 +- browser/app/js/browser/Login.js | 8 +- browser/app/js/browser/MainActions.js | 6 +- browser/app/js/browser/SideBar.js | 6 +- browser/app/js/browser/SidebarBackdrop.js | 4 +- browser/app/js/browser/SidebarToggle.js | 4 +- browser/app/js/browser/StorageInfo.js | 4 +- .../js/browser/__tests__/AboutModal.test.js | 6 +- .../browser/__tests__/BrowserDropdown.test.js | 14 +- .../__tests__/ChangePasswordModal.test.js | 30 +-- .../app/js/browser/__tests__/Header.test.js | 17 -- .../app/js/browser/__tests__/Login.test.js | 26 +- .../js/browser/__tests__/MainActions.test.js | 12 +- .../app/js/browser/__tests__/SideBar.test.js | 11 +- ...leHeader.test.js => SidebarToggle.test.js} | 12 +- .../js/browser/__tests__/StorageInfo.test.js | 4 +- .../app/js/browser/__tests__/actions.test.js | 20 +- .../app/js/browser/__tests__/reducer.test.js | 44 ++-- browser/app/js/browser/actions.js | 12 +- browser/app/js/browser/reducer.js | 14 +- browser/app/js/buckets/Bucket.js | 2 +- browser/app/js/buckets/BucketContainer.js | 4 +- browser/app/js/buckets/BucketDropdown.js | 8 +- browser/app/js/buckets/BucketPolicyModal.js | 6 +- browser/app/js/buckets/BucketSearch.js | 2 +- browser/app/js/buckets/MakeBucketModal.js | 10 +- browser/app/js/buckets/Policy.js | 10 +- browser/app/js/buckets/PolicyInput.js | 12 +- .../app/js/buckets/__tests__/Bucket.test.js | 8 +- .../buckets/__tests__/BucketContainer.test.js | 8 +- .../buckets/__tests__/BucketDropdown.test.js | 12 +- .../js/buckets/__tests__/BucketList.test.js | 10 +- .../__tests__/BucketPolicyModal.test.js | 6 +- .../js/buckets/__tests__/BucketSearch.test.js | 4 +- .../buckets/__tests__/MakeBucketModal.test.js | 28 +-- .../app/js/buckets/__tests__/Policy.test.js | 16 +- .../js/buckets/__tests__/PolicyInput.test.js | 26 +- .../app/js/buckets/__tests__/actions.test.js | 82 +++---- .../app/js/buckets/__tests__/reducer.test.js | 26 +- browser/app/js/buckets/actions.js | 44 ++-- browser/app/js/buckets/reducer.js | 20 +- browser/app/js/buckets/selectors.js | 2 +- browser/app/js/components/BrowserUpdate.js | 2 +- browser/app/js/history.js | 2 +- browser/app/js/jest/setup.js | 2 +- browser/app/js/jsonrpc.js | 6 +- browser/app/js/mime.js | 4 +- .../js/objects/DeleteObjectConfirmModal.js | 2 +- browser/app/js/objects/ObjectContainer.js | 4 +- browser/app/js/objects/ObjectItem.js | 8 +- browser/app/js/objects/ObjectsHeader.js | 12 +- .../app/js/objects/ObjectsListContainer.js | 6 +- browser/app/js/objects/Path.js | 4 +- browser/app/js/objects/PrefixContainer.js | 6 +- browser/app/js/objects/ShareObjectModal.js | 24 +- .../{ObjectsBulkActions.js => Toolbar.js} | 20 +- .../DeleteObjectConfirmModal.test.js | 4 +- .../objects/__tests__/ObjectContainer.test.js | 24 -- .../js/objects/__tests__/ObjectItem.test.js | 10 +- .../objects/__tests__/ObjectsHeader.test.js | 18 +- .../js/objects/__tests__/ObjectsList.test.js | 4 +- .../__tests__/ObjectsListContainer.test.js | 12 +- browser/app/js/objects/__tests__/Path.test.js | 22 +- .../objects/__tests__/PrefixContainer.test.js | 2 +- .../__tests__/ShareObjectModal.test.js | 58 ++--- ...ctsBulkActions.test.js => Toolbar.test.js} | 67 +++-- .../app/js/objects/__tests__/actions.test.js | 232 +++++++++--------- .../app/js/objects/__tests__/reducer.test.js | 110 ++++----- browser/app/js/objects/actions.js | 66 ++--- browser/app/js/objects/reducer.js | 32 +-- browser/app/js/reducers.js | 2 +- browser/app/js/uploads/AbortConfirmModal.js | 10 +- browser/app/js/uploads/Dropzone.js | 2 +- browser/app/js/uploads/UploadModal.js | 4 +- .../__tests__/AbortConfirmModal.test.js | 4 +- .../app/js/uploads/__tests__/Dropzone.test.js | 4 +- .../js/uploads/__tests__/UploadModal.test.js | 4 +- .../app/js/uploads/__tests__/actions.test.js | 58 ++--- .../app/js/uploads/__tests__/reducer.test.js | 44 ++-- browser/app/js/uploads/actions.js | 34 +-- browser/app/js/uploads/reducer.js | 20 +- browser/app/js/utils.js | 8 +- browser/app/js/web.js | 8 +- 95 files changed, 839 insertions(+), 890 deletions(-) rename browser/app/js/browser/__tests__/{MobileHeader.test.js => SidebarToggle.test.js} (76%) rename browser/app/js/objects/{ObjectsBulkActions.js => Toolbar.js} (90%) rename browser/app/js/objects/__tests__/{ObjectsBulkActions.test.js => Toolbar.test.js} (51%) diff --git a/browser/app/js/__tests__/App.test.js b/browser/app/js/__tests__/App.test.js index 14ec5cedc..842f4e145 100644 --- a/browser/app/js/__tests__/App.test.js +++ b/browser/app/js/__tests__/App.test.js @@ -31,7 +31,7 @@ describe("App", () => { const wrapper = mount( - , + ) expect(wrapper.text()).toBe("Login") }) @@ -40,7 +40,7 @@ describe("App", () => { const wrapper = mount( - , + ) expect(wrapper.text()).toBe("Browser") }) @@ -49,7 +49,7 @@ describe("App", () => { const wrapper = mount( - , + ) expect(wrapper.text()).toBe("Browser") }) @@ -58,7 +58,7 @@ describe("App", () => { const wrapper = mount( - , + ) expect(wrapper.text()).toBe("Browser") }) diff --git a/browser/app/js/__tests__/jsonrpc-test.js b/browser/app/js/__tests__/jsonrpc-test.js index a2e96dd93..30d15b7de 100644 --- a/browser/app/js/__tests__/jsonrpc-test.js +++ b/browser/app/js/__tests__/jsonrpc-test.js @@ -21,7 +21,7 @@ describe("jsonrpc", () => { try { let jsonRPC = new JSONrpc({ endpoint: "htt://localhost:9000", - namespace: "Test", + namespace: "Test" }) } catch (e) { done() @@ -30,7 +30,7 @@ describe("jsonrpc", () => { it("should succeed with valid endpoint", () => { let jsonRPC = new JSONrpc({ endpoint: "http://localhost:9000/webrpc", - namespace: "Test", + namespace: "Test" }) expect(jsonRPC.version).toEqual("2.0") expect(jsonRPC.host).toEqual("localhost") diff --git a/browser/app/js/alert/AlertContainer.js b/browser/app/js/alert/AlertContainer.js index d3202e420..a36e9910d 100644 --- a/browser/app/js/alert/AlertContainer.js +++ b/browser/app/js/alert/AlertContainer.js @@ -28,13 +28,13 @@ export const AlertContainer = ({ alert, clearAlert }) => { const mapStateToProps = state => { return { - alert: state.alert, + alert: state.alert } } const mapDispatchToProps = dispatch => { return { - clearAlert: () => dispatch(alertActions.clear()), + clearAlert: () => dispatch(alertActions.clear()) } } diff --git a/browser/app/js/alert/__tests___/Alert.test.js b/browser/app/js/alert/__tests___/Alert.test.js index bcedcaa7f..b6a9e6268 100644 --- a/browser/app/js/alert/__tests___/Alert.test.js +++ b/browser/app/js/alert/__tests___/Alert.test.js @@ -26,10 +26,10 @@ describe("Alert", () => { it("should call onDismiss when close button is clicked", () => { const onDismiss = jest.fn() const wrapper = mount( - , + ) - wrapper.find("button").simulate("click", { - preventDefault: jest.fn(), + wrapper.find("i").simulate("click", { + preventDefault: jest.fn() }) expect(onDismiss).toHaveBeenCalled() }) diff --git a/browser/app/js/alert/__tests___/AlertContainer.test.js b/browser/app/js/alert/__tests___/AlertContainer.test.js index f748e1915..d41bc6f02 100644 --- a/browser/app/js/alert/__tests___/AlertContainer.test.js +++ b/browser/app/js/alert/__tests___/AlertContainer.test.js @@ -21,15 +21,13 @@ import { AlertContainer } from "../AlertContainer" describe("Alert", () => { it("should render without crashing", () => { shallow( - , + ) }) it("should render nothing if message is empty", () => { const wrapper = shallow( - , + ) expect(wrapper.find("Alert").length).toBe(0) }) diff --git a/browser/app/js/alert/__tests___/actions.test.js b/browser/app/js/alert/__tests___/actions.test.js index b06eed57a..4dc616a3e 100644 --- a/browser/app/js/alert/__tests___/actions.test.js +++ b/browser/app/js/alert/__tests___/actions.test.js @@ -32,15 +32,15 @@ describe("Alert actions", () => { alert: { id: 0, message: "Test alert", - type: "danger", - }, - }, + type: "danger" + } + } ] store.dispatch( actionsAlert.set({ message: "Test alert", - type: "danger", - }), + type: "danger" + }) ) const actions = store.getActions() expect(actions).toEqual(expectedActions) @@ -53,20 +53,20 @@ describe("Alert actions", () => { type: "alert/SET", alert: { id: 1, - message: "Test alert", - }, + message: "Test alert" + } }, { type: "alert/CLEAR", alert: { - id: 1, - }, - }, + id: 1 + } + } ] store.dispatch( actionsAlert.set({ - message: "Test alert", - }), + message: "Test alert" + }) ) jest.runAllTimers() const actions = store.getActions() @@ -77,8 +77,8 @@ describe("Alert actions", () => { const store = mockStore() const expectedActions = [ { - type: "alert/CLEAR", - }, + type: "alert/CLEAR" + } ] store.dispatch(actionsAlert.clear()) const actions = store.getActions() diff --git a/browser/app/js/alert/__tests___/reducer.test.js b/browser/app/js/alert/__tests___/reducer.test.js index a875228b8..69099710b 100644 --- a/browser/app/js/alert/__tests___/reducer.test.js +++ b/browser/app/js/alert/__tests___/reducer.test.js @@ -21,7 +21,7 @@ describe("alert reducer", () => { it("should return the initial state", () => { expect(reducer(undefined, {})).toEqual({ show: false, - type: "danger", + type: "danger" }) }) @@ -32,14 +32,14 @@ describe("alert reducer", () => { alert: { id: 1, type: "danger", - message: "Test message", - }, - }), + message: "Test message" + } + }) ).toEqual({ show: true, id: 1, type: "danger", - message: "Test message", + message: "Test message" }) }) @@ -49,15 +49,15 @@ describe("alert reducer", () => { { show: true, type: "danger", - message: "Test message", + message: "Test message" }, { - type: actionsAlert.CLEAR, - }, - ), + type: actionsAlert.CLEAR + } + ) ).toEqual({ show: false, - type: "danger", + type: "danger" }) }) @@ -68,18 +68,18 @@ describe("alert reducer", () => { show: true, id: 1, type: "danger", - message: "Test message", + message: "Test message" }, { type: actionsAlert.CLEAR, alert: { - id: 1, - }, - }, - ), + id: 1 + } + } + ) ).toEqual({ show: false, - type: "danger", + type: "danger" }) }) @@ -90,20 +90,20 @@ describe("alert reducer", () => { show: true, id: 1, type: "danger", - message: "Test message", + message: "Test message" }, { type: actionsAlert.CLEAR, alert: { - id: 2, - }, - }, - ), + id: 2 + } + } + ) ).toEqual({ show: true, id: 1, type: "danger", - message: "Test message", + message: "Test message" }) }) }) diff --git a/browser/app/js/alert/actions.js b/browser/app/js/alert/actions.js index 17a518234..6afd182ed 100644 --- a/browser/app/js/alert/actions.js +++ b/browser/app/js/alert/actions.js @@ -27,22 +27,22 @@ export const set = alert => { dispatch({ type: CLEAR, alert: { - id, - }, + id + } }) }, 5000) } dispatch({ type: SET, alert: Object.assign({}, alert, { - id, - }), + id + }) }) } } export const clear = () => { return { - type: CLEAR, + type: CLEAR } } diff --git a/browser/app/js/alert/reducer.js b/browser/app/js/alert/reducer.js index 04ff594ea..3bcd4fddb 100644 --- a/browser/app/js/alert/reducer.js +++ b/browser/app/js/alert/reducer.js @@ -18,7 +18,7 @@ import * as actionsAlert from "./actions" const initialState = { show: false, - type: "danger", + type: "danger" } export default (state = initialState, action) => { switch (action.type) { @@ -27,7 +27,7 @@ export default (state = initialState, action) => { show: true, id: action.alert.id, type: action.alert.type, - message: action.alert.message, + message: action.alert.message } case actionsAlert.CLEAR: if (action.alert && action.alert.id != state.id) { diff --git a/browser/app/js/browser/BrowserDropdown.js b/browser/app/js/browser/BrowserDropdown.js index defb04d0d..1676d4d1f 100644 --- a/browser/app/js/browser/BrowserDropdown.js +++ b/browser/app/js/browser/BrowserDropdown.js @@ -28,29 +28,29 @@ export class BrowserDropdown extends React.Component { super(props) this.state = { showAboutModal: false, - showChangePasswordModal: false, + showChangePasswordModal: false } } showAbout(e) { e.preventDefault() this.setState({ - showAboutModal: true, + showAboutModal: true }) } hideAbout() { this.setState({ - showAboutModal: false, + showAboutModal: false }) } showChangePassword(e) { e.preventDefault() this.setState({ - showChangePasswordModal: true, + showChangePasswordModal: true }) } hideChangePassword() { this.setState({ - showChangePasswordModal: false, + showChangePasswordModal: false }) } componentDidMount() { @@ -142,13 +142,13 @@ export class BrowserDropdown extends React.Component { const mapStateToProps = state => { return { - serverInfo: state.browser.serverInfo, + serverInfo: state.browser.serverInfo } } const mapDispatchToProps = dispatch => { return { - fetchServerInfo: () => dispatch(browserActions.fetchServerInfo()), + fetchServerInfo: () => dispatch(browserActions.fetchServerInfo()) } } diff --git a/browser/app/js/browser/ChangePasswordModal.js b/browser/app/js/browser/ChangePasswordModal.js index c9d0aaef9..d6a6584dc 100644 --- a/browser/app/js/browser/ChangePasswordModal.js +++ b/browser/app/js/browser/ChangePasswordModal.js @@ -24,7 +24,7 @@ import { Modal, ModalBody, ModalHeader, - OverlayTrigger, + OverlayTrigger } from "react-bootstrap" export class ChangePasswordModal extends React.Component { @@ -33,7 +33,7 @@ export class ChangePasswordModal extends React.Component { this.state = { accessKey: "", secretKey: "", - keysReadOnly: false, + keysReadOnly: false } } // When its shown, it loads the access key and secret key. @@ -45,13 +45,13 @@ export class ChangePasswordModal extends React.Component { this.setState({ accessKey: "xxxxxxxxx", secretKey: "xxxxxxxxx", - keysReadOnly: true, + keysReadOnly: true }) } else { web.GetAuth().then(data => { this.setState({ accessKey: data.accessKey, - secretKey: data.secretKey, + secretKey: data.secretKey }) }) } @@ -60,19 +60,19 @@ export class ChangePasswordModal extends React.Component { // Handle field changes from inside the modal. accessKeyChange(e) { this.setState({ - accessKey: e.target.value, + accessKey: e.target.value }) } secretKeyChange(e) { this.setState({ - secretKey: e.target.value, + secretKey: e.target.value }) } secretKeyVisible(secretKeyVisible) { this.setState({ - secretKeyVisible, + secretKeyVisible }) } @@ -84,18 +84,18 @@ export class ChangePasswordModal extends React.Component { web .SetAuth({ accessKey, - secretKey, + secretKey }) .then(data => { showAlert({ type: "success", - message: "Changed credentials", + message: "Changed credentials" }) }) .catch(err => { showAlert({ type: "danger", - message: err.message, + message: err.message }) }) } @@ -105,7 +105,7 @@ export class ChangePasswordModal extends React.Component { this.setState({ accessKey: data.accessKey, secretKey: data.secretKey, - secretKeyVisible: true, + secretKeyVisible: true }) }) } @@ -136,7 +136,7 @@ export class ChangePasswordModal extends React.Component { { return { - serverInfo: state.browser.serverInfo, + serverInfo: state.browser.serverInfo } } const mapDispatchToProps = dispatch => { return { - showAlert: alert => dispatch(alertActions.set(alert)), + showAlert: alert => dispatch(alertActions.set(alert)) } } diff --git a/browser/app/js/browser/ConfirmModal.js b/browser/app/js/browser/ConfirmModal.js index 9e0236725..75bb89a75 100644 --- a/browser/app/js/browser/ConfirmModal.js +++ b/browser/app/js/browser/ConfirmModal.js @@ -26,7 +26,7 @@ let ConfirmModal = ({ cancelText, okHandler, cancelHandler, - show, + show }) => { return ( { return (
- +
) diff --git a/browser/app/js/browser/Login.js b/browser/app/js/browser/Login.js index 64ba57621..f9f758ce5 100644 --- a/browser/app/js/browser/Login.js +++ b/browser/app/js/browser/Login.js @@ -40,7 +40,7 @@ export class Login extends React.Component { web .Login({ username: document.getElementById("accessKey").value, - password: document.getElementById("secretKey").value, + password: document.getElementById("secretKey").value }) .then(res => { history.push("/") @@ -114,10 +114,10 @@ const mapDispatchToProps = dispatch => { dispatch( actionsAlert.set({ type: type, - message: message, - }), + message: message + }) ), - clearAlert: () => dispatch(actionsAlert.clear()), + clearAlert: () => dispatch(actionsAlert.clear()) } } diff --git a/browser/app/js/browser/MainActions.js b/browser/app/js/browser/MainActions.js index 3354b2f64..ee1d44a64 100644 --- a/browser/app/js/browser/MainActions.js +++ b/browser/app/js/browser/MainActions.js @@ -25,7 +25,7 @@ import { getPrefixWritable } from "../objects/selectors" export const MainActions = ({ prefixWritable, uploadFile, - showMakeBucketModal, + showMakeBucketModal }) => { const uploadTooltip = Upload file const makeBucketTooltip = ( @@ -89,14 +89,14 @@ export const MainActions = ({ const mapStateToProps = state => { return { - prefixWritable: getPrefixWritable(state), + prefixWritable: getPrefixWritable(state) } } const mapDispatchToProps = dispatch => { return { uploadFile: file => dispatch(uploadsActions.uploadFile(file)), - showMakeBucketModal: () => dispatch(actionsBuckets.showMakeBucketModal()), + showMakeBucketModal: () => dispatch(actionsBuckets.showMakeBucketModal()) } } diff --git a/browser/app/js/browser/SideBar.js b/browser/app/js/browser/SideBar.js index 9250f544e..fc3eb88c9 100644 --- a/browser/app/js/browser/SideBar.js +++ b/browser/app/js/browser/SideBar.js @@ -30,7 +30,7 @@ export const SideBar = ({ sidebarOpen }) => {