Skip to content

Commit

Permalink
Refactor StoreListingWidget test with single export
Browse files Browse the repository at this point in the history
  • Loading branch information
ligangty committed Nov 16, 2023
1 parent 8973642 commit 6d55d96
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,4 @@ StoreListingWidget.propTypes = {
storeType: PropTypes.string
};

export {LocalURLSection,
CapabilitiesSection,
StoreNameSection,
StoreListingWidget};
export {StoreListingWidget};
Original file line number Diff line number Diff line change
Expand Up @@ -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(<LocalURLSection storeKey="maven:remote:central"/>);
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(<CapabilitiesSection options={hostedOptionLegend}/>);
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 <Link> is in <StoreNameSection>, needs to use a Router to wrap it
render(<MemoryRouter>
<StoreNameSection
store={{packageType: "maven", type: "remote", name: "central"}}
storeClass="test-style"/>
</MemoryRouter>);
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,
Expand All @@ -70,6 +41,22 @@ describe('StoreListingWidget tests', () => {
render(<MemoryRouter>
<StoreListingWidget storeList={mockRemoteStoreList} disableMap={mockDisableMap} storeType="remote"/>
</MemoryRouter>);

// 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();
Expand Down

0 comments on commit 6d55d96

Please sign in to comment.