test: FilterBoxItemControl (#13753)

* Tests for FilterBoxItemControl

* factory for props

* fix lint
This commit is contained in:
Bruno Motta
2021-04-05 15:00:20 -03:00
committed by GitHub
parent 555d7bbb35
commit 7e394e556a
2 changed files with 67 additions and 6 deletions

View File

@@ -0,0 +1,61 @@
/**
* 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 { render, screen } from 'spec/helpers/testing-library';
import userEvent from '@testing-library/user-event';
import FilterBoxItemControl from '.';
const createProps = () => ({
datasource: {
columns: [],
metrics: [],
},
asc: true,
clearable: true,
multiple: true,
column: 'developer_type',
label: 'Developer Type',
metric: undefined,
searchAllOptions: false,
defaultValue: undefined,
onChange: jest.fn(),
});
test('Shoud render', () => {
const props = createProps();
render(<FilterBoxItemControl {...props} />);
expect(screen.getByTestId('FilterBoxItemControl')).toBeInTheDocument();
expect(screen.getByRole('button')).toBeInTheDocument();
});
test('Shoud open modal', () => {
const props = createProps();
render(<FilterBoxItemControl {...props} />);
userEvent.click(screen.getByRole('button'));
expect(screen.getByText('Filter configuration')).toBeInTheDocument();
expect(screen.getByText('Column')).toBeInTheDocument();
expect(screen.getByText('Label')).toBeInTheDocument();
expect(screen.getByText('Default')).toBeInTheDocument();
expect(screen.getByText('Sort metric')).toBeInTheDocument();
expect(screen.getByText('Sort ascending')).toBeInTheDocument();
expect(screen.getByText('Allow multiple selections')).toBeInTheDocument();
expect(screen.getByText('Search all filter options')).toBeInTheDocument();
expect(screen.getByText('Required')).toBeInTheDocument();
});

View File

@@ -22,11 +22,11 @@ import { t } from '@superset-ui/core';
import { InfoTooltipWithTrigger } from '@superset-ui/chart-controls';
import Popover from 'src/components/Popover';
import FormRow from '../../../components/FormRow';
import SelectControl from './SelectControl';
import CheckboxControl from './CheckboxControl';
import TextControl from './TextControl';
import { FILTER_CONFIG_ATTRIBUTES } from '../../constants';
import FormRow from 'src/components/FormRow';
import SelectControl from 'src/explore/components/controls/SelectControl';
import CheckboxControl from 'src/explore/components/controls/CheckboxControl';
import TextControl from 'src/explore/components/controls/TextControl';
import { FILTER_CONFIG_ATTRIBUTES } from 'src/explore/constants';
const INTEGRAL_TYPES = new Set([
'TINYINT',
@@ -272,7 +272,7 @@ export default class FilterBoxItemControl extends React.Component {
render() {
return (
<span>
<span data-test="FilterBoxItemControl">
{this.textSummary()}{' '}
<Popover
trigger="click"