From 06ff405b455153b98fa8ef4dc0ad270210cc2a2d Mon Sep 17 00:00:00 2001 From: metzgegu <31687635+metzgegu@users.noreply.github.com> Date: Fri, 3 Jan 2020 09:48:19 +0100 Subject: [PATCH] test(front): add unit tests to frontend ref: #2239 --- frontend/configEnv-test.json | 3 + frontend/package.json | 10 +- frontend/src/action-creator.async.js | 4 +- .../component/Account/MenuSubComponent.jsx | 11 + .../src/component/Account/Notification.jsx | 16 +- frontend/src/component/Account/Timezone.jsx | 3 +- frontend/src/component/ContentItemSearch.jsx | 2 +- frontend/src/component/FlashMessage.jsx | 2 +- .../Header/MenuActionListItem/MenuProfil.jsx | 2 +- frontend/src/component/Header/Search.jsx | 2 +- .../component/Workspace/BtnExtandedAction.jsx | 2 +- .../component/Workspace/ContentItemHeader.jsx | 2 +- .../common/Input/DropdownCreateButton.jsx | 2 +- .../common/Input/SubDropdownCreateButton.jsx | 2 +- frontend/src/container/Account.jsx | 2 +- .../src/container/AppFullscreenRouter.jsx | 2 +- frontend/src/container/Home.jsx | 2 +- frontend/src/container/Sidebar.jsx | 2 +- frontend/src/container/Tracim.jsx | 2 +- frontend/src/helper.js | 4 +- frontend/src/index.js | 3 +- frontend/test/.mocharc.js | 3 +- frontend/test/fixture/app/agenda.js | 3 +- frontend/test/fixture/app/file.js | 3 +- frontend/test/fixture/app/folder.js | 3 +- frontend/test/fixture/app/htmlDocument.js | 3 +- frontend/test/fixture/app/thread.js | 3 +- frontend/test/fixture/contentType/comment.js | 10 +- frontend/test/fixture/contentType/file.js | 16 +- frontend/test/fixture/contentType/folder.js | 16 +- .../test/fixture/contentType/htmlDocument.js | 16 +- frontend/test/fixture/contentType/thread.js | 16 +- frontend/test/fixture/user/globalManager.js | 2 +- .../fixture/user/globalManagerAsMember.js | 2 +- .../test/fixture/workspace/firstWorkspace.js | 4 +- frontend/test/helper.spec.js | 104 --------- frontend/test/hocMock/helper.js | 48 +--- .../test/hocMock/redux/appList/appList.js | 10 +- .../redux/appList/appListAsSidebarEntry.js | 10 +- .../hocMock/redux/contentType/contentType.js | 10 +- frontend/test/hocMock/redux/user/user.js | 2 +- .../redux/workspaceList/workspaceList.js | 2 +- frontend/test/hocMock/store.js | 19 ++ frontend/test/hocMock/withRouter.js | 20 +- frontend/test/setup.js | 12 +- .../test/src/action-creator.async.spec.js | 27 +++ .../test/src/component/AgendaInfo.spec.js | 33 +++ .../src/component/BtnExtandedAction.spec.js | 67 ++++++ frontend/test/src/component/Button.spec.js | 48 ++++ frontend/test/src/component/Calendar.spec.js | 20 ++ frontend/test/src/component/Card.spec.js | 29 +++ frontend/test/src/component/CardBody.spec.js | 28 +++ .../test/src/component/CardHeader.spec.js | 35 +++ .../src/component/ContentItemHeader.spec.js | 24 ++ .../src/component/ContentItemSearch.spec.js | 76 +++++++ .../test/src/component/ContentTypeBtn.spec.js | 58 +++++ .../test/src/component/DragHandle.spec.js | 31 +++ .../component/DropdownCreateButton.spec.js | 42 ++++ .../test/src/component/DropdownLang.spec.js | 62 ++++++ .../test/src/component/FlashMessage.spec.js | 38 ++++ frontend/test/src/component/Help.spec.js | 22 ++ .../src/component/HomeHasWorkspace.spec.js | 20 ++ .../src/component/HomeNoWorkspace.spec.js | 45 ++++ .../test/src/component/InputGroupTest.spec.js | 74 +++++++ frontend/test/src/component/LoginLogo.spec.js | 23 ++ frontend/test/src/component/Logo.spec.js | 23 ++ .../test/src/component/MemberList.spec.js | 81 +++++++ .../test/src/component/MenuProfil.spec.js | 32 +++ .../src/component/MenuSubComponent.spec.js | 47 ++++ frontend/test/src/component/MoreInfo.spec.js | 53 +++++ .../test/src/component/Notification.spec.js | 49 +++++ .../test/src/component/OpenContentApp.spec.js | 72 ++++++ .../component/OpenCreateContentApp.spec.js | 53 +++++ frontend/test/src/component/Password.spec.js | 63 ++++++ .../test/src/component/PersonalData.spec.js | 45 ++++ .../test/src/component/RecentActivity.spec.js | 61 ++++++ frontend/test/src/component/Search.spec.js | 36 +++ .../component/SubDropdownCreateButton.spec.js | 53 +++++ frontend/test/src/component/Timezone.spec.js | 38 ++++ frontend/test/src/component/UserInfo.spec.js | 39 ++++ .../test/src/component/UserStatus.spec.js | 83 +++++++ .../test/src/component/WebdavInfo.spec.js | 33 +++ .../component/WorkspaceListItem.spec.js | 23 +- frontend/test/src/container/Account.spec.js | 207 ++++++++++++++++++ .../src/container/AppFullscreenRouter.spec.js | 73 ++++++ .../test/src/container/ForgotPassword.spec.js | 48 ++++ frontend/test/src/container/Home.spec.js | 44 ++++ frontend/test/src/container/Sidebar.spec.js | 34 +++ frontend/test/src/container/Tracim.spec.js | 169 ++++++++++++++ frontend/test/src/helper.spec.js | 168 ++++++++++++++ 90 files changed, 2585 insertions(+), 261 deletions(-) create mode 100644 frontend/configEnv-test.json delete mode 100644 frontend/test/helper.spec.js create mode 100644 frontend/test/hocMock/store.js create mode 100644 frontend/test/src/action-creator.async.spec.js create mode 100644 frontend/test/src/component/AgendaInfo.spec.js create mode 100644 frontend/test/src/component/BtnExtandedAction.spec.js create mode 100644 frontend/test/src/component/Button.spec.js create mode 100644 frontend/test/src/component/Calendar.spec.js create mode 100644 frontend/test/src/component/Card.spec.js create mode 100644 frontend/test/src/component/CardBody.spec.js create mode 100644 frontend/test/src/component/CardHeader.spec.js create mode 100644 frontend/test/src/component/ContentItemHeader.spec.js create mode 100644 frontend/test/src/component/ContentItemSearch.spec.js create mode 100644 frontend/test/src/component/ContentTypeBtn.spec.js create mode 100644 frontend/test/src/component/DragHandle.spec.js create mode 100644 frontend/test/src/component/DropdownCreateButton.spec.js create mode 100644 frontend/test/src/component/DropdownLang.spec.js create mode 100644 frontend/test/src/component/FlashMessage.spec.js create mode 100644 frontend/test/src/component/Help.spec.js create mode 100644 frontend/test/src/component/HomeHasWorkspace.spec.js create mode 100644 frontend/test/src/component/HomeNoWorkspace.spec.js create mode 100644 frontend/test/src/component/InputGroupTest.spec.js create mode 100644 frontend/test/src/component/LoginLogo.spec.js create mode 100644 frontend/test/src/component/Logo.spec.js create mode 100644 frontend/test/src/component/MemberList.spec.js create mode 100644 frontend/test/src/component/MenuProfil.spec.js create mode 100644 frontend/test/src/component/MenuSubComponent.spec.js create mode 100644 frontend/test/src/component/MoreInfo.spec.js create mode 100644 frontend/test/src/component/Notification.spec.js create mode 100644 frontend/test/src/component/OpenContentApp.spec.js create mode 100644 frontend/test/src/component/OpenCreateContentApp.spec.js create mode 100644 frontend/test/src/component/Password.spec.js create mode 100644 frontend/test/src/component/PersonalData.spec.js create mode 100644 frontend/test/src/component/RecentActivity.spec.js create mode 100644 frontend/test/src/component/Search.spec.js create mode 100644 frontend/test/src/component/SubDropdownCreateButton.spec.js create mode 100644 frontend/test/src/component/Timezone.spec.js create mode 100644 frontend/test/src/component/UserInfo.spec.js create mode 100644 frontend/test/src/component/UserStatus.spec.js create mode 100644 frontend/test/src/component/WebdavInfo.spec.js rename frontend/test/{ => src}/component/WorkspaceListItem.spec.js (74%) create mode 100644 frontend/test/src/container/Account.spec.js create mode 100644 frontend/test/src/container/AppFullscreenRouter.spec.js create mode 100644 frontend/test/src/container/ForgotPassword.spec.js create mode 100644 frontend/test/src/container/Home.spec.js create mode 100644 frontend/test/src/container/Sidebar.spec.js create mode 100644 frontend/test/src/container/Tracim.spec.js create mode 100644 frontend/test/src/helper.spec.js diff --git a/frontend/configEnv-test.json b/frontend/configEnv-test.json new file mode 100644 index 0000000000..c4fcf2876a --- /dev/null +++ b/frontend/configEnv-test.json @@ -0,0 +1,3 @@ +{ + "apiUrl": "http://localhost:1337/api/v2" +} diff --git a/frontend/package.json b/frontend/package.json index f442b2f84e..80759461c7 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -13,7 +13,7 @@ "buildwindoz": "set NODE_ENV=production&& webpack -p", "build-devwindoz": "set NODE_ENV=production&& webpack", "build-translation": "node i18next.scanner.js", - "test": "NODE_ENV=test mocha --config test/.mocharc.js" + "test": "(standard --env mocha \"test/**/*.js\" || echo \"\nSome Linting error\") && NODE_ENV=test mocha --config test/.mocharc.js" }, "author": "", "license": "ISC", @@ -32,7 +32,7 @@ "react-device-detect": "^1.7.5", "react-dnd": "7.4.5", "react-dnd-html5-backend": "7.4.4", - "react-dom": "^16.7.0", + "react-dom": "16.7.0", "react-i18next": "7.4.0", "react-redux": "5.0.6", "react-router": "^5.0.1", @@ -57,14 +57,18 @@ "chai": "^4.2.0", "chai-enzyme": "^1.0.0-beta.1", "css-loader": "^3.0.0", - "enzyme": "^3.10.0", + "enzyme": "3.10.0", "enzyme-adapter-react-16": "^1.14.0", "file-loader": "^4.0.0", "i18next-scanner": "^2.10.2", "ignore-styles": "^5.0.1", + "isomorphic-fetch": "^2.2.1", "jsdom": "^15.1.1", "json-server": "^0.15.0", "mocha": "^6.1.4", + "nock": "^10.0.6", + "redux-mock-store": "^1.5.3", + "sinon": "^7.4.1", "standard": "^12.0.1", "standard-loader": "^6.0.1", "style-loader": "^0.23.1", diff --git a/frontend/src/action-creator.async.js b/frontend/src/action-creator.async.js index cdb346950e..05d8c34f13 100644 --- a/frontend/src/action-creator.async.js +++ b/frontend/src/action-creator.async.js @@ -3,7 +3,8 @@ import { FETCH_CONFIG, PAGE, COOKIE_FRONTEND, - unLoggedAllowedPageList + unLoggedAllowedPageList, + history } from './helper.js' import i18n from './i18n.js' import * as Cookies from 'js-cookie' @@ -45,7 +46,6 @@ import { WORKSPACE_CONTENT_MOVE, SEARCHED_KEYWORDS } from './action-creator.sync.js' -import { history } from './index.js' import { ErrorFlashMessageTemplateHtml } from 'tracim_frontend_lib' /* diff --git a/frontend/src/component/Account/MenuSubComponent.jsx b/frontend/src/component/Account/MenuSubComponent.jsx index 16d150281f..76ff31478f 100644 --- a/frontend/src/component/Account/MenuSubComponent.jsx +++ b/frontend/src/component/Account/MenuSubComponent.jsx @@ -1,5 +1,6 @@ import React from 'react' import classnames from 'classnames' +import PropTypes from 'prop-types' import { translate } from 'react-i18next' require('./MenuSubComponent.styl') @@ -31,3 +32,13 @@ export const MenuSubComponent = props => { } export default translate()(MenuSubComponent) + +MenuSubComponent.propTypes = { + menu: PropTypes.arrayOf(PropTypes.object), + onClickMenuItem: PropTypes.func +} + +MenuSubComponent.defaultProps = { + menu: [], + onClickMenuItem: () => {} +} diff --git a/frontend/src/component/Account/Notification.jsx b/frontend/src/component/Account/Notification.jsx index 92f545cb47..10c5cf163e 100755 --- a/frontend/src/component/Account/Notification.jsx +++ b/frontend/src/component/Account/Notification.jsx @@ -1,6 +1,7 @@ import React from 'react' +import PropTypes from 'prop-types' import { translate } from 'react-i18next' -import { BtnSwitch, ROLE } from 'tracim_frontend_lib' +import { BtnSwitch, ROLE_LIST } from 'tracim_frontend_lib' export const Notification = props =>
@@ -24,7 +25,7 @@ export const Notification = props => {props.workspaceList.length > 0 ? props.workspaceList.map(ws => { const mySelf = ws.memberList.find(u => u.id === props.userLoggedId) - const myRole = ROLE.find(r => r.slug === mySelf.role) + const myRole = ROLE_LIST.find(r => r.slug === mySelf.role) return ( @@ -67,3 +68,14 @@ export const Notification = props =>
export default translate()(Notification) + +Notification.propTypes = { + workspaceList: PropTypes.arrayOf(PropTypes.object), + userLoggedId: PropTypes.number, + onChangeSubscriptionNotif: PropTypes.func +} + +Notification.defaultProps = { + workspaceList: [], + onChangeSubscriptionNotif: () => {} +} diff --git a/frontend/src/component/Account/Timezone.jsx b/frontend/src/component/Account/Timezone.jsx index d4a0cc4ada..36239c6d2f 100644 --- a/frontend/src/component/Account/Timezone.jsx +++ b/frontend/src/component/Account/Timezone.jsx @@ -1,6 +1,7 @@ import React from 'react' import Select from 'react-select' -import 'react-select/dist/react-select.css' +// INFO - GM - 2019-08-20 - this css file doesn't exist +// import 'react-select/dist/react-select.css' import { translate } from 'react-i18next' export const Timezone = props => { diff --git a/frontend/src/component/ContentItemSearch.jsx b/frontend/src/component/ContentItemSearch.jsx index 9ec99495cf..7b2dd0cd78 100644 --- a/frontend/src/component/ContentItemSearch.jsx +++ b/frontend/src/component/ContentItemSearch.jsx @@ -6,7 +6,7 @@ import { Badge, Avatar } from 'tracim_frontend_lib' require('./ContentItemSearch.styl') -const ContentItemSearch = props => { +export const ContentItemSearch = props => { const status = props.contentType.availableStatuses.find(s => s.slug === props.statusSlug) || { hexcolor: '', label: '', faIcon: '' } return ( diff --git a/frontend/src/component/FlashMessage.jsx b/frontend/src/component/FlashMessage.jsx index 7d3e06e4de..0556f28ed9 100644 --- a/frontend/src/component/FlashMessage.jsx +++ b/frontend/src/component/FlashMessage.jsx @@ -4,7 +4,7 @@ import PropTypes from 'prop-types' require('./FlashMessage.styl') -const FlashMessage = props => { +export const FlashMessage = props => { if (!props.flashMessage.length || props.flashMessage.length === 0) return null const dataTypeArray = [{ diff --git a/frontend/src/component/Header/MenuActionListItem/MenuProfil.jsx b/frontend/src/component/Header/MenuActionListItem/MenuProfil.jsx index 0589fd30bc..fc6980df68 100644 --- a/frontend/src/component/Header/MenuActionListItem/MenuProfil.jsx +++ b/frontend/src/component/Header/MenuActionListItem/MenuProfil.jsx @@ -7,7 +7,7 @@ import { Avatar } from 'tracim_frontend_lib' require('./MenuProfil.styl') -const MenuProfil = props => { +export const MenuProfil = props => { if (!props.user.logged) return null return ( diff --git a/frontend/src/component/Header/Search.jsx b/frontend/src/component/Header/Search.jsx index 87e418d324..d5476cf399 100644 --- a/frontend/src/component/Header/Search.jsx +++ b/frontend/src/component/Header/Search.jsx @@ -3,7 +3,7 @@ import { translate } from 'react-i18next' require('./Search.styl') -class Search extends React.Component { +export class Search extends React.Component { constructor (props) { super(props) diff --git a/frontend/src/component/Workspace/BtnExtandedAction.jsx b/frontend/src/component/Workspace/BtnExtandedAction.jsx index a85759736b..7d7f314d34 100644 --- a/frontend/src/component/Workspace/BtnExtandedAction.jsx +++ b/frontend/src/component/Workspace/BtnExtandedAction.jsx @@ -5,7 +5,7 @@ import { ROLE } from 'tracim_frontend_lib' import { PAGE } from '../../helper' import { Link } from 'react-router-dom' -const ExtandedAction = props => { +export const ExtandedAction = props => { return (
{ +export const FileItemHeader = props => { return (
diff --git a/frontend/src/component/common/Input/DropdownCreateButton.jsx b/frontend/src/component/common/Input/DropdownCreateButton.jsx index 5a8261acc2..7d22e28ccf 100644 --- a/frontend/src/component/common/Input/DropdownCreateButton.jsx +++ b/frontend/src/component/common/Input/DropdownCreateButton.jsx @@ -4,7 +4,7 @@ import classnames from 'classnames' import SubDropdownCreateButton from './SubDropdownCreateButton.jsx' import { translate } from 'react-i18next' -const DropdownCreateButton = props => { +export const DropdownCreateButton = props => { return (