Skip to content

Commit

Permalink
Merge pull request #83 from ligangty/2.0-refactor
Browse files Browse the repository at this point in the history
Add unit test for StoreBasicSections
  • Loading branch information
ligangty authored Nov 16, 2023
2 parents 2047454 + 6ec7e18 commit fd91f99
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,15 @@ export const StoreViewBasicSection = ({store})=>{
</div>
<div className="detail-field">
<label>Local URL:</label>
{
// TODO: is this store.demo still available now?
store.demo ?
<span>{Utils.storeHref(store.key)}</span> :
<span><a href={Utils.storeHref(store.key)} target="_new">{Utils.storeHref(store.key)}</a></span>
}
</div>
<div className="detail-field">
<label>Remote URL:</label>
<span><a href={store.url} target="_new">{store.url}</a></span>
<span><a href={Utils.storeHref(store.key)} target="_new">{Utils.storeHref(store.key)}</a></span>
</div>
{
store.type==="remote" &&
<div className="detail-field">
<label>Remote URL:</label>
<span><a href={store.url} target="_new">{store.url}</a></span>
</div>
}
<div className="sub-fields">
<div className="detail-field">
<span>{Filters.checkmark(!store.is_passthrough)}</span>
Expand All @@ -79,7 +77,6 @@ export const StoreViewBasicSection = ({store})=>{
</div>
{
!store.is_passthrough &&

<div>
<div className="detail-field">
<label>Content Cache Timeout:</label>
Expand All @@ -90,25 +87,26 @@ export const StoreViewBasicSection = ({store})=>{
<span>{TimeUtils.secondsToDuration(store.metadata_timeout_seconds, true)}</span>
</div>
</div>

}
</div>

<div className="sub-fields">
<div className="detail-field">
<label>Pre-fetching Priority:</label>
<span>{store.prefetch_priority}</span>
<PrefetchHint />
</div>
<div className="detail-field">
<span>{Filters.checkmark(store.prefetch_rescan)}</span>
<label>Allow Pre-fetching Rescan?</label>
</div>
<div className="detail-field">
<label>Pre-fetching Listing Type:</label>
<span>{store.prefetch_listing_type}</span>
{
store.type==="remote" &&
<div className="sub-fields">
<div className="detail-field">
<label>Pre-fetching Priority:</label>
<span>{store.prefetch_priority}</span>
<PrefetchHint />
</div>
<div className="detail-field">
<span>{Filters.checkmark(store.prefetch_rescan)}</span>
<label>Allow Pre-fetching Rescan?</label>
</div>
<div className="detail-field">
<label>Pre-fetching Listing Type:</label>
<span>{store.prefetch_listing_type}</span>
</div>
</div>
</div>
}
</div>;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* 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 from "react";
import {render, screen, cleanup} from '@testing-library/react';
import '@testing-library/jest-dom';
import {StoreViewBasicSection} from "./StoreBasicSections.jsx";
import {Utils} from "../../../utils/AppUtils.js";

afterEach(() => {
cleanup();
});

describe('StoreBasicSections tests', () => {
it("Verify StoreViewBasicSection for remote repo", ()=>{
// Remote repository test
const mockRemoteStore = {name: "central", type: "remote", packageType: "maven",
key: "maven:remote:central", disabled: false, "allow_snapshots": true,
"allow_releases": true, url: "https://repo.maven.apache.org/maven2/",
description: "official maven central"};
render(<StoreViewBasicSection store={mockRemoteStore} />);
expect(screen.getByText("Package Type:")).toBeInTheDocument();
expect(screen.getByText(/\s*maven\s*$/u, {selector: "span"})).toBeInTheDocument();

expect(screen.getByText("Name:")).toBeInTheDocument();
expect(screen.getByText(/\s*central\s*$/u, {selector: "span"})).toBeInTheDocument();

expect(screen.getByText("Make the content index authoritative to this repository")).toBeInTheDocument();

let storeLocalURL = Utils.storeHref(mockRemoteStore.key);
expect(screen.getByRole("link", {name: storeLocalURL})).toHaveAttribute("href", storeLocalURL);
expect(screen.getByRole("link", {name: mockRemoteStore.url})).toHaveAttribute("href", mockRemoteStore.url);

expect(screen.getByText("Content Cache Timeout:")).toBeInTheDocument();
expect(screen.getByText("Metadata Cache Timeout:")).toBeInTheDocument();

expect(screen.getByText("Pre-fetching Priority:")).toBeInTheDocument();
expect(screen.getByText("Allow Pre-fetching Rescan?")).toBeInTheDocument();
expect(screen.getByText("Pre-fetching Listing Type:")).toBeInTheDocument();
});

it("Verify StoreViewBasicSection for hosted repo", ()=>{
// Remote repository test
const mockHostedStore = {name: "local-deployments", type: "hosted", packageType: "maven",
key: "maven:hosted:local-deployments", disabled: false, "allow_snapshots": true,
"allow_releases": true, description: "work for local deployment",
url: "http://fakeurl"};
render(<StoreViewBasicSection store={mockHostedStore} />);
expect(screen.getByText("Package Type:")).toBeInTheDocument();
expect(screen.getByText(/\s*maven\s*$/u, {selector: "span"})).toBeInTheDocument();

expect(screen.getByText("Name:")).toBeInTheDocument();
expect(screen.getByText(/\s*local-deployments\s*$/u, {selector: "span"})).toBeInTheDocument();

expect(screen.getByText("Make the content index authoritative to this repository (when readonly, this will be enabled automatically)")).toBeInTheDocument();

const storeLocalURL = Utils.storeHref(mockHostedStore.key);
expect(screen.getByRole("link", {name: storeLocalURL})).toHaveAttribute("href", storeLocalURL);
expect(screen.queryByRole("link", {name: mockHostedStore.url})).toBeNull();

expect(screen.getByText("Content Cache Timeout:")).toBeInTheDocument();
expect(screen.getByText("Metadata Cache Timeout:")).toBeInTheDocument();

expect(screen.queryByText("Pre-fetching Priority:")).toBeNull();
expect(screen.queryByText("Allow Pre-fetching Rescan?")).toBeNull();
expect(screen.queryByText("Pre-fetching Listing Type:")).toBeNull();
});
});

0 comments on commit fd91f99

Please sign in to comment.