-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Vu Nguyen
authored
Jun 19, 2020
1 parent
bc54564
commit 92cc55f
Showing
6 changed files
with
136 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 26 additions & 41 deletions
67
packages/marketplace/src/components/ui/__tests__/__snapshots__/developer-set-status.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,33 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`SetDeveloperStatusModal should match snapshot 1`] = ` | ||
<Component | ||
afterClose={[Function]} | ||
renderChildren={true} | ||
visible={true} | ||
> | ||
<Component | ||
afterClose={[Function]} | ||
title="Confirm undefined Deactivation" | ||
/> | ||
<Component | ||
body={ | ||
<Unknown | ||
isCentered={true} | ||
> | ||
Are you sure you want to | ||
deactivate | ||
‘ | ||
’? | ||
</Unknown> | ||
<Provider | ||
store={ | ||
Object { | ||
"clearActions": [Function], | ||
"dispatch": [Function], | ||
"getActions": [Function], | ||
"getState": [Function], | ||
"replaceReducer": [Function], | ||
"subscribe": [Function], | ||
} | ||
/> | ||
} | ||
> | ||
<Component | ||
footerItems={ | ||
<React.Fragment> | ||
<Unknown | ||
loading={false} | ||
onClick={[Function]} | ||
type="button" | ||
variant="danger" | ||
> | ||
Confirm | ||
</Unknown> | ||
<Unknown | ||
disabled={false} | ||
onClick={[Function]} | ||
type="button" | ||
variant="secondary" | ||
> | ||
Cancel | ||
</Unknown> | ||
</React.Fragment> | ||
developer={ | ||
Object { | ||
"id": "", | ||
"isInactive": false, | ||
} | ||
} | ||
/> | ||
</Component> | ||
onSuccess={[Function]} | ||
visible={true} | ||
> | ||
<Component | ||
afterClose={[Function]} | ||
renderChildren={true} | ||
visible={true} | ||
/> | ||
</Component> | ||
</Provider> | ||
`; |
84 changes: 51 additions & 33 deletions
84
packages/marketplace/src/components/ui/__tests__/developer-set-status.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,73 @@ | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
import * as ReactRedux from 'react-redux' | ||
import { mount } from 'enzyme' | ||
import configureStore from 'redux-mock-store' | ||
import appState from '@/reducers/__stubs__/app-state' | ||
import { | ||
SetDeveloperStatusModal, | ||
SetDeveloperStatusProps, | ||
onAfterCloseHandler, | ||
onSuccessHandler, | ||
onConfirmButtonClick, | ||
} from '../developer-set-status' | ||
import { developerSetStatusSetInitFormState, developerSetStatusRequest } from '@/actions/developer-set-status' | ||
import { developerStub } from '@/sagas/__stubs__/developer' | ||
|
||
const props: SetDeveloperStatusProps = { | ||
developer: { id: '', isInactive: false }, | ||
onSuccess: () => jest.fn(), | ||
visible: true, | ||
} | ||
|
||
describe('SetDeveloperStatusModal', () => { | ||
let store | ||
let spyDispatch | ||
beforeEach(() => { | ||
/* mocking store */ | ||
const mockStore = configureStore() | ||
store = mockStore(appState) | ||
spyDispatch = jest.spyOn(ReactRedux, 'useDispatch').mockImplementation(() => store.dispatch) | ||
}) | ||
|
||
it('should match snapshot', () => { | ||
const props = { | ||
developer: { id: '', isInactive: false }, | ||
developerName: '', | ||
onSuccess: () => jest.fn(), | ||
formState: 'PENDING', | ||
visible: true, | ||
afterClose: () => jest.fn(), | ||
developerSetStatusRequest: () => jest.fn(), | ||
resetDeveloperSetStatusReducer: () => jest.fn(), | ||
} as SetDeveloperStatusProps | ||
|
||
const wrapper = shallow(<SetDeveloperStatusModal {...props} />) | ||
const wrapper = mount( | ||
<ReactRedux.Provider store={store}> | ||
<SetDeveloperStatusModal {...props} /> | ||
</ReactRedux.Provider>, | ||
) | ||
expect(wrapper).toMatchSnapshot() | ||
}) | ||
}) | ||
|
||
describe('onAfterCloseHandler', () => { | ||
it('should return a function when executing', () => { | ||
const mockAfterClose = jest.fn() | ||
describe('onAfterCloseHandler', () => { | ||
it('should return a function when executing', () => { | ||
const mockAfterClose = jest.fn() | ||
|
||
const onAfterCloseHandlerFn = onAfterCloseHandler({ afterClose: mockAfterClose, isLoading: false }) | ||
expect(onAfterCloseHandlerFn).toBeDefined() | ||
const onAfterCloseHandlerFn = onAfterCloseHandler(false, mockAfterClose) | ||
expect(onAfterCloseHandlerFn).toBeDefined() | ||
|
||
onAfterCloseHandlerFn() | ||
expect(mockAfterClose).toBeCalled() | ||
onAfterCloseHandlerFn() | ||
expect(mockAfterClose).toBeCalled() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('onSuccessHandler', () => { | ||
it('should return a function when executing', () => { | ||
const mockOnSuccess = jest.fn() | ||
const mockResetDeveloperSetStatusReducer = jest.fn() | ||
describe('onSuccessHandler', () => { | ||
it('should return a function when executing', () => { | ||
const mockOnSuccess = jest.fn() | ||
const onSuccessHandlerFn = onSuccessHandler(mockOnSuccess, spyDispatch) | ||
expect(onSuccessHandlerFn).toBeDefined() | ||
|
||
const onSuccessHandlerFn = onSuccessHandler({ | ||
onSuccess: mockOnSuccess, | ||
resetDeveloperSetStatusReducer: mockResetDeveloperSetStatusReducer, | ||
onSuccessHandlerFn() | ||
expect(mockOnSuccess).toBeCalled() | ||
expect(spyDispatch).toBeCalledWith(developerSetStatusSetInitFormState()) | ||
}) | ||
expect(onSuccessHandlerFn).toBeDefined() | ||
}) | ||
|
||
onSuccessHandlerFn() | ||
expect(mockOnSuccess).toBeCalled() | ||
expect(mockResetDeveloperSetStatusReducer).toBeCalled() | ||
describe('onConfirmButtonClick', () => { | ||
it('should run correctly', () => { | ||
const mockIsInactive = false | ||
const fn = onConfirmButtonClick(developerStub, spyDispatch, mockIsInactive) | ||
fn() | ||
expect(spyDispatch).toBeCalledWith(developerSetStatusRequest({ ...developerStub, isInactive: !mockIsInactive })) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/marketplace/src/selector/__tests__/developer-set-status.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ReduxState } from '@/types/core' | ||
import { selectDeveloperSetStatusFormState } from '../developer-set-status' | ||
|
||
describe('selectAppDeleteFormState', () => { | ||
it('should run correctly', () => { | ||
const input = { | ||
developerSetStatus: { | ||
formState: 'PENDING', | ||
}, | ||
} as ReduxState | ||
const result = selectDeveloperSetStatusFormState(input) | ||
expect(result).toEqual('PENDING') | ||
}) | ||
|
||
it('should run correctly and return []', () => { | ||
const input = {} as ReduxState | ||
const result = selectDeveloperSetStatusFormState(input) | ||
expect(result).toEqual(undefined) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { ReduxState, FormState } from '@/types/core' | ||
|
||
export const selectDeveloperSetStatusFormState = (state: ReduxState): FormState => { | ||
return state.developerSetStatus?.formState | ||
} |