Skip to content

Commit

Permalink
Merge pull request #142 from ligangty/main
Browse files Browse the repository at this point in the history
Add unit test for RemoteView
  • Loading branch information
ligangty authored Jan 9, 2024
2 parents 2181ee0 + cbf6c68 commit 8256fcb
Showing 1 changed file with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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(<MemoryRouter initialEntries={["/remote/maven/view/central"]}>
<Routes>
<Route path="/remote/:packageType/view/:name" element={<RemoteView />} />
</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(/\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();
});
});
});

0 comments on commit 8256fcb

Please sign in to comment.