Fix broken filtering on metric visualizations. (#38029) (#38143)

This commit is contained in:
Luke Elmers 2019-06-05 16:09:33 -06:00 committed by GitHub
parent c1a549a904
commit 565dfd455a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 78 additions and 1 deletions

View file

@ -43,4 +43,41 @@ describe('MetricVisValue', () => {
expect(component.find('EuiKeyboardAccessible').exists()).toBe(false);
});
it('should add -isfilterable class if onFilter is provided', () => {
const onFilter = jest.fn();
const component = shallow(
<MetricVisValue
fontSize={12}
metric={{ label: 'Foo', value: 'foo' }}
onFilter={onFilter}
/>
);
component.simulate('click');
expect(component.find('.mtrVis__container-isfilterable')).toHaveLength(1);
});
it('should not add -isfilterable class if onFilter is not provided', () => {
const component = shallow(
<MetricVisValue
fontSize={12}
metric={{ label: 'Foo', value: 'foo' }}
onFilter={null}
/>
);
component.simulate('click');
expect(component.find('.mtrVis__container-isfilterable')).toHaveLength(0);
});
it('should call onFilter callback if provided', () => {
const onFilter = jest.fn();
const component = shallow(
<MetricVisValue
fontSize={12}
metric={{ label: 'Foo', value: 'foo' }}
onFilter={onFilter}
/>
);
component.find('.mtrVis__container-isfilterable').simulate('click');
expect(onFilter).toHaveBeenCalledWith({ label: 'Foo', value: 'foo' });
});
});

View file

@ -161,7 +161,7 @@ export class MetricVisComponent extends Component {
key={index}
metric={metric}
fontSize={this.props.visParams.metric.style.fontSize}
onFilter={metric.filterKey && metric.bucketAgg ? this._filterBucket : null}
onFilter={this.props.visParams.dimensions.bucket ? this._filterBucket : null}
showLabel={this.props.visParams.metric.labels.show}
/>
);

View file

@ -22,6 +22,7 @@ import expect from '@kbn/expect';
export default function ({ getService, getPageObjects }) {
const log = getService('log');
const retry = getService('retry');
const filterBar = getService('filterBar');
const inspector = getService('inspector');
const PageObjects = getPageObjects(['common', 'visualize', 'timePicker']);
@ -170,5 +171,37 @@ export default function ({ getService, getPageObjects }) {
});
});
describe('with filters', function () {
it('should prevent filtering without buckets', async function () {
let filterCount = 0;
await retry.try(async function tryingForTime() {
// click first metric bucket
await PageObjects.visualize.clickMetricByIndex(0);
filterCount = await filterBar.getFilterCount();
});
expect(filterCount).to.equal(0);
});
it('should allow filtering with buckets', async function () {
await PageObjects.visualize.clickMetricEditor();
log.debug('Bucket = Split Group');
await PageObjects.visualize.clickBucket('Split Group');
log.debug('Aggregation = Terms');
await PageObjects.visualize.selectAggregation('Terms');
log.debug('Field = machine.os.raw');
await PageObjects.visualize.selectField('machine.os.raw');
await PageObjects.visualize.clickGo();
let filterCount = 0;
await retry.try(async function tryingForTime() {
// click first metric bucket
await PageObjects.visualize.clickMetricByIndex(0);
filterCount = await filterBar.getFilterCount();
});
await filterBar.removeAllFilters();
expect(filterCount).to.equal(1);
});
});
});
}

View file

@ -401,6 +401,13 @@ export function VisualizePageProvider({ getService, getPageObjects, updateBaseli
await find.clickByCssSelector('button[data-test-subj="toggleEditor"]');
}
async clickMetricByIndex(index) {
log.debug(`clickMetricByIndex(${index})`);
const metrics = await find.allByCssSelector('[data-test-subj="visualizationLoader"] .mtrVis .mtrVis__container');
expect(metrics.length).greaterThan(index);
await metrics[index].click();
}
async clickNewSearch(indexPattern = this.index.LOGSTASH_TIME_BASED) {
await testSubjects.click(`savedObjectTitle${indexPattern.split(' ').join('-')}`);
await PageObjects.header.waitUntilLoadingHasFinished();