Skip to content

Commit

Permalink
Merge pull request #144 from ligangty/main
Browse files Browse the repository at this point in the history
Add unit test for GroupView
  • Loading branch information
ligangty authored Jan 9, 2024
2 parents d530ff6 + 15c8675 commit 9175754
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 9 deletions.
65 changes: 65 additions & 0 deletions src/main/webui/src/app/components/content/group/GroupView.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* eslint-disable camelcase */
/**
* 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 {MemoryRouter, Route, Routes} from 'react-router-dom';
import {render, screen, cleanup, waitFor, within} from '@testing-library/react';
import '@testing-library/jest-dom';
import fetchMock from "fetch-mock";
import GroupView from "./GroupView.jsx";
import {STORE_API_BASE_URL} from "../../ComponentConstants.js";

beforeEach(()=>{
fetchMock.restore();
});

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

describe('GroupView tests', () => {
it("Verify GroupView", async ()=>{
const mockGroup = {name: "public", type: "group", packageType: "maven",
key: "maven:group:public", disabled: false,
description: "official maven public",
constituents: ["maven:remote:central", "maven:hosted:local-deployment"]};
const mockDisableTimeout = {name: "Disable-Timeout", group: "maven:group:public#Disable-Timeout",
expiration: "2030-02-22T17:00:00.000Z"};
fetchMock.mock(`${STORE_API_BASE_URL}/maven/group/public`, {status: 200, body: JSON.stringify(mockGroup)});
fetchMock.mock("/api/admin/schedule/store/maven/group/public/disable-timeout", {status: 200, body: JSON.stringify(mockDisableTimeout)});
render(<MemoryRouter initialEntries={["/group/maven/view/public"]}>
<Routes>
<Route path="/group/:packageType/view/:name" element={<GroupView />} />
</Routes>
</MemoryRouter>);

await waitFor(() => {
// ListControl section testing
expect(screen.getByRole("button", {name: "New..."})).toBeInTheDocument();

// StoreView: Basic section testing
expect(screen.getByText("Package Type:")).toBeInTheDocument();
expect(screen.getByText(mockGroup.packageType, {selector: "span"})).toBeInTheDocument();
expect(screen.getByText("Name:")).toBeInTheDocument();
expect(screen.getByText(mockGroup.name, {selector: "span"})).toBeInTheDocument();

// StoreView: Constituents section testing
expect(screen.getByText("maven:remote:central", {selector: "a"})).toBeInTheDocument();
expect(screen.getByText("maven:hosted:local-deployment", {selector: "a"})).toBeInTheDocument();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ afterEach(() => {

describe('HostedView tests', () => {
it("Verify HostedView", async ()=>{
const mockHostedStore = {name: "central", type: "hosted", packageType: "maven",
key: "maven:hosted:central", disabled: false, storage: "/var/lib/storage",
const mockHostedStore = {name: "local-deployment", type: "hosted", packageType: "maven",
key: "maven:hosted:local-deployment", disabled: false, storage: "/var/lib/storage",
"allow_snapshots": true, "allow_releases": true,
description: "official maven central"};
const mockDisableTimeout = {name: "Disable-Timeout", group: "maven:hosted:central#Disable-Timeout",
description: "local deployment repo"};
const mockDisableTimeout = {name: "Disable-Timeout", group: "maven:hosted:local-deployment#Disable-Timeout",
expiration: "2030-02-22T17:00:00.000Z"};
fetchMock.mock(`${STORE_API_BASE_URL}/maven/hosted/central`, {status: 200, body: JSON.stringify(mockHostedStore)});
fetchMock.mock("/api/admin/schedule/store/maven/hosted/central/disable-timeout", {status: 200, body: JSON.stringify(mockDisableTimeout)});
render(<MemoryRouter initialEntries={["/hosted/maven/view/central"]}>
fetchMock.mock(`${STORE_API_BASE_URL}/maven/hosted/local-deployment`, {status: 200, body: JSON.stringify(mockHostedStore)});
fetchMock.mock("/api/admin/schedule/store/maven/hosted/local-deployment/disable-timeout", {status: 200, body: JSON.stringify(mockDisableTimeout)});
render(<MemoryRouter initialEntries={["/hosted/maven/view/local-deployment"]}>
<Routes>
<Route path="/hosted/:packageType/view/:name" element={<HostedView />} />
</Routes>
Expand All @@ -54,9 +54,9 @@ describe('HostedView tests', () => {

// StoreView: Basic section testing
expect(screen.getByText("Package Type:")).toBeInTheDocument();
expect(screen.getByText(/\s*maven\s*$/u, {selector: "span"})).toBeInTheDocument();
expect(screen.getByText(mockHostedStore.packageType, {selector: "span"})).toBeInTheDocument();
expect(screen.getByText("Name:")).toBeInTheDocument();
expect(screen.getByText(/\s*central\s*$/u, {selector: "span"})).toBeInTheDocument();
expect(screen.getByText(mockHostedStore.name, {selector: "span"})).toBeInTheDocument();
expect(screen.getByText("Alternative Storage Directory:")).toBeInTheDocument();
expect(screen.getByText(mockHostedStore.storage, {selector: "span"})).toBeInTheDocument();

Expand Down

0 comments on commit 9175754

Please sign in to comment.