diff --git a/superset-frontend/src/dashboard/components/FiltersBadge/FilterIndicator/FilterIndicator.test.tsx b/superset-frontend/src/dashboard/components/FiltersBadge/FilterIndicator/FilterIndicator.test.tsx new file mode 100644 index 00000000000..c93abaa9036 --- /dev/null +++ b/superset-frontend/src/dashboard/components/FiltersBadge/FilterIndicator/FilterIndicator.test.tsx @@ -0,0 +1,85 @@ +/** + * 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 userEvent from '@testing-library/user-event'; +import React from 'react'; +import { render, screen } from 'spec/helpers/testing-library'; +import { Indicator } from 'src/dashboard/components/FiltersBadge/selectors'; +import FilterIndicator from '.'; + +const createProps = () => ({ + indicator: { + column: 'product_category', + name: 'Vaccine Approach', + value: [] as any[], + path: [ + 'ROOT_ID', + 'TABS-wUKya7eQ0Z', + 'TAB-BCIJF4NvgQ', + 'ROW-xSeNAspgw', + 'CHART-eirDduqb1A', + ], + } as Indicator, + onClick: jest.fn(), +}); + +test('Should render', () => { + const props = createProps(); + render(); + + expect( + screen.getByRole('button', { name: 'search Vaccine Approach' }), + ).toBeInTheDocument(); + expect(screen.getByRole('img', { name: 'search' })).toBeInTheDocument(); +}); + +test('Should call "onClick"', () => { + const props = createProps(); + render(); + + expect(props.onClick).toBeCalledTimes(0); + userEvent.click( + screen.getByRole('button', { name: 'search Vaccine Approach' }), + ); + expect(props.onClick).toBeCalledTimes(1); +}); + +test('Should render "value"', () => { + const props = createProps(); + props.indicator.value = ['any', 'string']; + render(); + + expect( + screen.getByRole('button', { + name: 'search Vaccine Approach: any, string', + }), + ).toBeInTheDocument(); +}); + +test('Should render with default props', () => { + const props = createProps(); + delete props.indicator.path; + render(); + + expect( + screen.getByRole('button', { name: 'search Vaccine Approach' }), + ).toBeInTheDocument(); + userEvent.click( + screen.getByRole('button', { name: 'search Vaccine Approach' }), + ); +}); diff --git a/superset-frontend/src/dashboard/components/FiltersBadge/FilterIndicator.tsx b/superset-frontend/src/dashboard/components/FiltersBadge/FilterIndicator/index.tsx similarity index 83% rename from superset-frontend/src/dashboard/components/FiltersBadge/FilterIndicator.tsx rename to superset-frontend/src/dashboard/components/FiltersBadge/FilterIndicator/index.tsx index 6add0ab8429..f962a72e478 100644 --- a/superset-frontend/src/dashboard/components/FiltersBadge/FilterIndicator.tsx +++ b/superset-frontend/src/dashboard/components/FiltersBadge/FilterIndicator/index.tsx @@ -19,10 +19,14 @@ import { SearchOutlined } from '@ant-design/icons'; import React, { FC } from 'react'; -import { getFilterValueForDisplay } from '../nativeFilters/FilterBar/FilterSets/utils'; -import { FilterValue, Item, ItemIcon, Title } from './Styles'; - -import { Indicator } from './selectors'; +import { getFilterValueForDisplay } from 'src/dashboard/components/nativeFilters/FilterBar/FilterSets/utils'; +import { + FilterValue, + Item, + ItemIcon, + Title, +} from 'src/dashboard/components/FiltersBadge/Styles'; +import { Indicator } from 'src/dashboard/components/FiltersBadge/selectors'; export interface IndicatorProps { indicator: Indicator;