-
Notifications
You must be signed in to change notification settings - Fork 8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
86 additions
and
0 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
x-pack/plugins/cases/public/client/attachment_framework/registry.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,86 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { AttachmentTypeRegistry } from './registry'; | ||
|
||
export const ExpressionComponent: React.FunctionComponent = () => { | ||
return null; | ||
}; | ||
|
||
const getItem = (id: string = 'test') => { | ||
return { id }; | ||
}; | ||
|
||
describe('AttachmentTypeRegistry', () => { | ||
beforeEach(() => jest.resetAllMocks()); | ||
|
||
describe('has()', () => { | ||
it('returns false for unregistered items', () => { | ||
const registry = new AttachmentTypeRegistry(); | ||
|
||
expect(registry.has('test')).toEqual(false); | ||
}); | ||
|
||
it('returns true after registering an item', () => { | ||
const registry = new AttachmentTypeRegistry(); | ||
registry.register(getItem()); | ||
|
||
expect(registry.has('test')); | ||
}); | ||
}); | ||
|
||
describe('register()', () => { | ||
it('able to register items', () => { | ||
const registry = new AttachmentTypeRegistry(); | ||
registry.register(getItem()); | ||
|
||
expect(registry.has('test')).toEqual(true); | ||
}); | ||
|
||
it('throws error if item is already registered', () => { | ||
const registry = new AttachmentTypeRegistry(); | ||
registry.register(getItem('test')); | ||
|
||
expect(() => registry.register(getItem('test'))).toThrowErrorMatchingInlineSnapshot( | ||
`"Attachment type \\"test\\" is already registered."` | ||
); | ||
}); | ||
}); | ||
|
||
describe('get()', () => { | ||
it('returns item', () => { | ||
const registry = new AttachmentTypeRegistry(); | ||
registry.register(getItem()); | ||
const actionType = registry.get('test'); | ||
|
||
expect(actionType).toEqual({ | ||
id: 'test', | ||
}); | ||
}); | ||
|
||
it(`throw error when action type doesn't exist`, () => { | ||
const registry = new AttachmentTypeRegistry(); | ||
expect(() => registry.get('not-exist-item')).toThrowErrorMatchingInlineSnapshot( | ||
`"Attachment type \\"not-exist-item\\" is not registered."` | ||
); | ||
}); | ||
}); | ||
|
||
describe('list()', () => { | ||
it('returns list of items', () => { | ||
const actionTypeRegistry = new AttachmentTypeRegistry(); | ||
actionTypeRegistry.register(getItem()); | ||
const actionTypes = actionTypeRegistry.list(); | ||
|
||
expect(actionTypes).toEqual([ | ||
{ | ||
id: 'test', | ||
}, | ||
]); | ||
}); | ||
}); | ||
}); |