Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: ac892247 <[email protected]>
  • Loading branch information
achmelo committed Feb 3, 2025
1 parent 47a2fda commit 1ce0c4f
Show file tree
Hide file tree
Showing 20 changed files with 57 additions and 184 deletions.
12 changes: 3 additions & 9 deletions api-catalog-ui/frontend/src/actions/catalog-tile-actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import {
FETCH_TILES_REQUEST,
FETCH_TILES_STOP,
FETCH_TILES_SUCCESS,
STORE_CURRENT_TILEID,
FETCH_NEW_SERVICE_REQUEST, FETCH_NEW_SERVICE_SUCCESS, FETCH_SERVICE_STOP,
FETCH_NEW_SERVICE_REQUEST,
FETCH_NEW_SERVICE_SUCCESS,
FETCH_SERVICE_STOP,
FETCH_SERVICE_FAILED
} from '../constants/catalog-tile-constants';

Expand Down Expand Up @@ -57,13 +58,6 @@ export function fetchNewServiceSuccess(service) {
};
}

export function storeCurrentTileId(currentId) {
return {
type: STORE_CURRENT_TILEID,
payload: currentId,
};
}

export function fetchTilesStop() {
// dismiss the notification if it is displayed
toast.dismiss(fetchRetryToastId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,20 @@ describe('>>> Catalog tiles actions tests', () => {

it('should create when start fetching new tiles', () => {
const expectedAction = {
type: constants.FETCH_NEW_TILES_REQUEST,
type: constants.FETCH_NEW_SERVICE_REQUEST,
payload: '',
};

expect(actions.fetchNewTiles('')).toEqual(expectedAction);
expect(actions.fetchNewService('')).toEqual(expectedAction);
});

it('should create when fetching new tiles is successful', () => {
const expectedAction = {
type: constants.FETCH_TILES_NEW_SUCCESS,
type: constants.FETCH_NEW_SERVICE_SUCCESS,
payload: [],
};

expect(actions.fetchNewTilesSuccess([])).toEqual(expectedAction);
expect(actions.fetchNewServiceSuccess([])).toEqual(expectedAction);
});

it('should create when storing current tile ID', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ function Dashboard({
refreshedStaticApisError,
clearError,
authentication,
storeCurrentTileId,
selectEnabler,
clear,
refreshedStaticApi,
Expand Down Expand Up @@ -146,7 +145,6 @@ function Dashboard({
.filter((tile) => tile.services.includes(service))
.map((tile) => (
<Tile
storeCurrentTileId={storeCurrentTileId}
service={service}
key={service}
tile={tile}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
fetchTilesStart,
fetchTilesSuccess,
fetchTilesStop,
storeCurrentTileId, fetchNewService,
fetchNewService,
} from '../../actions/catalog-tile-actions';
import {clearService, selectService} from '../../actions/selected-service-actions';
import { filterText, clear } from '../../actions/filter-actions';
Expand All @@ -34,7 +34,6 @@ const mapStateToProps = (state) => ({
refreshedStaticApisError: state.refreshStaticApisReducer.error,
refreshTimestamp: state.refreshStaticApisReducer.refreshTimestamp,
authentication: state.authenticationReducer,
currentTileId: state.tilesReducer.currentTileId,

});

Expand All @@ -51,7 +50,6 @@ const mapDispatchToProps = {
wizardToggleDisplay,
selectEnabler,
closeAlert: () => userActions.closeAlert(),
storeCurrentTileId: (id) => storeCurrentTileId(id),
selectService: (service, tileId) => selectService(service, tileId),
fetchNewService: (id) => fetchNewService(id)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
fetchTilesFailed,
fetchTilesStart,
fetchTilesStop,
fetchTilesSuccess, storeCurrentTileId, fetchNewService, fetchServiceStop, fetchServiceFailed,
fetchTilesSuccess, fetchNewService, fetchServiceStop, fetchServiceFailed,
} from '../../actions/catalog-tile-actions';
import {clearService, selectService} from '../../actions/selected-service-actions';
import { createLoadingSelector } from '../../selectors/selectors';
Expand All @@ -29,7 +29,6 @@ const mapStateToProps = (state) => ({
selectedTile: state.selectedServiceReducer.selectedTile,
selectedService: state.selectedServiceReducer.selectedService,
isLoading: loadingSelector(state),
currentTileId: state.tilesReducer.currentTileId,
authentication: state.authenticationReducer,
service: state.tilesReducer.service,
serviceLoading: state.tilesReducer.serviceLoading,
Expand All @@ -43,7 +42,6 @@ const mapDispatchToProps = (dispatch) => ({
fetchTilesStop: () => dispatch(fetchTilesStop()),
clearService: () => dispatch(clearService()),
selectService: (service, tileId) => dispatch(selectService(service, tileId)),
storeCurrentTileId: (id) => storeCurrentTileId(id),
fetchServiceStop: () => dispatch(fetchServiceStop()),
fetchNewService: (id) => dispatch(fetchNewService(id)),
fetchServiceFailed: (id) => dispatch(fetchServiceFailed(id)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ import { Component } from 'react';
import './InstanceInfo.css';
import Shield from '../ErrorBoundary/Shield/Shield';

export default class InstanceInfo extends Component {
render() {
const { service, selectedVersion, tiles } = this.props;
function InstanceInfo({ service, selectedVersion, tiles }) {

const apiInfo =
service.apis[selectedVersion || service.defaultApiVersion] || service.apis.default;
Expand Down Expand Up @@ -46,5 +44,7 @@ export default class InstanceInfo extends Component {
</div>
</Shield>
);
}

}

export default InstanceInfo;
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ describe('>>> InstanceInfo component tests', () => {
selectedService.apis = {
v1: { apiId: 'zowe.apiml.gateway' },
};
const selectService = jest.fn();
const tiles = [
{
activeServices: 1,
Expand All @@ -32,10 +31,9 @@ describe('>>> InstanceInfo component tests', () => {
];
const instanceInfo = shallow(
<InstanceInfo
selectedService={selectedService}
service={selectedService}
selectedVersion="v1"
tiles={tiles}
selectService={selectService}
/>
);

Expand All @@ -50,10 +48,9 @@ describe('>>> InstanceInfo component tests', () => {
v1: { apiId: 'zowe.apiml.gateway' },
};
selectedService.defaultApiVersion = ['v1'];
const selectService = jest.fn();
const tiles = [{}];
const instanceInfo = shallow(
<InstanceInfo selectedService={selectedService} selectService={selectService} tiles={tiles} />
<InstanceInfo service={selectedService} tiles={tiles} />
);

expect(instanceInfo.find('span').at(1).prop('children')).toEqual('zowe.apiml.gateway');
Expand All @@ -64,10 +61,9 @@ describe('>>> InstanceInfo component tests', () => {
default: { apiId: 'zowe.apiml.gateway' },
};
selectedService.defaultApiVersion = null;
const selectService = jest.fn();
const tiles = [{}];
const instanceInfo = shallow(
<InstanceInfo selectedService={selectedService} selectService={selectService} tiles={tiles} />
<InstanceInfo service={selectedService} tiles={tiles} />
);

expect(instanceInfo.find('span').at(1).prop('children')).toEqual('zowe.apiml.gateway');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import SwaggerContainer from '../Swagger/SwaggerContainer';
import GraphQLContainer from '../GraphQL/GraphQLUIApimlContainer';
import ServiceVersionDiffContainer from '../ServiceVersionDiff/ServiceVersionDiffContainer';

function ServiceTab({isLoading,service}) {
function ServiceTab({service}) {

const containsVersion = () => {
return service && 'apiVersions' in service && service.apiVersions;
Expand All @@ -25,7 +25,6 @@ function ServiceTab({isLoading,service}) {
const [isDialogOpen, setIsDialogOpen] = useState(false);

const basePath = () => {
console.log(service)
if (!service?.basePath) {
if (service?.instances?.[0]?.includes('gateway')) {
// Return the basePath right away, since it's a GW instance (either primary or additional)
Expand Down Expand Up @@ -235,7 +234,7 @@ function ServiceTab({isLoading,service}) {
</div>
)}
{graphqlUrl !== null && <GraphQLContainer graphqlUrl={graphqlUrl} />}
{!isLoading && graphqlUrl === null && selectedVersion !== 'diff' && (
{graphqlUrl === null && selectedVersion !== 'diff' && (
<SwaggerContainer selectedVersion={selectedVersion} />
)}
{graphqlUrl === null && selectedVersion === 'diff' && isDialogOpen && containsVersion() && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,17 @@
* Copyright Contributors to the Zowe Project.
*/
import { connect } from 'react-redux';
import { fetchTilesStop } from '../../actions/catalog-tile-actions';
import { selectService } from '../../actions/selected-service-actions';
import ServiceTab from './ServiceTab';
import {createLoadingSelector} from "../../selectors/selectors";

const loadingSelector = createLoadingSelector(['FETCH_TILES']);
const mapStateToProps = (state) => ({
selectedService: state.selectedServiceReducer.selectedService,
selectedTile: state.selectedServiceReducer.selectedTile,
currentTileId: state.tilesReducer.currentTileId,
services: state.tilesReducer.services,
isLoading: loadingSelector(state),
service: state.tilesReducer.service,
});

const mapDispatchToProps = (dispatch) => ({
fetchTilesStop: () => dispatch(fetchTilesStop()),
selectService: (service, tileId) => dispatch(selectService(service, tileId)),
});


const withRouter = (ServiceTab) =>{
return (props) =>{
return <ServiceTab {...props}/>
}
}

export default withRouter(connect(mapStateToProps, mapDispatchToProps)(ServiceTab));
export default withRouter(connect(mapStateToProps)(ServiceTab));
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,11 @@ describe('ServiceTab Container', () => {
store = mockStore({
tilesReducer: {
tiles,
},
selectedServiceReducer: {
selectedTile: 'tile',
selectedService: {
service: {
serviceId: 'service',
},
},
}
}
});
const history = {
location: {
pathname: {},
},
push: jest.fn(),
listen: jest.fn(),
};
container = render(
<HashRouter>
<Provider store={store}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,6 @@ describe('>>> ServiceNavigationBar component tests', () => {
expect(clear).toHaveBeenCalled();
});

// it('should trigger filterText on handleSearch', async () => {
// const filterText = jest.fn();
// useLocation.mockReturnValue({
// pathname: '/mock/path/1234',
// });
// render(
// <ServicesNavigationBar filterText={filterText} services={[]} currentTileId="apicatalog" clear={jest.fn()}/>
// );
// expect(filterText).toHaveBeenCalled();
// });

it('should display label', () => {
useLocation.mockReturnValue({
Expand All @@ -112,29 +102,5 @@ describe('>>> ServiceNavigationBar component tests', () => {

});

it('should set current tile id', () => {
localStorage.setItem('serviceId', 'apicatalog');
const storeCurrentTileId = jest.fn();
const clear = jest.fn();
useLocation.mockReturnValue({
pathname: '/mock/path/1234',
});
render(<BrowserRouter>
<Routes>
<Route path="*"
element={<ServicesNavigationBar
clear={clear}
services={[tile]}
match={match}
currentTileId="apicatalog"
storeCurrentTileId={storeCurrentTileId}
selectService={jest.fn()}
/>}/>
</Routes>
</BrowserRouter>);
screen.debug();
fireEvent.click(screen.getByText('API Catalog'));

expect(storeCurrentTileId).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { connect } from 'react-redux';
import ServicesNavigationBar from './ServicesNavigationBar';
import { getFilteredServices } from '../../selectors/selectors';
import { clear, filterText } from '../../actions/filter-actions';
import {fetchNewService, storeCurrentTileId} from '../../actions/catalog-tile-actions';
import {fetchNewService} from '../../actions/catalog-tile-actions';
import {selectService} from "../../actions/selected-service-actions";

const mapStateToProps = (state) => ({
Expand All @@ -22,7 +22,6 @@ const mapStateToProps = (state) => ({
const mapDispatchToProps = (dispatch) => ({
filterText: (text) => dispatch(filterText(text)),
clear: () => dispatch(clear()),
storeCurrentTileId: (id) => dispatch(storeCurrentTileId(id)),
selectService: (service, tileId) => dispatch(selectService(service, tileId)),
fetchNewService: (id) => dispatch(fetchNewService(id))
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { connect } from 'react-redux';
import SwaggerUIApiml from './SwaggerUIApiml';

const mapStateToProps = (state) => ({
selectedService: state.selectedServiceReducer.selectedService,
service: state.tilesReducer.service,
tiles: state.tilesReducer.tiles,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ describe('Swagger Container', () => {
let container;
beforeEach(() => {
store = mockStore({
selectedServiceReducer: {
selectedService: {
apis: [],
serviceId: 'service',
},
},
tilesReducer: {
tiles: [{}],
service: {
apis: [],
serviceId: 'service',
}
},
});
container = render(
Expand Down
Loading

0 comments on commit 1ce0c4f

Please sign in to comment.