metadata-based-explorer1
Version:
Box UI Elements
37 lines (33 loc) • 1.38 kB
JavaScript
import * as React from 'react';
import { shallow } from 'enzyme';
import EditableKeywords from '../EditableKeywords';
describe('elements/content-sidebar/Skills/Keywords/EditableKeywords', () => {
test('should correctly render', () => {
const props = {
keywords: [{ text: 'foo' }, { text: 'bar' }],
onAdd: jest.fn(),
onDelete: jest.fn(),
onSave: jest.fn(),
onCancel: jest.fn(),
};
const wrapper = shallow(<EditableKeywords {...props} />);
expect(wrapper).toMatchSnapshot();
});
describe('onKeyDown()', () => {
test('should call onBlur when enter is pressed and is not in composition mode', () => {
const wrapper = shallow(<EditableKeywords />);
const instance = wrapper.instance();
instance.onBlur = jest.fn();
instance.onKeyDown({ key: 'Enter' });
expect(instance.onBlur).toBeCalled();
});
test('should not call onBlur when in composition mode', () => {
const wrapper = shallow(<EditableKeywords />);
const instance = wrapper.instance();
instance.setState({ isInCompositionMode: true });
instance.onBlur = jest.fn();
instance.onKeyDown({ key: 'Enter' });
expect(instance.onBlur).not.toBeCalled();
});
});
});