2020-04-02 06:34:16 -05:00
|
|
|
import React from 'react';
|
|
|
|
import { noop } from 'lodash';
|
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import { SecondaryActions } from './SecondaryActions';
|
|
|
|
|
|
|
|
const addQueryRowButtonSelector = '[aria-label="Add row button"]';
|
|
|
|
const richHistoryButtonSelector = '[aria-label="Rich history button"]';
|
2020-08-06 10:22:54 -05:00
|
|
|
const queryInspectorButtonSelector = '[aria-label="Query inspector button"]';
|
2020-04-02 06:34:16 -05:00
|
|
|
|
|
|
|
describe('SecondaryActions', () => {
|
|
|
|
it('should render component two buttons', () => {
|
2020-08-06 10:22:54 -05:00
|
|
|
const wrapper = shallow(
|
|
|
|
<SecondaryActions
|
|
|
|
onClickAddQueryRowButton={noop}
|
|
|
|
onClickRichHistoryButton={noop}
|
|
|
|
onClickQueryInspectorButton={noop}
|
|
|
|
/>
|
|
|
|
);
|
2020-04-02 06:34:16 -05:00
|
|
|
expect(wrapper.find(addQueryRowButtonSelector)).toHaveLength(1);
|
|
|
|
expect(wrapper.find(richHistoryButtonSelector)).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render add row button if addQueryRowButtonHidden=true', () => {
|
|
|
|
const wrapper = shallow(
|
|
|
|
<SecondaryActions
|
|
|
|
addQueryRowButtonHidden={true}
|
|
|
|
onClickAddQueryRowButton={noop}
|
|
|
|
onClickRichHistoryButton={noop}
|
2020-08-06 10:22:54 -05:00
|
|
|
onClickQueryInspectorButton={noop}
|
2020-04-02 06:34:16 -05:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
expect(wrapper.find(addQueryRowButtonSelector)).toHaveLength(0);
|
|
|
|
expect(wrapper.find(richHistoryButtonSelector)).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should disable add row button if addQueryRowButtonDisabled=true', () => {
|
|
|
|
const wrapper = shallow(
|
|
|
|
<SecondaryActions
|
|
|
|
addQueryRowButtonDisabled={true}
|
|
|
|
onClickAddQueryRowButton={noop}
|
|
|
|
onClickRichHistoryButton={noop}
|
2020-08-06 10:22:54 -05:00
|
|
|
onClickQueryInspectorButton={noop}
|
2020-04-02 06:34:16 -05:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
expect(wrapper.find(addQueryRowButtonSelector).props().disabled).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should map click handlers correctly', () => {
|
|
|
|
const onClickAddRow = jest.fn();
|
|
|
|
const onClickHistory = jest.fn();
|
2020-08-06 10:22:54 -05:00
|
|
|
const onClickQueryInspector = jest.fn();
|
2020-04-02 06:34:16 -05:00
|
|
|
const wrapper = shallow(
|
2020-08-06 10:22:54 -05:00
|
|
|
<SecondaryActions
|
|
|
|
onClickAddQueryRowButton={onClickAddRow}
|
|
|
|
onClickRichHistoryButton={onClickHistory}
|
|
|
|
onClickQueryInspectorButton={onClickQueryInspector}
|
|
|
|
/>
|
2020-04-02 06:34:16 -05:00
|
|
|
);
|
2020-08-06 10:22:54 -05:00
|
|
|
|
2020-04-02 06:34:16 -05:00
|
|
|
wrapper.find(addQueryRowButtonSelector).simulate('click');
|
|
|
|
expect(onClickAddRow).toBeCalled();
|
|
|
|
|
|
|
|
wrapper.find(richHistoryButtonSelector).simulate('click');
|
|
|
|
expect(onClickHistory).toBeCalled();
|
2020-08-06 10:22:54 -05:00
|
|
|
|
|
|
|
wrapper.find(queryInspectorButtonSelector).simulate('click');
|
|
|
|
expect(onClickQueryInspector).toBeCalled();
|
2020-04-02 06:34:16 -05:00
|
|
|
});
|
|
|
|
});
|