Allowing withVerification to remove all options if none are valid (#7652)

This commit is contained in:
michellethomas
2019-06-18 14:06:05 -07:00
committed by GitHub
parent f278faa8be
commit 5864ddc079
2 changed files with 14 additions and 4 deletions

View File

@@ -44,7 +44,7 @@ const defaultProps = {
const VALID_METRIC = { metric_name: 'sum__value', expression: 'SUM(energy_usage.value)' };
function setup(overrides) {
function setup(overrides, validMetric) {
const onChange = sinon.spy();
const props = {
onChange,
@@ -53,7 +53,7 @@ function setup(overrides) {
};
const VerifiedControl = withVerification(MetricsControl, 'metric_name', 'savedMetrics');
const wrapper = shallow(<VerifiedControl {...props} />);
fetchMock.mock('glob:*/valid_metrics*', `["${VALID_METRIC.metric_name}"]`);
fetchMock.mock('glob:*/valid_metrics*', validMetric || `["${VALID_METRIC.metric_name}"]`);
return { props, wrapper, onChange };
}
@@ -103,4 +103,14 @@ describe('VerifiedMetricsControl', () => {
fetchMock.reset();
}, 0);
});
it('Returns no verified options if none are valid', () => {
const { wrapper } = setup({}, []);
setTimeout(() => {
expect(fetchMock.calls(defaultProps.getEndpoint())).toHaveLength(1);
const child = wrapper.find(MetricsControl);
expect(child.props().savedMetrics).toEqual([]);
fetchMock.reset();
}, 0);
});
});