Skip to content

Commit

Permalink
Merge branch 'master' of bitbucket.org:unicon/shib-idp-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Jj! committed Sep 13, 2021
2 parents f4f6df0 + 1a901ca commit d1f6e8d
Show file tree
Hide file tree
Showing 35 changed files with 160 additions and 14 deletions.
1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "ui",
"version": "0.1.0",
"private": true,
"homepage": ".",
"dependencies": {
"@fortawesome/fontawesome-free": "^5.15.3",
"@fortawesome/fontawesome-svg-core": "^1.2.35",
Expand Down
10 changes: 8 additions & 2 deletions ui/src/app/App.constant.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
export const API_BASE_PATH = 'api';
export const getBasePath = () => {
const url = new URL(document.getElementsByTagName('base')[0].href);
return url.pathname?.replace(/^\/+/g, '');

export const FILTER_PLUGIN_TYPES = ['RequiredValidUntil', 'SignatureValidation', 'EntityRoleWhiteList'];
//replace(/^\/|\/$/g, '')
};

export const BASE_PATH = getBasePath();
export const API_BASE_PATH = `${BASE_PATH}api`;

export const FILTER_PLUGIN_TYPES = ['RequiredValidUntil', 'SignatureValidation', 'EntityRoleWhiteList'];

export default API_BASE_PATH;
3 changes: 2 additions & 1 deletion ui/src/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { SessionModal } from './core/user/SessionModal';
import { Roles } from './admin/Roles';
import Button from 'react-bootstrap/Button';
import { Groups } from './admin/Groups';
import { BASE_PATH } from './App.constant';


function App() {
Expand Down Expand Up @@ -66,7 +67,7 @@ function App() {
<Contention>
<UserConfirmation>
{(message, confirm, confirmCallback, setConfirm, getConfirmation) =>
<Router getUserConfirmation={getConfirmation}>
<Router getUserConfirmation={getConfirmation} basename={BASE_PATH}>
<ConfirmWindow message={message} confirm={confirm} confirmCallback={confirmCallback} setConfirm={setConfirm} />
<QueryParamProvider ReactRouterRoute={Route}>
<Header />
Expand Down
6 changes: 6 additions & 0 deletions ui/src/app/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

jest.mock('./App.constant', () => ({
get API_BASE_PATH() {
return '/';
}
}));

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
Expand Down
3 changes: 2 additions & 1 deletion ui/src/app/admin/container/EditGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { GroupForm } from '../component/GroupForm';
import { GroupProvider } from '../hoc/GroupProvider';
import { createNotificationAction, NotificationTypes, useNotificationDispatcher } from '../../notifications/hoc/Notifications';
import { useTranslator } from '../../i18n/hooks';
import { BASE_PATH } from '../../App.constant';

export function EditGroup() {

Expand Down Expand Up @@ -67,7 +68,7 @@ export function EditGroup() {
<div className="section-body p-4 border border-top-0 border-info">
<GroupProvider id={id}>
{(group) =>
<Schema path={`/assets/schema/groups/group.json`}>
<Schema path={`/${BASE_PATH}assets/schema/groups/group.json`}>
{(schema) =>
<>{group &&
<FormManager initial={group}>
Expand Down
3 changes: 2 additions & 1 deletion ui/src/app/admin/container/EditRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { RoleForm } from '../component/RoleForm';
import { RoleProvider } from '../hoc/RoleProvider';
import { createNotificationAction, NotificationTypes, useNotificationDispatcher } from '../../notifications/hoc/Notifications';
import { useTranslator } from '../../i18n/hooks';
import { BASE_PATH } from '../../App.constant';

export function EditRole() {

Expand Down Expand Up @@ -67,7 +68,7 @@ export function EditRole() {
<div className="section-body p-4 border border-top-0 border-info">
<RoleProvider id={id}>
{(role) =>
<Schema path={`/assets/schema/roles/role.json`}>
<Schema path={`/${BASE_PATH}assets/schema/roles/role.json`}>
{(schema) =>
<>{role &&
<FormManager initial={role}>
Expand Down
3 changes: 2 additions & 1 deletion ui/src/app/admin/container/NewGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { GroupForm } from '../component/GroupForm';

import { createNotificationAction, NotificationTypes, useNotificationDispatcher } from '../../notifications/hoc/Notifications';
import { useTranslator } from '../../i18n/hooks';
import { BASE_PATH } from '../../App.constant';

export function NewGroup() {
const history = useHistory();
Expand Down Expand Up @@ -59,7 +60,7 @@ export function NewGroup() {
</div>
</div>
<div className="section-body p-4 border border-top-0 border-info">
<Schema path={`/assets/schema/groups/group.json`}>
<Schema path={`/${BASE_PATH}assets/schema/groups/group.json`}>
{(schema) =>
<FormManager initial={{}}>
{(data, errors) =>
Expand Down
3 changes: 2 additions & 1 deletion ui/src/app/admin/container/NewRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { RoleForm } from '../component/RoleForm';

import { createNotificationAction, NotificationTypes, useNotificationDispatcher } from '../../notifications/hoc/Notifications';
import { useTranslator } from '../../i18n/hooks';
import { BASE_PATH } from '../../App.constant';

export function NewRole() {
const history = useHistory();
Expand Down Expand Up @@ -59,7 +60,7 @@ export function NewRole() {
</div>
</div>
<div className="section-body p-4 border border-top-0 border-info">
<Schema path={`/assets/schema/roles/role.json`}>
<Schema path={`/${BASE_PATH}assets/schema/roles/role.json`}>
{(schema) =>
<FormManager initial={{}}>
{(data, errors) =>
Expand Down
6 changes: 6 additions & 0 deletions ui/src/app/admin/hoc/RoleProvider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import {RoleProvider} from './RoleProvider';

import {useRole} from '../hooks';

jest.mock('../../App.constant', () => ({
get API_BASE_PATH() {
return '/';
}
}));

jest.mock('../hooks');

describe('RoleProvider component', () => {
Expand Down
6 changes: 6 additions & 0 deletions ui/src/app/admin/hoc/RolesProvider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import { RolesProvider } from './RolesProvider';
import { useRoles } from '../hooks';
import { useNotificationDispatcher } from "../../notifications/hoc/Notifications";

jest.mock('../../App.constant', () => ({
get API_BASE_PATH() {
return '/';
}
}));

jest.mock('../hooks');

jest.mock('../../notifications/hoc/Notifications');
Expand Down
6 changes: 6 additions & 0 deletions ui/src/app/admin/hooks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import {
import useFetch from 'use-http';
import API_BASE_PATH from '../App.constant';

jest.mock('../App.constant', () => ({
get API_BASE_PATH() {
return '/';
}
}));

jest.mock('use-http');

describe('api hooks', () => {
Expand Down
6 changes: 6 additions & 0 deletions ui/src/app/core/components/Footer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import React from 'react';
import { render, screen } from '@testing-library/react';
import { Footer } from './Footer';

jest.mock('../../App.constant', () => ({
get API_BASE_PATH() {
return '/';
}
}));

jest.mock('../../i18n/hooks', () => ({
useTranslation: (value) => value
}));
Expand Down
3 changes: 2 additions & 1 deletion ui/src/app/core/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useTranslator } from '../../i18n/hooks';

import { brand } from '../../app.brand';
import { useIsAdmin } from '../user/UserContext';
import { BASE_PATH } from '../../App.constant';

export function Header () {

Expand Down Expand Up @@ -73,7 +74,7 @@ export function Header () {
<FontAwesomeIcon icon={faTh} className="mr-2" />
<Translate value="action.dashboard">Dashboard</Translate>
</Link>
<Nav.Link href="/logout" target="_self" aria-label={translator('action.logout')}>
<Nav.Link href={`/${BASE_PATH}logout`} target="_self" aria-label={translator('action.logout')}>
<FontAwesomeIcon icon={faSignOutAlt} className="mr-2" />
<Translate value="action.logout">Logout</Translate>
</Nav.Link>
Expand Down
6 changes: 6 additions & 0 deletions ui/src/app/core/components/Header.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import { render, screen } from '@testing-library/react';
import { BrowserRouter as Router } from 'react-router-dom';
import { Header } from './Header';

jest.mock('../../App.constant', () => ({
get API_BASE_PATH() {
return '/';
}
}));

jest.mock('../../i18n/hooks', () => ({
useTranslator: () => (value) => value,
useTranslation: (value) => value
Expand Down
3 changes: 2 additions & 1 deletion ui/src/app/core/components/VersionInfo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';

import useFetch from 'use-http';
import { BASE_PATH } from '../../App.constant';

import Translate from '../../i18n/components/translate';

Expand All @@ -11,7 +12,7 @@ const params = { year };

export function VersionInfo () {

const { data = {} } = useFetch('/actuator/info', {}, []);
const { data = {} } = useFetch(`${BASE_PATH}actuator/info`, {}, []);

const [ versionData, setVersionData ] = React.useState('');

Expand Down
6 changes: 6 additions & 0 deletions ui/src/app/core/components/VersionInfo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import { render, screen } from '@testing-library/react';

import { VersionInfo } from './VersionInfo';

jest.mock('../../App.constant', () => ({
get API_BASE_PATH() {
return '/';
}
}));

const data = { "git": { "branch": "react", "commit": { "id": "634f1a4", "time": "2021-06-10T19:00:29Z" } }, "build": { "artifact": "shibui", "name": "backend", "time": "2021-06-10T19:26:14.478Z", "version": "2.0.0-SNAPSHOT", "group": "edu.internet2.tier.shibboleth.admin.ui" } };

jest.mock('../../i18n/components/translate', () => {
Expand Down
6 changes: 6 additions & 0 deletions ui/src/app/core/user/UserContext.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import { UserProvider, useIsAdmin } from './UserContext';

jest.mock('../../App.constant', () => ({
get API_BASE_PATH() {
return '/';
}
}));

const getFn = jest.fn();
const okFn = jest.fn();

Expand Down
1 change: 1 addition & 0 deletions ui/src/app/form/component/fields/FilterTargetField.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ const FilterTargetField = ({
className="form-control"
type="text"
name="script"
value={selectedTarget[0]}
onChange={ ({target: { value }}) => handleTextChange(value) } />
{errorSchema?.value?.__errors ?
<small className="form-text text-danger">
Expand Down
6 changes: 6 additions & 0 deletions ui/src/app/i18n/context/I18n.provider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import { I18nProvider } from './I18n.provider';

jest.mock('../../App.constant', () => ({
get API_BASE_PATH() {
return '/';
}
}));

const getFn = jest.fn();
const okFn = jest.fn();

Expand Down
5 changes: 5 additions & 0 deletions ui/src/app/i18n/hooks.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import React from 'react';

import { translate, getMessage, useTranslation, useTranslator } from './hooks';
jest.mock('../App.constant', () => ({
get API_BASE_PATH() {
return '/';
}
}));

const msgs = { foo: 'bar { baz }' };

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { defaultsDeep } from "lodash";
import { BASE_PATH } from "../../../App.constant";

export const CustomAttributeDefinition = {
label: 'Metadata Attribute',
type: '@MetadataAttribute',
steps: [],
schema: `/assets/schema/attribute/attribute.schema.json`,
schema: `${BASE_PATH}assets/schema/attribute/attribute.schema.json`,

uiSchema: {
layout: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { CustomAttributeDefinition } from "./CustomAttributeDefinition";

jest.mock('../../../App.constant', () => ({
get API_BASE_PATH() {
return '/';
}
}));


describe('formatter', () => {
it('should format the object passed for the json-schema-form', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import { getDefinition } from '../../../domain/index';
import { MetadataConfiguration } from '../../../component/MetadataConfiguration';
import { useMetadataConfiguration } from '../../../hooks/configuration';
import useFetch from 'use-http';
import { BASE_PATH } from '../../../../App.constant';

export function MetadataFilterConfigurationListItem ({ filter, isLast, isFirst, onOrderUp, onOrderDown, onEnable, editable, onRemove, loading, index }) {
const [open, setOpen] = React.useState(false);

const definition = React.useMemo(() => getDefinition(filter['@type'], ), [filter]);

const { get, response } = useFetch('');
const { get, response } = useFetch(`${BASE_PATH}`);

const [schema, setSchema] = React.useState();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { EntityAttributesFilterWizard } from "./EntityAttributesFilterDefinition";

jest.mock('../../../../App.constant', () => ({
get API_BASE_PATH() {
return '/';
}
}));

const addErrorMockFn = jest.fn();

const filters = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { NameIDFilterWizard } from "./NameIdFilterDefinition";

jest.mock('../../../../App.constant', () => ({
get API_BASE_PATH() {
return '/';
}
}));

const addErrorMockFn = jest.fn();

const filters = [
Expand Down
6 changes: 6 additions & 0 deletions ui/src/app/metadata/domain/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import { getDefinition } from './index';
import { FileSystemMetadataProviderEditor } from './provider/definition/FileSystemMetadataProviderDefinition';
import { SourceEditor } from './source/definition/SourceDefinition';

jest.mock('../../App.constant', () => ({
get API_BASE_PATH() {
return '/';
}
}));

describe('getDefinitions method', () => {
it('should retrieve the definition', () => {
expect(getDefinition('source')).toBe(SourceEditor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import { render, screen } from '@testing-library/react';

import { ProviderList } from './ProviderList';

jest.mock('../../../../App.constant', () => ({
get API_BASE_PATH() {
return '/';
}
}));

jest.mock('../../../../i18n/hooks', () => ({
useTranslation: (value) => value
}));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { BaseProviderDefinition } from './BaseProviderDefinition';
import schema from '../../../../../testing/dynamic-http.schema';

jest.mock('../../../../App.constant', () => ({
get API_BASE_PATH() {
return '/';
}
}));

const addErrorMockFn = jest.fn();

const providers = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { DynamicHttpMetadataProviderWizard } from './DynamicHttpMetadataProviderDefinition';
import schema from '../../../../../testing/dynamic-http.schema';

jest.mock('../../../../App.constant', () => ({
get API_BASE_PATH() {
return '/';
}
}));

const addErrorMockFn = jest.fn();

const providers = [
Expand Down
Loading

0 comments on commit d1f6e8d

Please sign in to comment.