diff --git a/src/main/webui/src/app/components/content/remote/RemoteView.test.jsx b/src/main/webui/src/app/components/content/remote/RemoteView.test.jsx new file mode 100644 index 0000000..db89c69 --- /dev/null +++ b/src/main/webui/src/app/components/content/remote/RemoteView.test.jsx @@ -0,0 +1,81 @@ +/* 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 RemoteView from "./RemoteView.jsx"; +import {Filters} from "#utils/Filters.js"; +import {STORE_API_BASE_URL} from "../../ComponentConstants.js"; + +beforeEach(()=>{ + fetchMock.restore(); +}); + +afterEach(() => { + cleanup(); +}); + +describe('RemoteView tests', () => { + it("Verify RemoteView", async ()=>{ + 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", + server_certificate_pem: "lksjdflksjdfl", key_certificate_pem: "kjlkjlkjlsdfsdf", + proxy_host: "https://test.proxy.server/", proxy_port: 8010, + user: "testuser"}; + const mockDisableTimeout = {name: "Disable-Timeout", group: "maven:remote:central#Disable-Timeout", + expiration: "2030-02-22T17:00:00.000Z"}; + fetchMock.mock(`${STORE_API_BASE_URL}/maven/remote/central`, {status: 200, body: JSON.stringify(mockRemoteStore)}); + fetchMock.mock("/api/admin/schedule/store/maven/remote/central/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(/\s*maven\s*$/u, {selector: "span"})).toBeInTheDocument(); + expect(screen.getByText("Name:")).toBeInTheDocument(); + expect(screen.getByText(/\s*central\s*$/u, {selector: "span"})).toBeInTheDocument(); + + // StoreView: Capabilities section testing + let parentDiv = screen.getByText("Allow Releases").closest("div"); + expect(within(parentDiv).getByText(Filters.checkmark(mockRemoteStore.allow_releases))).toBeInTheDocument(); + parentDiv = screen.getByText("Snapshots Allowed?").closest("div"); + expect(within(parentDiv).getByText(Filters.checkmark(mockRemoteStore.allow_snapshots))).toBeInTheDocument(); + + // StoreView: SSL section testing + parentDiv = screen.getByText("Proxy Host:").closest("div"); + expect(within(parentDiv).getByText(mockRemoteStore.proxy_host)).toBeInTheDocument(); + parentDiv = screen.getByText("Proxy Port:").closest("div"); + expect(within(parentDiv).getByText(mockRemoteStore.proxy_port)).toBeInTheDocument(); + parentDiv = screen.getByText("Username:").closest("div"); + expect(within(parentDiv).getByText(mockRemoteStore.user)).toBeInTheDocument(); + expect(screen.getByText(mockRemoteStore.server_certificate_pem, {selector: "textarea"})).toBeInTheDocument(); + expect(screen.getByText(mockRemoteStore.key_certificate_pem, {selector: "textarea"})).toBeInTheDocument(); + }); + }); +});