diff --git a/src/main/webui/src/app/components/content/RemoteList.jsx b/src/main/webui/src/app/components/content/RemoteList.jsx index 66e0b5f..9784122 100644 --- a/src/main/webui/src/app/components/content/RemoteList.jsx +++ b/src/main/webui/src/app/components/content/RemoteList.jsx @@ -98,7 +98,7 @@ export default function RemoteList() { handleCreateNew={handlers.createNew} /> { listing? - : + :
No content fetched!
diff --git a/src/main/webui/src/app/components/content/common/CommonPageWidget.jsx b/src/main/webui/src/app/components/content/common/CommonPageWidget.jsx deleted file mode 100644 index 515049c..0000000 --- a/src/main/webui/src/app/components/content/common/CommonPageWidget.jsx +++ /dev/null @@ -1,104 +0,0 @@ -/** - * Copyright (C) 2023 Red Hat, Inc. (https://github.com/Commonjava/indy-ui-service) - * - * 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 React, {Fragment} from 'react'; -import {Link} from 'react-router-dom'; -import {PropTypes} from 'prop-types'; -import {Utils} from '../../../utils/AppUtils.js'; - -const LocalURLSection = ({storeKey}) =>
- {' '} - {Utils.storeHref(storeKey)} -
; - -LocalURLSection.propTypes = { - storeKey: PropTypes.string -}; - -// For options, see AppUtils.remoteOptions|hostedOptions -const CapabilitiesSection = ({options}) =>
- {' '} - { - options.map(option =>
- {option.icon} -
) - } -
; - -CapabilitiesSection.propTypes = { - options: PropTypes.array -}; - -const StoreNameSection = ({store, storeClass}) =>
- - {store.packageType}-{store.name} - -
; - -StoreNameSection.propTypes = { - store: PropTypes.object, - storeClass: PropTypes.string -}; - -const StoreListingWidget = ({StoreList, DisMap, StoreType}) => { - const listing = StoreList; - const disMap = DisMap; - if(listing && listing.length >0){ - return ( -
-
- { - listing.map(store => { - const storeClass = Utils.isDisabled(store.key, disMap)? "disabled-store":"enabled-store"; - return ( -
- -
-
- - { - StoreType === "remote" &&
- - {store.url} -
- } -
-
- -
-
{store.description}
-
-
- ); - }) - } -
-
- ); - } - return ; -}; - -StoreListingWidget.propTypes = { - StoreList: PropTypes.array, - DisMap: PropTypes.object, - StoreType: PropTypes.string -}; - -export {LocalURLSection, - CapabilitiesSection, - StoreNameSection, - StoreListingWidget}; diff --git a/src/main/webui/src/app/components/content/common/StoreListingWidget.jsx b/src/main/webui/src/app/components/content/common/StoreListingWidget.jsx index da2fc21..ebcf3ba 100644 --- a/src/main/webui/src/app/components/content/common/StoreListingWidget.jsx +++ b/src/main/webui/src/app/components/content/common/StoreListingWidget.jsx @@ -15,13 +15,47 @@ */ import React, {Fragment} from 'react'; +import {Link} from 'react-router-dom'; import {PropTypes} from 'prop-types'; import {Utils} from '../../../utils/AppUtils.js'; -import {LocalURLSection,StoreNameSection,CapabilitiesSection} from './CommonPageWidget.jsx'; -export const StoreListingWidget = ({StoreList, DisMap, StoreType}) => { - const listing = StoreList; - const disMap = DisMap; +const LocalURLSection = ({storeKey}) =>
+ {' '} + {Utils.storeHref(storeKey)} +
; + +LocalURLSection.propTypes = { + storeKey: PropTypes.string +}; + +// For options, see AppUtils.remoteOptions|hostedOptions +const CapabilitiesSection = ({options}) =>
+ {' '} + { + options.map(option =>
+ {option.icon} +
) + } +
; + +CapabilitiesSection.propTypes = { + options: PropTypes.array +}; + +const StoreNameSection = ({store, storeClass}) =>
+ + {store.packageType}-{store.name} + +
; + +StoreNameSection.propTypes = { + store: PropTypes.object, + storeClass: PropTypes.string +}; + +const StoreListingWidget = ({storeList, disableMap, storeType}) => { + const listing = storeList; + const disMap = disableMap; if(listing && listing.length >0){ return (
@@ -36,7 +70,7 @@ export const StoreListingWidget = ({StoreList, DisMap, StoreType}) => {
{ - StoreType === "remote" &&
+ storeType === "remote" &&
{store.url}
@@ -59,7 +93,12 @@ export const StoreListingWidget = ({StoreList, DisMap, StoreType}) => { }; StoreListingWidget.propTypes = { - StoreList: PropTypes.array, - DisMap: PropTypes.object, - StoreType: PropTypes.string + storeList: PropTypes.array, + disableMap: PropTypes.object, + storeType: PropTypes.string }; + +export {LocalURLSection, + CapabilitiesSection, + StoreNameSection, + StoreListingWidget}; diff --git a/src/main/webui/src/app/components/content/common/CommonPageWidget.test.js b/src/main/webui/src/app/components/content/common/StoreListingWidget.test.js similarity index 57% rename from src/main/webui/src/app/components/content/common/CommonPageWidget.test.js rename to src/main/webui/src/app/components/content/common/StoreListingWidget.test.js index dc508da..c203261 100644 --- a/src/main/webui/src/app/components/content/common/CommonPageWidget.test.js +++ b/src/main/webui/src/app/components/content/common/StoreListingWidget.test.js @@ -18,15 +18,18 @@ import React from "react"; import {MemoryRouter} from 'react-router-dom'; import {render, screen, cleanup} from '@testing-library/react'; import '@testing-library/jest-dom'; -import {LocalURLSection, CapabilitiesSection, StoreNameSection} from "./CommonPageWidget.jsx"; +import {LocalURLSection, + CapabilitiesSection, + StoreNameSection, + StoreListingWidget} from "./StoreListingWidget.jsx"; import {hostedOptionLegend} from '../../ComponentConstants.js'; afterEach(() => { cleanup(); }); -describe('CommonPageWidget tests', () => { - it("LocalURLSection", () => { +describe('StoreListingWidget tests', () => { + it("Verify LocalURLSection", () => { render(); const keyLink = screen.getByRole("link"); expect(keyLink).toBeInTheDocument(); @@ -35,14 +38,14 @@ describe('CommonPageWidget tests', () => { expect(screen.getByText(urlPat)).toBeInTheDocument(); }); - it("CapabilitiesSection",()=>{ + it("Verify CapabilitiesSection",()=>{ render(); expect(screen.getByText(/\s*S\s*/u)).toBeInTheDocument(); expect(screen.getByText(/\s*R\s*/u)).toBeInTheDocument(); expect(screen.getByText(/\s*D\s*/u)).toBeInTheDocument(); }); - it("StoreNameSection", ()=>{ + it("Verify StoreNameSection", ()=>{ // As is in , needs to use a Router to wrap it render( { ); expect(screen.getByText(/maven-central/u)).toBeInTheDocument(); }); + + it("Verify StoreListingWidget", ()=>{ + const mockRemoteStoreList = [ + {name: "central", type: "remote", packageType: "maven", + key: "maven:remote:central", disabled: false, + url: "https://repo.maven.apache.org/maven2/", + description: "official maven central"}, + {name: "mrrc", type: "remote", packageType: "maven", + key: "maven:remote:mrrc", disabled: false, + url: "https://maven.repository.redhat.com/ga/", + description: "Red Hat maven repository"}, + ]; + const mockDisableMap = {}; + render( + + ); + expect(screen.getByText(/https:\/\/repo.maven.apache.org\/maven2\//u)).toBeInTheDocument(); + expect(screen.getByText(/official maven central/u)).toBeInTheDocument(); + expect(screen.getByText(/https:\/\/maven.repository.redhat.com\/ga\//u)).toBeInTheDocument(); + expect(screen.getByText(/Red Hat maven repository/u)).toBeInTheDocument(); + }); });