Skip to content

Commit

Permalink
fix: cld-719 modal should disapper when success message (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
duong-se authored Jan 15, 2020
1 parent 444f8f0 commit 1082581
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 95 deletions.
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
"lint:src": "tslint --fix --project tsconfig.json --format stylish",
"lint:cypress": "tslint --fix --project './cypress/tsconfig.json' --format stylish",
"lint": "yarn lint:src && yarn lint:cypress",
"test": "jest --coverage --silent",
"test-dev": "jest --watch --verbose",
"test:ci": "jest --ci --reporters=default --reporters=jest-junit",
"test": "cross-env TZ=UTC jest --coverage --silent",
"test-dev": "cross-env TZ=UTC jest --watch --verbose",
"test:ci": "cross-env TZ=UTC jest --ci --reporters=default --reporters=jest-junit",
"test-e2e:dev": "cypress open",
"test-e2e": "cypress run --headless",
"test-e2e:ci": "concurrently --success=\"first\" \"yarn start\" \"yarn test-e2e\" -k",
"test-perf": "npx jest --config='src/tests/lighthouse/jest.config.js'",
"test-perf": "cross-env TZ=UTC npx jest --config='src/tests/lighthouse/jest.config.js'",
"test-perf:ci": "concurrently --success=\"first\" \"yarn start\" \"yarn test-perf\" -k"
},
"dependencies": {
Expand Down Expand Up @@ -69,6 +69,7 @@
"bundle-phobia-cli": "~0.13.0",
"chromedriver": "~2.43.1",
"concurrently": "~4.1.1",
"cross-env": "^6.0.3",
"css-loader": "~3.0.0",
"cypress": "^3.8.0",
"cypress-file-upload": "^3.5.1",
Expand All @@ -92,6 +93,7 @@
"lint-staged": "~8.1.7",
"loader-utils": "^1.2.3",
"mini-css-extract-plugin": "~0.7.0",
"mockdate": "^2.0.5",
"nanoid": "^2.1.8",
"node-sass": "~4.12.0",
"prettier": "^1.18.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ exports[`AdminRevisionModalInner should match a snapshot when LOADING false 1`]
data-test="revision-detail-modal"
title="Confirm Peter's Properties revision"
/>
<Connect(Component)
afterClose={[Function]}
onApproveSuccess={[Function]}
visible={false}
/>
<Connect(Component)
afterClose={[Function]}
onDeclineSuccess={[Function]}
visible={false}
/>
<ModalBody
body={
<React.Fragment>
Expand Down Expand Up @@ -260,15 +250,15 @@ Get notifications when a new deal is available."
<Button
className="mr-2"
dataTest="revision-approve-button"
onClick={[Function]}
onClick={[MockFunction]}
type="button"
variant="primary"
>
Approve
</Button>
<Button
data-test="revision-decline-button"
onClick={[Function]}
onClick={[MockFunction]}
type="button"
variant="danger"
>
Expand Down
44 changes: 31 additions & 13 deletions src/components/ui/__tests__/admin-approval-modal.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import * as React from 'react'
import { shallow, mount } from 'enzyme'
import { shallow } from 'enzyme'
import toJson from 'enzyme-to-json'
import {
AdminApprovalModalInner,
AdminApprovalInnerProps,
AdminApprovalModalInnerProps,
isAppearInScope,
renderCheckboxesDiff,
handleOnApproveSuccess,
handleOnDeclineSuccess,
handleSetIsDeclineModal,
handleSetIsApproveModal
handleSetIsApproveModal,
mapStateToProps
} from '../admin-approval-modal'
import { appDetailDataStub } from '@/sagas/__stubs__/app-detail'
import { revisionDetailDataStub } from '@/sagas/__stubs__/revision-detail'
import { appPermissionStub } from '@/sagas/__stubs__/app-permission'
import { ModalBody } from '@reapit/elements'
import { ReduxState } from '@/types/core'

const props = (loading: boolean, error: boolean): AdminApprovalInnerProps => ({
const props = (loading: boolean, error: boolean): AdminApprovalModalInnerProps => ({
appDetailState: {
loading,
error,
Expand All @@ -33,7 +35,9 @@ const props = (loading: boolean, error: boolean): AdminApprovalInnerProps => ({
revisionDetailData: { data: revisionDetailDataStub.data, scopes: appPermissionStub },
approveFormState: 'PENDING',
declineFormState: 'PENDING'
}
},
onApprovalClick: jest.fn(),
onDeclineClick: jest.fn()
})

describe('AdminRevisionModalInner', () => {
Expand Down Expand Up @@ -126,30 +130,35 @@ describe('renderAdditionalCheckboxes', () => {

describe('handleOnApproveSuccess', () => {
it('should call function correctly', () => {
const closeParentModal = jest.fn()
const setIsApproveModalOpen = jest.fn()
const fn = handleOnApproveSuccess({ closeParentModal, setIsApproveModalOpen })
const fn = handleOnApproveSuccess(setIsApproveModalOpen)
fn()
expect(closeParentModal).toBeCalled()
expect(setIsApproveModalOpen).toBeCalled()
})
})

describe('handleOnDeclineSuccess', () => {
it('should call function correctly', () => {
const closeParentModal = jest.fn()
const setIsDeclineModalOpen = jest.fn()
const fn = handleOnDeclineSuccess({ closeParentModal, setIsDeclineModalOpen })
const fn = handleOnDeclineSuccess(setIsDeclineModalOpen)
fn()
expect(closeParentModal).toBeCalled()
expect(setIsDeclineModalOpen).toBeCalled()
})
})

describe('handleSetIsDeclineModal', () => {
it('should call function correctly', () => {
const setIsDeclineModalOpen = jest.fn()
const fn = handleSetIsDeclineModal(setIsDeclineModalOpen, true)
const afterClose = jest.fn()
const fn = handleSetIsDeclineModal({ setIsDeclineModalOpen, isDeclineModalOpen: true, afterClose })
fn()
expect(setIsDeclineModalOpen).toBeCalled()
expect(afterClose).toBeCalled()
})

it('should call function correctly', () => {
const setIsDeclineModalOpen = jest.fn()
const fn = handleSetIsDeclineModal({ setIsDeclineModalOpen, isDeclineModalOpen: true })
fn()
expect(setIsDeclineModalOpen).toBeCalled()
})
Expand All @@ -158,7 +167,16 @@ describe('handleSetIsDeclineModal', () => {
describe('handleSetIsApproveModal', () => {
it('should call function correctly', () => {
const setIsApproveModalOpen = jest.fn()
const fn = handleSetIsApproveModal(setIsApproveModalOpen, true)
const afterClose = jest.fn()
const fn = handleSetIsApproveModal({ setIsApproveModalOpen, isApproveModalOpen: true, afterClose })
fn()
expect(setIsApproveModalOpen).toBeCalled()
expect(afterClose).toBeCalled()
})

it('should call function correctly', () => {
const setIsApproveModalOpen = jest.fn()
const fn = handleSetIsApproveModal({ setIsApproveModalOpen, isApproveModalOpen: true })
fn()
expect(setIsApproveModalOpen).toBeCalled()
})
Expand Down
Loading

0 comments on commit 1082581

Please sign in to comment.