diff --git a/src/main/webui/src/app/components/content/group/GroupView.test.jsx b/src/main/webui/src/app/components/content/group/GroupView.test.jsx new file mode 100644 index 0000000..3cf485c --- /dev/null +++ b/src/main/webui/src/app/components/content/group/GroupView.test.jsx @@ -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( + + } /> + + ); + + 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(); + }); + }); +}); diff --git a/src/main/webui/src/app/components/content/hosted/HostedView.test.jsx b/src/main/webui/src/app/components/content/hosted/HostedView.test.jsx index 67b47ae..e1ea97d 100644 --- a/src/main/webui/src/app/components/content/hosted/HostedView.test.jsx +++ b/src/main/webui/src/app/components/content/hosted/HostedView.test.jsx @@ -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( + 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( } /> @@ -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();