[Enterprise Search] Migrate shared ApiKey component (#82511)
This commit is contained in:
parent
64f50f8ff7
commit
5a9fc25dc8
3 changed files with 67 additions and 0 deletions
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* 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 { shallow } from 'enzyme';
|
||||
|
||||
import { EuiCodeBlock, EuiFormLabel } from '@elastic/eui';
|
||||
|
||||
import { ApiKey } from './';
|
||||
|
||||
const key = '123abc';
|
||||
const label = 'foo';
|
||||
|
||||
describe('ApiKey', () => {
|
||||
it('renders', () => {
|
||||
const wrapper = shallow(<ApiKey apiKey={key} />);
|
||||
|
||||
expect(wrapper.find(EuiCodeBlock)).toHaveLength(1);
|
||||
expect(wrapper.find(EuiFormLabel)).toHaveLength(0);
|
||||
expect(wrapper.find(EuiCodeBlock).prop('children')).toEqual(key);
|
||||
});
|
||||
|
||||
it('renders label', () => {
|
||||
const wrapper = shallow(<ApiKey apiKey={key} label={label} />);
|
||||
|
||||
expect(wrapper.find(EuiFormLabel)).toHaveLength(1);
|
||||
expect(wrapper.find(EuiFormLabel).prop('children')).toEqual(label);
|
||||
});
|
||||
});
|
|
@ -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 React from 'react';
|
||||
|
||||
import { EuiCodeBlock, EuiFormLabel, EuiSpacer } from '@elastic/eui';
|
||||
|
||||
interface IApiKeyProps {
|
||||
apiKey: string;
|
||||
label?: string;
|
||||
}
|
||||
|
||||
export const ApiKey: React.FC<IApiKeyProps> = ({ apiKey, label }) => (
|
||||
<>
|
||||
{label && (
|
||||
<>
|
||||
<EuiFormLabel>{label}</EuiFormLabel>
|
||||
<EuiSpacer size="xs" />
|
||||
</>
|
||||
)}
|
||||
<EuiCodeBlock language="bash" fontSize="m" paddingSize="m" color="dark" isCopyable>
|
||||
{apiKey}
|
||||
</EuiCodeBlock>
|
||||
</>
|
||||
);
|
|
@ -0,0 +1,7 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export { ApiKey } from './api_key';
|
Loading…
Reference in a new issue