/* * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ import { fireEvent, render } from '@testing-library/react'; import { configure } from 'enzyme'; import Adapter from 'enzyme-adapter-react-16'; import React from 'react'; import { mockEditorProps } from '../../../test/mocks/mockData'; import { GanttChartEditor } from '../gantt_chart_editor'; describe(' spec', () => { configure({ adapter: new Adapter() }); it('renders the component', () => { const setValue = jest.fn(); const utils = render(); expect(utils.container.firstChild).toMatchSnapshot(); }); it('changes label field', () => { const setValue = jest.fn(); const props = mockEditorProps(setValue); props.stateParams.labelField = ''; const utils = render(); utils.getByTestId('gantt-chart-editor-label-field').click(); utils.getByText('test-field-1').click(); expect(setValue).toBeCalledWith('labelField', 'test-field-1'); }); it('changes start time field', () => { const setValue = jest.fn(); const utils = render(); utils.getByTestId('gantt-chart-editor-start-time-field').click(); utils.getByText('test-field-2').click(); expect(setValue).toBeCalledWith('startTimeField', 'test-field-2'); }); it('changes duration field', () => { const setValue = jest.fn(); const utils = render(); utils.getByTestId('gantt-chart-editor-duration-field').click(); utils.getByText('test-field-3').click(); expect(setValue).toBeCalledWith('durationField', 'test-field-3'); }); it('changes size field', () => { const setValue = jest.fn(); const utils = render(); const field = utils.getByTestId('gantt-chart-editor-size-field'); fireEvent.change(field, { target: { value: 3 } }); expect(setValue).toBeCalledWith('size', 3); }); });