test: Adds tests to the OptionControls component (#13729)

This commit is contained in:
Michael S. Molina
2021-03-31 22:07:22 -03:00
committed by GitHub
parent ec5d2f5f32
commit 6fd62e3f7e
12 changed files with 156 additions and 82 deletions

View File

@@ -26,7 +26,7 @@ import AdhocFilter, {
EXPRESSION_TYPES,
CLAUSES,
} from 'src/explore/components/controls/FilterControl/AdhocFilter';
import { LabelsContainer } from 'src/explore/components/OptionControls';
import { LabelsContainer } from 'src/explore/components/controls/OptionControls';
import { AGGREGATES, OPERATORS } from 'src/explore/constants';
import AdhocFilterControl from 'src/explore/components/controls/FilterControl/AdhocFilterControl';
import AdhocMetric from 'src/explore/components/controls/MetricControl/AdhocMetric';

View File

@@ -22,7 +22,7 @@ import sinon from 'sinon';
import { shallow } from 'enzyme';
import { AGGREGATES } from 'src/explore/constants';
import { LabelsContainer } from 'src/explore/components/OptionControls';
import { LabelsContainer } from 'src/explore/components/controls/OptionControls';
import { supersetTheme } from '@superset-ui/core';
import MetricsControl from 'src/explore/components/controls/MetricControl/MetricsControl';
import AdhocMetric, {

View File

@@ -1,69 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import React from 'react';
import { ThemeProvider, supersetTheme } from '@superset-ui/core';
import { DndProvider } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';
import { render, screen } from 'spec/helpers/testing-library';
import { OptionControlLabel } from 'src/explore/components/OptionControls';
import { noOp } from 'src/utils/common';
const setup = (overrides?: Record<string, any>) => {
const props = {
label: <span>Test label</span>,
onRemove: noOp,
onMoveLabel: noOp,
onDropLabel: noOp,
type: 'test',
index: 0,
...overrides,
};
return render(
<ThemeProvider theme={supersetTheme}>
<DndProvider backend={HTML5Backend}>
<OptionControlLabel {...props} />
</DndProvider>
</ThemeProvider>,
);
};
describe('OptionControls', () => {
it('should render', () => {
const { container } = setup();
expect(container).toBeVisible();
});
it('should display a label', () => {
setup();
expect(screen.getByText('Test label')).toBeTruthy();
});
it('should display a certification icon if saved metric is certified', () => {
const { container } = setup({
savedMetric: {
metric_name: 'test_metric',
is_certified: true,
},
});
screen.getByText('test_metric');
expect(screen.queryByText('Test label')).toBeFalsy();
expect(container.querySelector('.metric-option > svg')).toBeInTheDocument();
});
});