Skip to content

Commit

Permalink
chore: update follow PR cmts
Browse files Browse the repository at this point in the history
  • Loading branch information
Truong An committed Jul 16, 2020
1 parent e02ce38 commit b698207
Show file tree
Hide file tree
Showing 22 changed files with 97 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ exports[`admin-apps AdminApprovals should match a snapshot 1`] = `
validate={null}
>
<div
className="field "
className=""
>
<div
className="control "
Expand All @@ -238,7 +238,7 @@ exports[`admin-apps AdminApprovals should match a snapshot 1`] = `
App Name
</label>
<input
className="input is-primary"
className=""
data-test=""
disabled={false}
id="appName"
Expand Down Expand Up @@ -273,7 +273,7 @@ exports[`admin-apps AdminApprovals should match a snapshot 1`] = `
validate={null}
>
<div
className="field "
className=""
>
<div
className="control "
Expand All @@ -285,7 +285,7 @@ exports[`admin-apps AdminApprovals should match a snapshot 1`] = `
Developer Name
</label>
<input
className="input is-primary"
className=""
data-test=""
disabled={false}
id="developerName"
Expand Down Expand Up @@ -320,7 +320,7 @@ exports[`admin-apps AdminApprovals should match a snapshot 1`] = `
validate={null}
>
<div
className="field "
className=""
>
<div
className="control "
Expand All @@ -332,7 +332,7 @@ exports[`admin-apps AdminApprovals should match a snapshot 1`] = `
Company Name
</label>
<input
className="input is-primary"
className=""
data-test=""
disabled={false}
id="companyName"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import * as React from 'react'
import { mount } from 'enzyme'
import { DevsManagement, onPageChangeHandler, onSearchHandler, handleFetchData } from '../devs-management'
import { DevsManagementFilterFormValues } from '@/components/ui/devs-management-filter-form'
import {
DevsManagement,
onPageChangeHandler,
onSearchHandler,
handleFetchData,
onClickStatusButton,
} from '../devs-management'
import { getMockRouterProps } from '@/utils/mock-helper'
import { MemoryRouter } from 'react-router'
import configureStore from 'redux-mock-store'
Expand All @@ -10,6 +15,7 @@ import Routes from '@/constants/routes'
import appState from '@/reducers/__stubs__/app-state'
import { PagedResultDeveloperModel_ } from '@reapit/foundations-ts-definitions'
import { devsManagementRequestData } from '@/actions/devs-management'
import { DevsManagementFilterFormValues } from '@/components/ui/devs-management-filter-form'

const createStore = (loading: boolean, data?: PagedResultDeveloperModel_) => {
return {
Expand Down Expand Up @@ -111,3 +117,15 @@ describe('handleFetchData', () => {
expect(dispatch).toBeCalledWith(devsManagementRequestData(params))
})
})

describe('onClickStatusButton', () => {
it('should run correctly', () => {
const setDeveloper = jest.fn()
const setIsSetStatusModalOpen = jest.fn()
const developerData = {}
const fn = onClickStatusButton(setDeveloper, setIsSetStatusModalOpen, developerData)
fn()
expect(setDeveloper).toBeCalledWith({ ...developerData })
expect(setIsSetStatusModalOpen).toBeCalledWith(true)
})
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react'
import React from 'react'
import { History } from 'history'
import { useDispatch, useSelector } from 'react-redux'
import { Link } from 'react-router-dom'
Expand Down Expand Up @@ -82,6 +82,15 @@ export const onSearchHandler = (history: History<any>) => (
}
}

export const onClickStatusButton = (
setDeveloper: React.Dispatch<DeveloperModel>,
setIsSetStatusModalOpen: React.Dispatch<boolean>,
developerData,
) => () => {
setDeveloper({ ...developerData })
setIsSetStatusModalOpen(true)
}

export const DevsManagement: React.FC = () => {
const dispatch = useDispatch()
const history = useHistory()
Expand All @@ -92,7 +101,7 @@ export const DevsManagement: React.FC = () => {
const onPageChange = React.useCallback(onPageChangeHandler(history, filterValues), [history, filterValues])
const onSearch = React.useCallback(onSearchHandler(history), [history])
const [isSetStatusModalOpen, setIsSetStatusModalOpen] = React.useState(false)
const [developer, setDeveloper] = React.useState({} as DeveloperModel)
const [developer, setDeveloper] = React.useState<DeveloperModel>({} as DeveloperModel)

const devsManagementState = useSelector(selectDevsManagement)
const { loading, data } = devsManagementState
Expand All @@ -105,6 +114,7 @@ export const DevsManagement: React.FC = () => {
fetchData({ page: pageNumber, queryString: qs.stringify(filterValues as { name: string; company: string }) })
}
}

const pageNo = pageNumber - 1
const pageNoTimesRevsions = pageNo * REVISIONS_PER_PAGE
const HeaderCell = ({ row: { index } }) => <div style={{ width: 'auto' }}>{pageNoTimesRevsions + index + 1}</div>
Expand Down Expand Up @@ -136,10 +146,7 @@ export const DevsManagement: React.FC = () => {
<Button
type="button"
variant="primary"
onClick={() => {
setDeveloper({ ...original })
setIsSetStatusModalOpen(true)
}}
onClick={onClickStatusButton(setDeveloper, setIsSetStatusModalOpen, original)}
>
Status
</Button>
Expand Down
2 changes: 1 addition & 1 deletion packages/admin-portal/src/tests/badges/badge-branches.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/admin-portal/src/tests/badges/badge-functions.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/admin-portal/src/tests/badges/badge-lines.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit b698207

Please sign in to comment.