Skip to content

Commit

Permalink
Merge pull request #70 from ligangty/2.0-refactor
Browse files Browse the repository at this point in the history
Add unit test for CommonPageWidget
  • Loading branch information
ligangty authored Nov 14, 2023
2 parents f6b5dd7 + 0c55e99 commit 044c198
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 38 deletions.
36 changes: 0 additions & 36 deletions src/main/webui/src/app/components/CompUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* limitations under the License.
*/

import {jsonGet} from '../RestClient.js';

export const Utils = {
remoteOptions: store => {
let options = [];
Expand Down Expand Up @@ -139,39 +137,5 @@ export const Utils = {
let allParams = [message];
params.forEach(p => allParams.push(p));
Reflect.apply(console.log, undefined, allParams);
},
// TODO: not used?
getDisTimeouts: (state, setState, storeType) => {
jsonGet({
url: '/api/admin/schedule/store/all/disable-timeout',
done: response => {
let disabledMap = Utils.setDisableMap(response, state.listing);
setState({
disabledMap
});
},
fail: () => {
Utils.logMessage(`disable timeout get failed in ${storeType} listing.`);
}
});
},
// TODO: Not used?
getStores: (state, setState, storeType) => {
let url = `/api/admin/stores/_all/${storeType}`;
jsonGet({
url,
done: response => {
setState({
listing: response.items,
rawListing: response.items
});
Utils.getDisTimeouts(state, setState);
},
fail: errorText => {
setState({
message: JSON.parse(errorText).error
});
}
});
}
};
5 changes: 3 additions & 2 deletions src/main/webui/src/app/components/ComponentConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// mock data: options
// TODO: mock data: options. Need to use CompUtils.
const remoteOptionLegend = [
{icon: "S", title: "Snapshots allowed"},
{icon: "R", title: "Releases allowed"}
];

// TODO: mock data: options. Need to use CompUtils.
const hostedOptionLegend = [
{icon: 'S', title: 'Snapshots allowed'},
{icon: 'R', title: 'Releases allowed'},
{icon: 'D', title: 'Deployment allowed'}
];

// TODO this should be fetched from backend
// TODO: this should be fetched from backend
const PACKAGE_TYPES = ["maven", "generic","npm"];


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ LocalURLSection.propTypes = {
storeKey: PropTypes.string
};

// For options, see CompUtils.remoteOptions|hostedOptions
const CapabilitiesSection = ({options}) => <div className="left-half">
<label>Capabilities:</label>{' '}
{
Expand Down
46 changes: 46 additions & 0 deletions src/main/webui/src/app/components/content/CommonPageWidget.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* 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 {LocalURLSection,
CapabilitiesSection} from "./CommonPageWidget.jsx";
import {hostedOptionLegend} from '../ComponentConstants.js';

// const mockData = {};

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

describe('CommonPageWidget tests', () => {
it("LocalURLSection", () => {
render(<LocalURLSection storeKey="maven:remote:central"/>);
const keyLink = screen.getByRole("link");
expect(keyLink).toBeInTheDocument();
const urlPat = /https?:\/\/.*\/maven\/remote\/central$/ui;
expect(keyLink.href).toMatch(urlPat);
expect(screen.getByText(urlPat)).toBeInTheDocument();
});

it("CapabilitiesSection",()=>{
render(<CapabilitiesSection options={hostedOptionLegend}/>);
expect(screen.getByText(/\s*S\s*/u)).toBeInTheDocument();
expect(screen.getByText(/\s*R\s*/u)).toBeInTheDocument();
expect(screen.getByText(/\s*D\s*/u)).toBeInTheDocument();
});
});
4 changes: 4 additions & 0 deletions src/main/webui/src/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ app.get([Config.APP_ROOT, `${Config.APP_ROOT}/*`, '/'], (req, res) => {
res.sendFile(indexHtml);
});

app.get('/api/stats/package-type/keys', (req, res)=>{
res.status(200).json(["generic-http", "maven", "npm"]);
});

app.get('/api/admin/stores/_all/remote', (req, res) => {
const remoteList = require('./mock/list/FakeRemoteList.json');
res.status(200).json(remoteList);
Expand Down

0 comments on commit 044c198

Please sign in to comment.