2022-05-05 08:55:59 -05:00
|
|
|
import { render, screen } from '@testing-library/react';
|
|
|
|
import userEvent from '@testing-library/user-event';
|
2022-04-22 08:33:13 -05:00
|
|
|
import { noop } from 'lodash';
|
|
|
|
import React from 'react';
|
|
|
|
|
2020-04-02 06:34:16 -05:00
|
|
|
import { SecondaryActions } from './SecondaryActions';
|
|
|
|
|
|
|
|
describe('SecondaryActions', () => {
|
2022-05-05 08:55:59 -05:00
|
|
|
it('should render component with three buttons', () => {
|
|
|
|
render(
|
2020-08-06 10:22:54 -05:00
|
|
|
<SecondaryActions
|
|
|
|
onClickAddQueryRowButton={noop}
|
|
|
|
onClickRichHistoryButton={noop}
|
|
|
|
onClickQueryInspectorButton={noop}
|
|
|
|
/>
|
|
|
|
);
|
2022-05-05 08:55:59 -05:00
|
|
|
|
|
|
|
expect(screen.getByRole('button', { name: /Add row button/i })).toBeInTheDocument();
|
|
|
|
expect(screen.getByRole('button', { name: /Rich history button/i })).toBeInTheDocument();
|
|
|
|
expect(screen.getByRole('button', { name: /Query inspector button/i })).toBeInTheDocument();
|
2020-04-02 06:34:16 -05:00
|
|
|
});
|
|
|
|
|
2022-06-02 08:51:11 -05:00
|
|
|
it('should not render hidden elements', () => {
|
2022-05-05 08:55:59 -05:00
|
|
|
render(
|
2020-04-02 06:34:16 -05:00
|
|
|
<SecondaryActions
|
|
|
|
addQueryRowButtonHidden={true}
|
2022-06-02 08:51:11 -05:00
|
|
|
richHistoryRowButtonHidden={true}
|
2020-04-02 06:34:16 -05:00
|
|
|
onClickAddQueryRowButton={noop}
|
|
|
|
onClickRichHistoryButton={noop}
|
2020-08-06 10:22:54 -05:00
|
|
|
onClickQueryInspectorButton={noop}
|
2020-04-02 06:34:16 -05:00
|
|
|
/>
|
|
|
|
);
|
2022-05-05 08:55:59 -05:00
|
|
|
|
|
|
|
expect(screen.queryByRole('button', { name: /Add row button/i })).not.toBeInTheDocument();
|
2022-06-02 08:51:11 -05:00
|
|
|
expect(screen.queryByRole('button', { name: /Rich history button/i })).not.toBeInTheDocument();
|
2022-05-05 08:55:59 -05:00
|
|
|
expect(screen.getByRole('button', { name: /Query inspector button/i })).toBeInTheDocument();
|
2020-04-02 06:34:16 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should disable add row button if addQueryRowButtonDisabled=true', () => {
|
2022-05-05 08:55:59 -05:00
|
|
|
render(
|
2020-04-02 06:34:16 -05:00
|
|
|
<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
|
|
|
/>
|
|
|
|
);
|
2022-05-05 08:55:59 -05:00
|
|
|
|
|
|
|
expect(screen.getByRole('button', { name: /Add row button/i })).toBeDisabled();
|
|
|
|
expect(screen.getByRole('button', { name: /Rich history button/i })).toBeInTheDocument();
|
|
|
|
expect(screen.getByRole('button', { name: /Query inspector button/i })).toBeInTheDocument();
|
2020-04-02 06:34:16 -05:00
|
|
|
});
|
|
|
|
|
2022-05-05 08:55:59 -05:00
|
|
|
it('should map click handlers correctly', async () => {
|
|
|
|
const user = userEvent.setup();
|
|
|
|
|
2020-04-02 06:34:16 -05:00
|
|
|
const onClickAddRow = jest.fn();
|
|
|
|
const onClickHistory = jest.fn();
|
2020-08-06 10:22:54 -05:00
|
|
|
const onClickQueryInspector = jest.fn();
|
2022-05-05 08:55:59 -05:00
|
|
|
|
|
|
|
render(
|
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
|
|
|
|
2022-05-05 08:55:59 -05:00
|
|
|
await user.click(screen.getByRole('button', { name: /Add row button/i }));
|
|
|
|
expect(onClickAddRow).toBeCalledTimes(1);
|
2020-04-02 06:34:16 -05:00
|
|
|
|
2022-05-05 08:55:59 -05:00
|
|
|
await user.click(screen.getByRole('button', { name: /Rich history button/i }));
|
|
|
|
expect(onClickHistory).toBeCalledTimes(1);
|
2020-08-06 10:22:54 -05:00
|
|
|
|
2022-05-05 08:55:59 -05:00
|
|
|
await user.click(screen.getByRole('button', { name: /Query inspector button/i }));
|
|
|
|
expect(onClickQueryInspector).toBeCalledTimes(1);
|
2020-04-02 06:34:16 -05:00
|
|
|
});
|
|
|
|
});
|