From 3cdb07af68bb7b6cec059cd50c48bf066ae3641c Mon Sep 17 00:00:00 2001 From: Ashish Gupta Date: Sat, 21 Sep 2024 11:14:50 +0530 Subject: [PATCH] supported class base for navbar utils items (#17932) * supported class base for navbar utils items * added unit test --------- Co-authored-by: Chirag Madlani <12962843+chirag-madlani@users.noreply.github.com> (cherry picked from commit 1badbb260b8f19773cf3a51ef9505d27ef11d187) --- .../ui/src/utils/NavbarUtilClassBase.test.tsx | 39 +++++++++++++++++++ .../ui/src/utils/NavbarUtilClassBase.ts | 24 ++++++++++++ .../resources/ui/src/utils/NavbarUtils.tsx | 9 ++--- 3 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 openmetadata-ui/src/main/resources/ui/src/utils/NavbarUtilClassBase.test.tsx create mode 100644 openmetadata-ui/src/main/resources/ui/src/utils/NavbarUtilClassBase.ts diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/NavbarUtilClassBase.test.tsx b/openmetadata-ui/src/main/resources/ui/src/utils/NavbarUtilClassBase.test.tsx new file mode 100644 index 00000000000..20becde6baf --- /dev/null +++ b/openmetadata-ui/src/main/resources/ui/src/utils/NavbarUtilClassBase.test.tsx @@ -0,0 +1,39 @@ +/* + * Copyright 2024 Collate. + * Licensed 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 { ROUTES } from '../constants/constants'; +import { + URL_GITHUB_REPO, + URL_JOIN_SLACK, + URL_OPEN_METADATA_DOCS, +} from '../constants/URL.constants'; +import navbarUtilClassBase from './NavbarUtilClassBase'; + +describe('NavbarUtilClassBase', () => { + it('should return all helper items with appropriate value', () => { + const result = navbarUtilClassBase.getHelpItems(); + const stringifyResult = JSON.stringify(result); + + expect(stringifyResult).toContain(ROUTES.TOUR); + expect(stringifyResult).toContain(URL_OPEN_METADATA_DOCS); + expect(stringifyResult).toContain(ROUTES.SWAGGER); + expect(stringifyResult).toContain(URL_JOIN_SLACK); + expect(stringifyResult).toContain(URL_GITHUB_REPO); + expect(stringifyResult).toContain('label.tour'); + expect(stringifyResult).toContain('label.doc-plural'); + expect(stringifyResult).toContain('label.api-uppercase'); + expect(stringifyResult).toContain('label.slack-support'); + expect(stringifyResult).toContain('label.whats-new'); + expect(stringifyResult).toContain('label.version'); + }); +}); diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/NavbarUtilClassBase.ts b/openmetadata-ui/src/main/resources/ui/src/utils/NavbarUtilClassBase.ts new file mode 100644 index 00000000000..6f7929b49e1 --- /dev/null +++ b/openmetadata-ui/src/main/resources/ui/src/utils/NavbarUtilClassBase.ts @@ -0,0 +1,24 @@ +/* + * Copyright 2024 Collate. + * Licensed 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 { HELP_ITEMS } from '../constants/Navbar.constants'; + +class NavbarUtilClassBase { + public getHelpItems() { + return HELP_ITEMS; + } +} + +const navbarUtilClassBase = new NavbarUtilClassBase(); + +export default navbarUtilClassBase; +export { NavbarUtilClassBase }; diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/NavbarUtils.tsx b/openmetadata-ui/src/main/resources/ui/src/utils/NavbarUtils.tsx index 84e6fa5c154..1c2960f562c 100644 --- a/openmetadata-ui/src/main/resources/ui/src/utils/NavbarUtils.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/utils/NavbarUtils.tsx @@ -16,11 +16,8 @@ import { Col, Row, Typography } from 'antd'; import React from 'react'; import { Link } from 'react-router-dom'; import { ReactComponent as IconExternalLink } from '../assets/svg/external-links.svg'; -import { - HELP_ITEMS, - HELP_ITEMS_ENUM, - SupportItem, -} from '../constants/Navbar.constants'; +import { HELP_ITEMS_ENUM, SupportItem } from '../constants/Navbar.constants'; +import navbarUtilClassBase from './NavbarUtilClassBase'; const getHelpDropdownLabelContentRenderer = ( item: SupportItem, @@ -77,7 +74,7 @@ const getHelpDropdownLabel = (item: SupportItem, version?: string) => { }; export const getHelpDropdownItems = (version?: string) => - HELP_ITEMS.map((item) => ({ + navbarUtilClassBase.getHelpItems().map((item) => ({ label: getHelpDropdownLabel(item, version), key: item.key, }));