From d84e2c2a8dd3fde3364ad0f550a00622f166ad2c Mon Sep 17 00:00:00 2001 From: Sachin Chaurasiya Date: Sat, 23 Apr 2022 01:36:42 +0530 Subject: [PATCH] Fix: Glossary and Glossary term page issues. (#4381) * Fix: Glossary and Glossary term page issues. * Add unit test --- .../AddGlossary/AddGlossary.component.tsx | 11 +++++-- .../AddGlossary/AddGlossary.test.tsx | 27 +++++++++++++++++ .../AddGlossaryTerm.component.tsx | 11 +++++-- .../AddGlossaryTerm/AddGlossaryTerm.test.tsx | 29 +++++++++++++++++++ .../Glossary/GlossaryV1.component.tsx | 23 ++------------- 5 files changed, 76 insertions(+), 25 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/src/components/AddGlossary/AddGlossary.component.tsx b/openmetadata-ui/src/main/resources/ui/src/components/AddGlossary/AddGlossary.component.tsx index f9d9d4759e0..c782c369612 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/AddGlossary/AddGlossary.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/AddGlossary/AddGlossary.component.tsx @@ -48,6 +48,7 @@ const AddGlossary = ({ const [showErrorMsg, setShowErrorMsg] = useState<{ [key: string]: boolean }>({ name: false, invalidName: false, + description: false, }); const [name, setName] = useState(''); @@ -55,6 +56,10 @@ const AddGlossary = ({ const [showRevieweModal, setShowRevieweModal] = useState(false); const [reviewer, setReviewer] = useState>([]); + const getDescription = () => { + return markdownRef.current?.getEditorContent() || undefined; + }; + const onReviewerModalCancel = () => { setShowRevieweModal(false); }; @@ -99,6 +104,7 @@ const AddGlossary = ({ const errMsg = { name: !name.trim(), invalidName: UrlEntityCharRegEx.test(name.trim()), + description: !getDescription()?.trim(), }; setShowErrorMsg(errMsg); @@ -110,7 +116,7 @@ const AddGlossary = ({ const data: CreateGlossary = { name, displayName: name, - description: markdownRef.current?.getEditorContent() || undefined, + description: getDescription(), reviewers: reviewer.map((d) => ({ id: d.id, type: d.type })), owner: { id: getCurrentUserId(), @@ -210,7 +216,7 @@ const AddGlossary = ({ + {showErrorMsg.description && errorMsg('Description is required.')}
diff --git a/openmetadata-ui/src/main/resources/ui/src/components/AddGlossary/AddGlossary.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/AddGlossary/AddGlossary.test.tsx index 9a80d14247a..d8d2a3b61b0 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/AddGlossary/AddGlossary.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/AddGlossary/AddGlossary.test.tsx @@ -79,6 +79,9 @@ describe('Test AddGlossary component', () => { }); it('should be able to save', () => { + jest.spyOn(React, 'useRef').mockReturnValue({ + current: { getEditorContent: jest.fn().mockReturnValue('description') }, + }); const { container } = render(); const nameInput = getByTestId(container, 'name'); @@ -98,4 +101,28 @@ describe('Test AddGlossary component', () => { expect(mockOnSave).toBeCalled(); }); + + it('should not be able to save', () => { + jest.spyOn(React, 'useRef').mockReturnValue({ + current: { getEditorContent: jest.fn().mockReturnValue('') }, + }); + const { container } = render(); + + const nameInput = getByTestId(container, 'name'); + const saveButton = getByTestId(container, 'save-glossary'); + + expect(saveButton).toBeInTheDocument(); + + fireEvent.change(nameInput, { target: { value: 'Test Glossary' } }); + + fireEvent.click( + saveButton, + new MouseEvent('click', { + bubbles: true, + cancelable: true, + }) + ); + + expect(mockOnSave).not.toBeCalled(); + }); }); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/AddGlossaryTerm/AddGlossaryTerm.component.tsx b/openmetadata-ui/src/main/resources/ui/src/components/AddGlossaryTerm/AddGlossaryTerm.component.tsx index 2742da11d05..2e7d76be43c 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/AddGlossaryTerm/AddGlossaryTerm.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/AddGlossaryTerm/AddGlossaryTerm.component.tsx @@ -63,6 +63,7 @@ const AddGlossaryTerm = ({ name: false, invalidName: false, invalidReferences: false, + description: false, }); const [name, setName] = useState(''); @@ -82,6 +83,10 @@ const AddGlossaryTerm = ({ } }, [glossaryData]); + const getDescription = () => { + return markdownRef.current?.getEditorContent() || undefined; + }; + const onRelatedTermsModalCancel = () => { setShowRelatedTermsModal(false); }; @@ -187,6 +192,7 @@ const AddGlossaryTerm = ({ name: !name.trim(), invalidName: !isUrlFriendlyName(name.trim()), invalidReferences: !isValidReferences(refs), + description: !getDescription()?.trim(), }; setShowErrorMsg(errMsg); @@ -210,7 +216,7 @@ const AddGlossaryTerm = ({ const data: CreateGlossaryTerm = { name, displayName: name, - description: markdownRef.current?.getEditorContent() || undefined, + description: getDescription(), reviewers: reviewer.map((r) => ({ id: r.id, type: r.type, @@ -323,7 +329,7 @@ const AddGlossaryTerm = ({ + {showErrorMsg.description && errorMsg('Description is required.')} diff --git a/openmetadata-ui/src/main/resources/ui/src/components/AddGlossaryTerm/AddGlossaryTerm.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/AddGlossaryTerm/AddGlossaryTerm.test.tsx index 5e1dd867f17..07f5399f4ab 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/AddGlossaryTerm/AddGlossaryTerm.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/AddGlossaryTerm/AddGlossaryTerm.test.tsx @@ -87,6 +87,10 @@ describe('Test AddGlossaryTerm component', () => { }); it('should be able to save', () => { + jest.spyOn(React, 'useRef').mockReturnValue({ + current: { getEditorContent: jest.fn().mockReturnValue('description') }, + }); + const { container } = render(); const nameInput = getByTestId(container, 'name'); @@ -106,4 +110,29 @@ describe('Test AddGlossaryTerm component', () => { expect(mockOnSave).toBeCalled(); }); + + it('should not be able to save', () => { + jest.spyOn(React, 'useRef').mockReturnValue({ + current: { getEditorContent: jest.fn().mockReturnValue('') }, + }); + + const { container } = render(); + + const nameInput = getByTestId(container, 'name'); + const saveButton = getByTestId(container, 'save-glossary-term'); + + expect(saveButton).toBeInTheDocument(); + + fireEvent.change(nameInput, { target: { value: 'Test Glossary Term' } }); + + fireEvent.click( + saveButton, + new MouseEvent('click', { + bubbles: true, + cancelable: true, + }) + ); + + expect(mockOnSave).not.toBeCalled(); + }); }); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/Glossary/GlossaryV1.component.tsx b/openmetadata-ui/src/main/resources/ui/src/components/Glossary/GlossaryV1.component.tsx index b429920cbdc..d0281098cc1 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/Glossary/GlossaryV1.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/Glossary/GlossaryV1.component.tsx @@ -29,7 +29,6 @@ import { GlossaryTerm } from '../../generated/entity/data/glossaryTerm'; import { useAuth } from '../../hooks/authHooks'; import { ModifiedGlossaryData } from '../../pages/GlossaryPage/GlossaryPageV1.component'; import { generateTreeData, getActionsList } from '../../utils/GlossaryUtils'; -import { dropdownIcon as DropdownIcon } from '../../utils/svgconstant'; import { Button } from '../buttons/Button/Button'; import ErrorPlaceHolder from '../common/error-with-placeholder/ErrorPlaceHolder'; import NonAdminAction from '../common/non-admin-action/NonAdminAction'; @@ -261,26 +260,8 @@ const GlossaryV1 = ({ size="small" theme="primary" variant="contained" - onClick={() => { - setShowActions((show) => !show); - }}> - Actions{' '} - {showActions ? ( - - ) : ( - - )} + onClick={handleAddGlossaryTermClick}> + Add term {showActions && (