-
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.
feat: #1325 Update webhook page tests
- Loading branch information
Showing
4 changed files
with
189 additions
and
295 deletions.
There are no files selected for viewing
212 changes: 0 additions & 212 deletions
212
packages/marketplace/src/components/pages/__tests__/developer-webhooks.tsx
This file was deleted.
Oops, something went wrong.
139 changes: 139 additions & 0 deletions
139
.../marketplace/src/components/pages/developer-webhooks/__test__/developer-webhooks.test.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 |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import * as React from 'react' | ||
import * as ReactRedux from 'react-redux' | ||
import configureStore from 'redux-mock-store' | ||
import { | ||
handleSubscriptionChange, | ||
mapDeveloperAppsToAppSelectBoxOptions, | ||
DeveloperWebhooks, | ||
renderCustomerName, | ||
renderTopicName, | ||
openEditModal, | ||
MODAL_TYPE, | ||
openCreateModal, | ||
openTestModal, | ||
} from '../developer-webhooks' | ||
import { mount } from 'enzyme' | ||
import { TopicModel } from '@/reducers/webhook-subscriptions' | ||
|
||
import { AppSummaryModel } from '@reapit/foundations-ts-definitions' | ||
import { SelectBoxOptions } from '@reapit/elements' | ||
import appState from '@/reducers/__stubs__/app-state' | ||
import { webhookSubscriptionsRequestData, webhookTopicsRequestData } from '@/actions/webhook-subscriptions' | ||
import { webhookSetOpenModal } from '@/actions/webhook-edit-modal' | ||
|
||
describe('DeveloperWebHooks', () => { | ||
let store | ||
let spyDispatch | ||
beforeEach(() => { | ||
/* mocking store */ | ||
const mockStore = configureStore() | ||
store = mockStore(appState) | ||
spyDispatch = jest.spyOn(ReactRedux, 'useDispatch').mockImplementation(() => store.dispatch) | ||
}) | ||
it('should match a snapshot', () => { | ||
window.reapit.config.appEnv = 'development' | ||
expect( | ||
mount( | ||
<ReactRedux.Provider store={store}> | ||
<DeveloperWebhooks /> | ||
</ReactRedux.Provider>, | ||
), | ||
).toMatchSnapshot() | ||
}) | ||
|
||
describe('mapDeveloperAppsToAppSelectBoxOptions', () => { | ||
it('should return correctly', () => { | ||
const inputs: AppSummaryModel[] = [ | ||
{ name: '1', id: 'id1' }, | ||
{ name: '2', id: 'id2' }, | ||
] | ||
|
||
const outputs: SelectBoxOptions[] = [ | ||
{ label: '1', value: 'id1' }, | ||
{ label: '2', value: 'id2' }, | ||
] | ||
|
||
expect(mapDeveloperAppsToAppSelectBoxOptions(inputs)).toEqual(outputs) | ||
}) | ||
}) | ||
|
||
describe('handleSubscriptionChange', () => { | ||
it('should run correctly', () => { | ||
const values = { applicationId: '123' } | ||
handleSubscriptionChange(spyDispatch)(values) | ||
expect(spyDispatch).toHaveBeenCalledWith(webhookSubscriptionsRequestData(values.applicationId)) | ||
expect(spyDispatch).toHaveBeenCalledWith(webhookTopicsRequestData(values.applicationId)) | ||
}) | ||
}) | ||
describe('renderTopicName', () => { | ||
it('should run correctly', () => { | ||
const topics: TopicModel[] = [ | ||
{ | ||
id: 'XXX', | ||
created: '', | ||
modified: '', | ||
name: 'xxx', | ||
description: '', | ||
url: '', | ||
active: false, | ||
associatedScope: '', | ||
example: '', | ||
}, | ||
{ | ||
id: 'YYY', | ||
created: '', | ||
modified: '', | ||
name: 'yyy', | ||
description: '', | ||
url: '', | ||
active: false, | ||
associatedScope: '', | ||
example: '', | ||
}, | ||
] | ||
const subscriptionTopicIds: string[] = ['XXX', 'YYY'] | ||
const result = renderTopicName(topics, subscriptionTopicIds) | ||
const expected = ['xxx', 'yyy'] | ||
expect(result).toEqual(expected) | ||
}) | ||
}) | ||
describe('renderCustomerName', () => { | ||
it('should run correctly', () => { | ||
const subscriptionCustomerIds = ['XXX', 'yyy'] | ||
const subscriptionCustomerIdsEmpty = [] | ||
const result = renderCustomerName(subscriptionCustomerIds) | ||
const expected = ['XXX', 'yyy'] | ||
expect(result).toEqual(expected) | ||
|
||
const emptyResult = renderCustomerName(subscriptionCustomerIdsEmpty) | ||
expect(emptyResult).toEqual(['All Customers (*)']) | ||
}) | ||
}) | ||
describe('openEditModal', () => { | ||
it('should run correctly', () => { | ||
const setWebhookId = jest.fn() | ||
const webhookId = 'webhookId' | ||
|
||
openEditModal(spyDispatch, setWebhookId)(webhookId) | ||
expect(spyDispatch).toBeCalledWith(webhookSetOpenModal(MODAL_TYPE.EDIT)) | ||
expect(setWebhookId).toBeCalledWith(webhookId) | ||
}) | ||
}) | ||
describe('openCreateModal', () => { | ||
it('should run correctly', () => { | ||
openCreateModal(spyDispatch)() | ||
expect(spyDispatch).toBeCalledWith(webhookSetOpenModal(MODAL_TYPE.CREATE)) | ||
}) | ||
}) | ||
|
||
describe('openTestModal', () => { | ||
it('should run correctly', () => { | ||
const webhookSetOpenModal = jest.fn() | ||
const webhookId = 'webhookId' | ||
const setWebhookId = jest.fn() | ||
|
||
openTestModal(spyDispatch, setWebhookId)(webhookId) | ||
expect(spyDispatch).toBeCalledWith(webhookSetOpenModal(MODAL_TYPE.TEST)) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.