Skip to content

Commit

Permalink
Addresses comments
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina committed Dec 6, 2022
1 parent c762fdc commit 2962bde
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ const ColumnSelectPopover = ({
{t('Close')}
</Button>
<Button
disabled={stateIsValid && !hasUnsavedChanges}
disabled={!stateIsValid || !hasUnsavedChanges}
buttonStyle="primary"
buttonSize="small"
onClick={onSave}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe('AdhocFilterEditPopover', () => {
wrapper
.instance()
.onAdhocFilterChange(simpleAdhocFilter.duplicateWith({ operator: null }));
expect(wrapper.find(Button).find({ disabled: false })).toExist();
expect(wrapper.find(Button).find({ disabled: true })).toExist();
wrapper.instance().onAdhocFilterChange(sqlAdhocFilter);
expect(wrapper.find(Button).find({ disabled: true })).not.toExist();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ export default class AdhocFilterEditPopover extends React.Component {
<Button
data-test="adhoc-filter-edit-popover-save-button"
disabled={
(stateIsValid || !this.state.isSimpleTabValid) &&
!stateIsValid ||
!this.state.isSimpleTabValid ||
!hasUnsavedChanges
}
buttonStyle="primary"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,18 @@ describe('AdhocMetricEditPopover', () => {
const { wrapper } = setup();
expect(wrapper.find(Button).find({ disabled: false })).not.toExist();
wrapper.instance().onColumnChange(null);
expect(wrapper.find(Button).find({ disabled: true })).not.toExist();
expect(wrapper.find(Button).find({ disabled: true })).toExist();
wrapper.instance().onColumnChange(columns[0].column_name);
expect(wrapper.find(Button).find({ disabled: true })).not.toExist();
wrapper.instance().onAggregateChange(null);
expect(wrapper.find(Button).find({ disabled: true })).not.toExist();
expect(wrapper.find(Button).find({ disabled: true })).toExist();
});

it('highlights save if changes are present', () => {
const { wrapper } = setup();
expect(wrapper.find(Button).find({ disabled: true })).toExist();
wrapper.instance().onColumnChange(columns[1].column_name);
expect(wrapper.find(Button).find({ buttonStyle: 'primary' })).toExist();
expect(wrapper.find(Button).find({ disabled: true })).not.toExist();
});

it('will initiate a drag when clicked', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
import userEvent from '@testing-library/user-event';
import React from 'react';
import { render, screen } from 'spec/helpers/testing-library';
import { render, screen, waitFor, within } from 'spec/helpers/testing-library';
import AdhocMetric from 'src/explore/components/controls/MetricControl/AdhocMetric';
import AdhocMetricEditPopover from '.';

Expand All @@ -35,10 +35,15 @@ const createProps = () => ({
},
savedMetricsOptions: [
{
id: 65,
id: 64,
metric_name: 'count',
expression: 'COUNT(*)',
},
{
id: 65,
metric_name: 'sum',
expression: 'sum(num)',
},
],
adhocMetric: new AdhocMetric({ isNew: true }),
datasource: {
Expand Down Expand Up @@ -118,18 +123,20 @@ test('Clicking on "Close" should call onClose', () => {
expect(props.onClose).toBeCalledTimes(1);
});

test('Clicking on "Save" should call onChange and onClose', () => {
const props = {
...createProps(),
savedMetric: {},
};
test('Clicking on "Save" should call onChange and onClose', async () => {
const props = createProps();
render(<AdhocMetricEditPopover {...props} />);
expect(props.onChange).toBeCalledTimes(0);
expect(props.onClose).toBeCalledTimes(0);
const element = screen.getByRole('combobox', {
name: 'Select saved metrics',
});
expect(element).toBeVisible();
userEvent.click(
screen.getByRole('combobox', {
name: 'Select saved metrics',
}),
);
const sumOption = await waitFor(() =>
within(document.querySelector('.rc-virtual-list')!).getByText('sum'),
);
userEvent.click(sumOption);
userEvent.click(screen.getByRole('button', { name: 'Save' }));
expect(props.onChange).toBeCalledTimes(1);
expect(props.onClose).toBeCalledTimes(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ export default class AdhocMetricEditPopover extends React.PureComponent {
{t('Close')}
</Button>
<Button
disabled={stateIsValid && !hasUnsavedChanges}
disabled={!stateIsValid || !hasUnsavedChanges}
buttonStyle="primary"
buttonSize="small"
data-test="AdhocMetricEdit#save"
Expand Down

0 comments on commit 2962bde

Please sign in to comment.