Skip to content

Commit

Permalink
feat: #1917 Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vu Nguyen committed Jul 13, 2020
1 parent caee82a commit f4d71d6
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ describe('Menu', () => {
search: '',
state: {},
}
const logout = jest.fn()
const result = generateMenuConfig(logout, location, false)
const result = generateMenuConfig(location)
expect(result).toBeDefined()
})
})
Expand Down
184 changes: 69 additions & 115 deletions packages/developer-portal/src/components/ui/menu.tsx
Original file line number Diff line number Diff line change
@@ -1,122 +1,82 @@
import * as React from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { useLocation } from 'react-router'
import { Menu as Sidebar, MenuConfig, ReapitLogo } from '@reapit/elements'
import { authLogout } from '@/actions/auth'
import Routes from '../../constants/routes'
import { Location } from 'history'
import { FaSignOutAlt, FaCloud, FaReadme, FaCog, FaChartBar, FaBolt, FaDesktop } from 'react-icons/fa'
import { FaCloud, FaReadme, FaCog, FaChartBar, FaBolt, FaDesktop } from 'react-icons/fa'
import { MdHelp } from 'react-icons/md'
import { GoDatabase } from 'react-icons/go'
import { selectIsAdmin, selectLoginType } from '@/selector/auth'
import { ActionCreator } from '@/types/core'
import { LoginType } from '@reapit/cognito-auth'
import { Dispatch } from 'redux'
import { selectDeveloperEditionId } from '@/selector/client'

export const generateMenuConfig = (
logoutCallback: () => void,
location: Location<any>,
isAdmin: boolean,
): { [key: string]: MenuConfig } => {
export const generateMenuConfig = (location: Location<any>): MenuConfig => {
return {
ADMIN: {
defaultActiveKey: 'APPROVALS',
location,
menu: [
{
key: 'LOGO',
icon: <ReapitLogo className="nav-item-icon" />,
type: 'LOGO',
},

{
title: 'Logout',
key: 'LOGOUT',
callback: logoutCallback,
icon: <FaSignOutAlt className="nav-item-icon" />,
type: 'SECONDARY',
},
],
},
DEVELOPER: {
defaultActiveKey: 'MANAGE_APPS',
location,
menu: [
{
key: 'LOGO',
icon: <ReapitLogo className="nav-item-icon" />,
type: 'LOGO',
},
{
title: 'Apps',
key: 'MANAGE_APPS',
url: Routes.APPS,
type: 'PRIMARY',
icon: <FaCloud className="nav-item-icon" />,
},
{
title: 'Analytics',
key: 'DEVELOPER_ANALYTICS',
url: Routes.ANALYTICS,
type: 'PRIMARY',
icon: <FaChartBar className="nav-item-icon" />,
},
{
title: 'API',
key: 'SWAGGER',
url: Routes.SWAGGER,
type: 'PRIMARY',
icon: <GoDatabase className="nav-item-icon" />,
},
{
title: 'Webhooks',
key: 'WEBHOOKS',
url: Routes.WEBHOOKS,
type: 'PRIMARY',
icon: <FaBolt className="nav-item-icon" />,
},
{
title: 'Docs',
key: 'API_DOCS',
url: Routes.API_DOCS,
type: 'PRIMARY',
icon: <FaReadme className="nav-item-icon" />,
},
{
title: 'Desktop',
key: 'DESKTOP',
url: Routes.DESKTOP,
type: 'PRIMARY',
icon: <FaDesktop className="nav-item-icon" />,
},
{
title: 'Help',
key: 'HELP',
url: Routes.HELP,
type: 'PRIMARY',
icon: <MdHelp className="nav-item-icon" />,
},
{
title: 'Settings',
key: 'SETTINGS',
url: Routes.SETTINGS,
icon: <FaCog className="nav-item-icon" />,
type: 'SECONDARY',
},
],
},
CLIENT: {
defaultActiveKey: 'BROWSE_APPS',
location,
menu: [
{
key: 'LOGO',
icon: <ReapitLogo className="nav-item-icon" />,
type: 'LOGO',
},
],
},
defaultActiveKey: 'MANAGE_APPS',
location,
menu: [
{
key: 'LOGO',
icon: <ReapitLogo className="nav-item-icon" />,
type: 'LOGO',
},
{
title: 'Apps',
key: 'MANAGE_APPS',
url: Routes.APPS,
type: 'PRIMARY',
icon: <FaCloud className="nav-item-icon" />,
},
{
title: 'Analytics',
key: 'DEVELOPER_ANALYTICS',
url: Routes.ANALYTICS,
type: 'PRIMARY',
icon: <FaChartBar className="nav-item-icon" />,
},
{
title: 'API',
key: 'SWAGGER',
url: Routes.SWAGGER,
type: 'PRIMARY',
icon: <GoDatabase className="nav-item-icon" />,
},
{
title: 'Webhooks',
key: 'WEBHOOKS',
url: Routes.WEBHOOKS,
type: 'PRIMARY',
icon: <FaBolt className="nav-item-icon" />,
},
{
title: 'Docs',
key: 'API_DOCS',
url: Routes.API_DOCS,
type: 'PRIMARY',
icon: <FaReadme className="nav-item-icon" />,
},
{
title: 'Desktop',
key: 'DESKTOP',
url: Routes.DESKTOP,
type: 'PRIMARY',
icon: <FaDesktop className="nav-item-icon" />,
},
{
title: 'Help',
key: 'HELP',
url: Routes.HELP,
type: 'PRIMARY',
icon: <MdHelp className="nav-item-icon" />,
},
{
title: 'Settings',
key: 'SETTINGS',
url: Routes.SETTINGS,
icon: <FaCog className="nav-item-icon" />,
type: 'SECONDARY',
},
],
}
}

Expand All @@ -136,14 +96,8 @@ export const logout = ({ dispatch, authLogout }: { dispatch: Dispatch; authLogou

export const Menu: React.FunctionComponent<MenuProps> = () => {
const location = useLocation()
const dispatch = useDispatch()
const isDesktopAdmin = useSelector(selectIsAdmin)
const isDeveloperEdition = Boolean(useSelector(selectDeveloperEditionId))
const loginType = useSelector(selectLoginType)
const isAdmin = isDesktopAdmin || isDeveloperEdition

const menuConfigs = generateMenuConfig(logout({ dispatch, authLogout }), location, isAdmin)
return <Sidebar {...menuConfigs[loginType]} location={location} />
const menuConfigs = generateMenuConfig(location)
return <Sidebar {...menuConfigs['DEVELOPER']} location={location} />
}

export default Menu
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { shallow, mount } from 'enzyme'
import configureStore from 'redux-mock-store'
import appState from '@/reducers/__stubs__/app-state'
import { PrivateRouteWrapper, handleSetTermsAcceptFromCookie } from '../private-route-wrapper'
import { selectLoginSession, selectRefreshSession, selectLoginType } from '@/selector/auth'
import { selectLoginSession, selectRefreshSession } from '@/selector/auth'
import { getTokenFromQueryString, redirectToOAuth, RefreshParams } from '@reapit/cognito-auth'
import { getCookieString, COOKIE_DEVELOPER_FIRST_TIME_LOGIN_COMPLETE } from '@/utils/cookie'
import { authSetRefreshSession, setInitDeveloperTermsAcceptedStateFromCookie } from '@/actions/auth'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { put, takeLatest, call } from '@redux-saga/core/effects'
import { appDeleteRequestSuccess, appDeleteRequestLoading, appDeleteRequestFailure } from '@/actions/app-delete'
import { Action } from '@/types/core'
import { cloneableGenerator } from '@redux-saga/testing-utils'
import { deleteAppById, fetchAppsList } from '@/services/apps'
import { deleteAppById } from '@/services/apps'

jest.mock('@/services/apps')
jest.mock('@reapit/elements')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ describe('revision-detail thunks', () => {
describe('revision decline submmit', () => {
const gen = cloneableGenerator(declineRevision as any)(declineSubmitParams)
const { appId, appRevisionId, ...body } = declineSubmitParams.data
expect(gen.next('SUBMITTING').value).toEqual(put(declineRevisionSetFormState('SUBMITTING')))
expect(gen.next().value).toEqual(call(rejectAppRevisionById, { id: appId, revisionId: appRevisionId, ...body }))

test('api call success', () => {
const clone = gen.clone()
expect(clone.next({}).value).toBeCalled()
expect(clone.next('SUCCESS').value).toEqual(put(declineRevisionSetFormState('SUCCESS')))
expect(clone.next().done).toBe(true)
})
Expand Down
2 changes: 1 addition & 1 deletion packages/developer-portal/src/utils/__tests__/actions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { actionCreator, isType } from '../actions'
import ActionTypes from '../../constants/action-types'
import { developerRequestData, developerReceiveData } from '../../actions/developer'
import { developerRequestData } from '../../actions/developer'
import { Action } from '../../types/core'
import { DeveloperRequestParams } from '@/reducers/developer'

Expand Down

0 comments on commit f4d71d6

Please sign in to comment.