Skip to content

Commit

Permalink
support date_nanos type (#954)
Browse files Browse the repository at this point in the history
Signed-off-by: Hailong Cui <ihailong@amazon.com>
  • Loading branch information
Hailong-am authored Aug 1, 2024
1 parent 0153b94 commit ce4742b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import { FormikComboBox } from '../../../../components/FormControls';

const MonitorTimeField = ({ dataTypes }) => {
// Default empty option + options from index mappings mapped to ui select form
const dateFields = Array.from(dataTypes.date || []);
const dateFields = Array.from(dataTypes.date || []).concat(
Array.from(dataTypes.date_nanos || [])
);
const options = [].concat(dateFields).map((option) => ({ label: option }));
return (
<FormikComboBox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,40 @@ describe('MonitorTimeField', () => {
expect(render(component)).toMatchSnapshot();
});

test.skip('displays no options', () => {
test('displays no options', () => {
const wrapper = mount(
<Formik initialValues={{}} onSubmit={() => {}}>
<MonitorTimeField dataTypes={{}} />
</Formik>
);
// Default blank option
expect(wrapper.find('select').props().children[1].length).toBe(1);
expect(wrapper.find('EuiComboBox').props().options.length).toBe(0);
});

test.skip('displays options', () => {
test('displays options', () => {
const wrapper = mount(
<Formik initialValues={{}} onSubmit={() => {}}>
<MonitorTimeField dataTypes={{ date: ['date1', 'date2', 'date3'] }} />
</Formik>
);
// 3 options + default blank option
expect(wrapper.find('select').props().children[1].length).toBe(4);
// 3 options
expect(wrapper.find('EuiComboBox').props().options.length).toBe(3);
});

test('displays options includes date_nanos', () => {
const wrapper = mount(
<Formik initialValues={{}} onSubmit={() => {}}>
<MonitorTimeField
dataTypes={{ date: ['date1', 'date2', 'date3'], date_nanos: ['date_nanos1'] }}
/>
</Formik>
);
expect(wrapper).toMatchSnapshot();

// 4 options
expect(wrapper.find('EuiComboBox').props().options.length).toBe(4);
expect(wrapper.find('EuiComboBox').props().options).toEqual(
expect.arrayContaining([{ label: 'date_nanos1' }])
);
});
});

0 comments on commit ce4742b

Please sign in to comment.