From 6d55d966c575548a12522e1759728a0833e3db28 Mon Sep 17 00:00:00 2001 From: Gang Li Date: Thu, 16 Nov 2023 11:10:19 +0800 Subject: [PATCH] Refactor StoreListingWidget test with single export --- .../content/common/StoreListingWidget.jsx | 5 +- .../content/common/StoreListingWidget.test.js | 53 +++++++------------ 2 files changed, 21 insertions(+), 37 deletions(-) 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 ebcf3ba..88dcb68 100644 --- a/src/main/webui/src/app/components/content/common/StoreListingWidget.jsx +++ b/src/main/webui/src/app/components/content/common/StoreListingWidget.jsx @@ -98,7 +98,4 @@ StoreListingWidget.propTypes = { storeType: PropTypes.string }; -export {LocalURLSection, - CapabilitiesSection, - StoreNameSection, - StoreListingWidget}; +export {StoreListingWidget}; diff --git a/src/main/webui/src/app/components/content/common/StoreListingWidget.test.js b/src/main/webui/src/app/components/content/common/StoreListingWidget.test.js index c203261..1d8ef90 100644 --- a/src/main/webui/src/app/components/content/common/StoreListingWidget.test.js +++ b/src/main/webui/src/app/components/content/common/StoreListingWidget.test.js @@ -18,48 +18,19 @@ 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, - StoreListingWidget} from "./StoreListingWidget.jsx"; -import {hostedOptionLegend} from '../../ComponentConstants.js'; +import {StoreListingWidget} from "./StoreListingWidget.jsx"; +import {Utils} from "../../../utils/AppUtils.js"; afterEach(() => { cleanup(); }); describe('StoreListingWidget tests', () => { - it("Verify LocalURLSection", () => { - render(); - const keyLink = screen.getByRole("link"); - expect(keyLink).toBeInTheDocument(); - const urlPat = /https?:\/\/.*\/maven\/remote\/central$/ui; - expect(keyLink.href).toMatch(urlPat); - expect(screen.getByText(urlPat)).toBeInTheDocument(); - }); - - 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("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/", + key: "maven:remote:central", disabled: false, "allow_snapshots": true, + "allow_releases": true, url: "https://repo.maven.apache.org/maven2/", description: "official maven central"}, {name: "mrrc", type: "remote", packageType: "maven", key: "maven:remote:mrrc", disabled: false, @@ -70,6 +41,22 @@ describe('StoreListingWidget tests', () => { render( ); + + // Testing LocalURLSection + const generatedLocalURL= Utils.storeHref("maven:remote:central"); + const localUrlElem = screen.getByRole("link", {name: generatedLocalURL}); + expect(localUrlElem).toBeInTheDocument(); + expect(localUrlElem).toHaveAttribute("href", generatedLocalURL); + + // Testing CapabilitiesSection + expect(screen.getByText(/\s*S\s*$/u, {selector: "span"})).toBeInTheDocument(); + expect(screen.getByText(/\s*R\s*$/u, {selector: "span"})).toBeInTheDocument(); + + // Testing StoreNameSection + expect(screen.getByText(/maven-central/u, {selector: "span"})).toBeInTheDocument(); + expect(screen.getByText(/maven-mrrc/u, {selector: "span"})).toBeInTheDocument(); + + // Testing other parts in StoreListingWidget 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();