diff --git a/package.json b/package.json index 79f830f07c..3b5baa6c20 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,6 @@ "react-router-dom": "~5.1.2", "react-scripts": "~3.2.0", "redux": "~4.0.4", - "redux-logger": "~3.0.6", "redux-thunk": "~2.3.0", "typescript": "~3.6.3" }, @@ -56,7 +55,6 @@ "@types/react-redux": "^7.1.5", "@types/react-router": "~5.1.2", "@types/react-router-dom": "~5.1.0", - "@types/redux-logger": "^3.0.7", "@typescript-eslint/eslint-plugin": "~2.9.0", "@typescript-eslint/parser": "~2.9.0", "commitizen": "~4.0.3", diff --git a/src/__mocks__/react-i18next.js b/src/__mocks__/react-i18next.js new file mode 100644 index 0000000000..644db7e68d --- /dev/null +++ b/src/__mocks__/react-i18next.js @@ -0,0 +1,53 @@ +/* eslint-disable */ +const React = require('react') +const reactI18next = require('react-i18next') + +const hasChildren = (node) => node && (node.children || (node.props && node.props.children)) + +const getChildren = (node) => + node && node.children ? node.children : node.props && node.props.children + +const renderNodes = (reactNodes) => { + if (typeof reactNodes === 'string') { + return reactNodes + } + + return Object.keys(reactNodes).map((key, i) => { + const child = reactNodes[key] + const isElement = React.isValidElement(child) + + if (typeof child === 'string') { + return child + } + if (hasChildren(child)) { + const inner = renderNodes(getChildren(child)) + return React.cloneElement(child, { ...child.props, key: i }, inner) + } + if (typeof child === 'object' && !isElement) { + return Object.keys(child).reduce((str, childKey) => `${str}${child[childKey]}`, '') + } + + return child + }) +} + +const useMock = [(k) => k, {}] +useMock.t = (k) => k +useMock.i18n = {} + +module.exports = { + // this mock makes sure any components using the translate HoC receive the t function as a prop + withTranslation: () => (Component) => (props) => k} {...props} />, + Trans: ({ children }) => renderNodes(children), + Translation: ({ children }) => children((k) => k, { i18n: {} }), + useTranslation: () => useMock, + + // mock if needed + I18nextProvider: reactI18next.I18nextProvider, + initReactI18next: reactI18next.initReactI18next, + setDefaults: reactI18next.setDefaults, + getDefaults: reactI18next.getDefaults, + setI18n: reactI18next.setI18n, + getI18n: reactI18next.getI18n, +} + diff --git a/src/store/index.ts b/src/store/index.ts index 9721cb653d..5c41696df2 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -1,7 +1,5 @@ import { configureStore, combineReducers, Action } from '@reduxjs/toolkit' import ReduxThunk, { ThunkAction } from 'redux-thunk' -import { createLogger } from 'redux-logger' - import patient from '../slices/patient-slice' import patients from '../slices/patients-slice' import title from '../slices/title-slice' @@ -16,7 +14,7 @@ const reducer = combineReducers({ const store = configureStore({ reducer, - middleware: [ReduxThunk, createLogger()], + middleware: [ReduxThunk], }) export type AppDispatch = typeof store.dispatch