From fe1dc0ac52060e123c182c6bf59d839c0057ff96 Mon Sep 17 00:00:00 2001 From: darth-coder00 <86726556+darth-coder00@users.noreply.github.com> Date: Tue, 22 Mar 2022 00:16:08 +0530 Subject: [PATCH] Fix #3530: Tags container is skipping tags with "Tier" in name (#3558) --- .../tags-container/tags-container.test.tsx | 105 +++++++++++++++++- .../tags-container/tags-container.tsx | 4 +- 2 files changed, 101 insertions(+), 8 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/src/components/tags-container/tags-container.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/tags-container/tags-container.test.tsx index 1e0e75cf072..61ad6582928 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/tags-container/tags-container.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/tags-container/tags-container.test.tsx @@ -11,7 +11,13 @@ * limitations under the License. */ -import { getByTestId, render } from '@testing-library/react'; +import { + fireEvent, + getAllByTestId, + getByTestId, + queryByTestId, + render, +} from '@testing-library/react'; import React from 'react'; import TagsContainer from './tags-container'; @@ -20,13 +26,16 @@ const tagList = [ { fqn: 'tag 2', source: 'Tag' }, { fqn: 'tag 3', source: 'Glossary' }, ]; + +const tagListWithTier = [ + { fqn: 'Tier.Tier1', source: 'Tag' }, + { fqn: 'Data.Tier1Data', source: 'Tag' }, + { fqn: 'Tier.Tier2', source: 'Glossary' }, + { fqn: 'Count.Tier2Count', source: 'Glossary' }, +]; const onCancel = jest.fn(); const onSelectionChange = jest.fn(); -jest.mock('../dropdown/DropDownList', () => { - return jest.fn().mockReturnValue(

DropDownList

); -}); - jest.mock('../tags/tags', () => { return jest.fn().mockReturnValue(

tags

); }); @@ -47,7 +56,23 @@ describe('Test TagsContainer Component', () => { expect(TagContainer).toBeInTheDocument(); }); - it('should have two buttons', () => { + it('Should have one input', () => { + const { container } = render( + + ); + + const input = getByTestId(container, 'associatedTagName'); + + expect(input).toBeInTheDocument(); + }); + + it('Should have two buttons', () => { const { container } = render( { expect(buttons.childElementCount).toBe(2); }); + + it('Should suggest tags on typing', () => { + const { container } = render( + + ); + + const input = getByTestId(container, 'associatedTagName'); + + fireEvent.change(input, { target: { value: 'tag' } }); + + const tagSuggestions = getByTestId(container, 'dropdown-list'); + + expect(tagSuggestions).toBeInTheDocument(); + + const tagItems = getAllByTestId(tagSuggestions, 'list-item'); + + expect(tagItems).toHaveLength(3); + }); + + it('Should only exclude Tier tags from suggestions', () => { + const { container } = render( + + ); + + const input = getByTestId(container, 'associatedTagName'); + + fireEvent.change(input, { target: { value: 'tier' } }); + + const tagSuggestions = getByTestId(container, 'dropdown-list'); + + expect(tagSuggestions).toBeInTheDocument(); + + const tagItems = getAllByTestId(tagSuggestions, 'list-item'); + + expect(tagItems).toHaveLength(2); + }); + + it('Should not suggest tags on typing unmatched tag name', () => { + const { container } = render( + + ); + + const input = getByTestId(container, 'associatedTagName'); + + fireEvent.change(input, { target: { value: 'qwerty' } }); + + const tagSuggestions = queryByTestId(container, 'dropdown-list'); + + expect(tagSuggestions).not.toBeInTheDocument(); + }); }); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/tags-container/tags-container.tsx b/openmetadata-ui/src/main/resources/ui/src/components/tags-container/tags-container.tsx index 1a3a9e9b63a..ca1db055905 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/tags-container/tags-container.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/tags-container/tags-container.tsx @@ -11,6 +11,7 @@ * limitations under the License. */ +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import classNames from 'classnames'; import { isNull } from 'lodash'; import { EntityTags, TagOption } from 'Models'; @@ -20,7 +21,6 @@ import { Button } from '../buttons/Button/Button'; import DropDownList from '../dropdown/DropDownList'; import Tags from '../tags/tags'; import { TagsContainerProps } from './tags-container.interface'; -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; // const INPUT_COLLAPED = '1px'; // const INPUT_EXPANDED = '150px'; @@ -75,7 +75,7 @@ const TagsContainer: FunctionComponent = ({ .filter((tag) => { return !tags.some((selectedTag) => selectedTag.tagFQN === tag.fqn); }) - .filter((tag) => !tag.fqn?.includes('Tier')) + .filter((tag) => !tag.fqn?.startsWith('Tier.Tier')) // To filter out Tier tags .map((tag) => { return { name: tag.fqn,