-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
6 changed files
with
199 additions
and
51 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
x-pack/plugins/security_solution/public/cases/components/callout/callout.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,70 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
|
||
import { CallOut } from './callout'; | ||
import { ErrorMessage } from './types'; | ||
|
||
describe('Callout', () => { | ||
const defaultProps = { | ||
id: 'md5-hex', | ||
type: 'primary' as NonNullable<ErrorMessage['errorType']>, | ||
title: 'a tittle', | ||
messages: [ | ||
{ | ||
id: 'generic-error', | ||
title: 'message-one', | ||
description: <p>{'error'}</p>, | ||
}, | ||
], | ||
showCallOut: true, | ||
handleDismissCallout: jest.fn(), | ||
}; | ||
|
||
it('It renders the callout', () => { | ||
const wrapper = mount(<CallOut {...defaultProps} />); | ||
expect(wrapper.find(`[data-test-subj="case-callout-md5-hex"]`).exists()).toBeTruthy(); | ||
expect(wrapper.find(`[data-test-subj="callout-messages-md5-hex"]`).exists()).toBeTruthy(); | ||
expect(wrapper.find(`[data-test-subj="callout-dismiss-md5-hex"]`).exists()).toBeTruthy(); | ||
}); | ||
|
||
it('hides the callout', () => { | ||
const wrapper = mount(<CallOut {...defaultProps} showCallOut={false} />); | ||
expect(wrapper.find(`[data-test-subj="case-callout-md5-hex"]`).exists()).toBeFalsy(); | ||
}); | ||
|
||
it('does not shows any messages when the list is empty', () => { | ||
const wrapper = mount(<CallOut {...defaultProps} messages={[]} />); | ||
expect(wrapper.find(`[data-test-subj="callout-messages-md5-hex"]`).exists()).toBeFalsy(); | ||
}); | ||
|
||
it('transform the button color correctly', () => { | ||
let wrapper = mount(<CallOut {...defaultProps} />); | ||
expect(wrapper.find(`[data-test-subj="callout-dismiss-md5-hex"]`).first().prop('color')).toBe( | ||
'primary' | ||
); | ||
|
||
wrapper = mount(<CallOut {...defaultProps} type={'success'} />); | ||
expect(wrapper.find(`[data-test-subj="callout-dismiss-md5-hex"]`).first().prop('color')).toBe( | ||
'secondary' | ||
); | ||
|
||
wrapper = mount(<CallOut {...defaultProps} type={'danger'} />); | ||
expect(wrapper.find(`[data-test-subj="callout-dismiss-md5-hex"]`).first().prop('color')).toBe( | ||
'danger' | ||
); | ||
}); | ||
|
||
it('dismiss the button correctly', () => { | ||
const wrapper = mount(<CallOut {...defaultProps} messages={[]} />); | ||
expect(wrapper.find(`[data-test-subj="callout-dismiss-md5-hex"]`).exists()).toBeTruthy(); | ||
wrapper.find(`button[data-test-subj="callout-dismiss-md5-hex"]`).simulate('click'); | ||
wrapper.update(); | ||
expect(defaultProps.handleDismissCallout).toHaveBeenCalledWith('md5-hex'); | ||
}); | ||
}); |
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
28 changes: 28 additions & 0 deletions
28
x-pack/plugins/security_solution/public/cases/components/callout/helpers.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,28 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import md5 from 'md5'; | ||
import { createCalloutId } from './helpers'; | ||
|
||
describe('createCalloutId', () => { | ||
it('creates id correctly with one id', () => { | ||
const digest = md5('one'); | ||
const id = createCalloutId(['one']); | ||
expect(id).toBe(digest); | ||
}); | ||
|
||
it('creates id correctly with multiples ids', () => { | ||
const digest = md5('one|two|three'); | ||
const id = createCalloutId(['one', 'two', 'three']); | ||
expect(id).toBe(digest); | ||
}); | ||
|
||
it('creates id correctly with multiples ids and delimiter', () => { | ||
const digest = md5('one,two,three'); | ||
const id = createCalloutId(['one', 'two', 'three'], ','); | ||
expect(id).toBe(digest); | ||
}); | ||
}); |
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
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
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