Skip to content

Commit

Permalink
chore: revert back unused code in UI (#3143)
Browse files Browse the repository at this point in the history
* fix code smells

Signed-off-by: at670475 <[email protected]>

* revert back changes

Signed-off-by: at670475 <[email protected]>

---------

Signed-off-by: at670475 <[email protected]>
  • Loading branch information
taban03 authored Oct 16, 2023
1 parent 52d2cfa commit 620f670
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 84 deletions.
7 changes: 1 addition & 6 deletions api-catalog-ui/frontend/src/actions/user-actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import userConstants from '../constants/user-constants';
import { userService } from '../services';
import history from '../helpers/history';
import { isAPIPortal } from '../utils/utilFunctions';

function login(credentials) {
function request(user) {
Expand Down Expand Up @@ -42,11 +41,7 @@ function login(credentials) {
showUpdatePassSuccess = true;
}
dispatch(success(token, showUpdatePassSuccess));
let path = '/dashboard';
if (isAPIPortal()) {
path = '/homepage';
}
history.push(path);
history.push('/dashboard');
},
(error) => {
if (error.messageNumber === 'ZWEAT413E') {
Expand Down
18 changes: 0 additions & 18 deletions api-catalog-ui/frontend/src/actions/user-actions.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,6 @@ describe('>>> User actions tests', () => {
expect(dispatch.mock.calls[0][0]).toStrictEqual(expectedAction);
});

it('should use portal routing', async () => {
process.env.REACT_APP_API_PORTAL = true;
const dispatch = jest.fn();
const expectedAction = { type: 'USERS_LOGIN_REQUEST', user: { password: 'password', username: 'user' } };

userService.login = jest.fn().mockResolvedValue('token');

const pushSpy = jest.spyOn(history, 'push');

await userActions.login(credentials)(dispatch);

expect(dispatch.mock.calls[0][0]).toStrictEqual(expectedAction);

expect(pushSpy).toHaveBeenCalledWith('/homepage');

pushSpy.mockRestore();
});

it('should use normal routing', async () => {
const dispatch = jest.fn();
const expectedAction = { type: 'USERS_LOGIN_REQUEST', user: { password: 'password', username: 'user' } };
Expand Down
8 changes: 2 additions & 6 deletions api-catalog-ui/frontend/src/components/App/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@ class App extends Component {
render() {
const { history } = this.props;
const isLoading = true;
let headerPath = '/(dashboard|service/.*)/';
let dashboardPath = '/dashboard';
if (isAPIPortal()) {
headerPath = '/(homepage|service/.*)/';
dashboardPath = '/homepage';
}
const headerPath = '/(dashboard|service/.*)/';
const dashboardPath = '/dashboard';
return (
<div className="App">
<BigShield history={history}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ export default class DetailPage extends Component {
// eslint-disable-next-line react/sort-comp
handleGoBack = () => {
const { history } = this.props;
let path = '/dashboard';
if (isAPIPortal()) {
path = '/homepage';
}
history.push(path);
history.push('/dashboard');
};

handleLinkClick = (e, id) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { Typography, Button } from '@material-ui/core';
import ArrowBackIosNewIcon from '@material-ui/icons/ArrowBackIos';
import PropTypes from 'prop-types';
import './BigShield.css';
import { isAPIPortal } from '../../../utils/utilFunctions';

export default class BigShield extends Component {
constructor(props) {
Expand All @@ -33,20 +32,13 @@ export default class BigShield extends Component {
handleGoToHome = () => {
const { history } = this.props;
this.setState({ error: null });
let path = '/dashboard';
if (isAPIPortal()) {
path = '/homepage';
}
history.push(path);
history.push('/dashboard');
};

render() {
const iconBack = <ArrowBackIosNewIcon />;
const { history } = this.props;
let path = '/dashboard';
if (isAPIPortal()) {
path = '/homepage';
}
const path = '/dashboard';
let disableButton = true;
if (history !== undefined && history !== null) {
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,31 +57,6 @@ describe('>>> BigShield component tests', () => {
expect(container.textContent).toMatch(errorMessageMatch);
});

it('Should go back to portal homepage when enabled', () => {
process.env.REACT_APP_API_PORTAL = true;
const historyMock = { push: jest.fn() };

const container = document.createElement('div');
act(() => {
render(
<BigShield history={historyMock}>
<Child history={historyMock} />
</BigShield>,
container
);
});

const button = container.querySelector('button');

expect(button.textContent).toBe('Go to Dashboard');

act(() => {
button.dispatchEvent(new MouseEvent('click', { bubbles: true }));
});

expect(historyMock.push).toHaveBeenCalledWith('/homepage');
});

it('Should go back to dashboard', () => {
const historyMock = { push: jest.fn() };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,11 @@ import { Component } from 'react';
import { IconButton, Typography } from '@material-ui/core';
import ChevronLeftIcon from '@material-ui/icons/ChevronLeft';
import PropTypes from 'prop-types';
import { isAPIPortal } from '../../utils/utilFunctions';

export default class PageNotFound extends Component {
handleGoToHome = () => {
const { history } = this.props;
let path = '/dashboard';
if (isAPIPortal()) {
path = '/homepage';
}
history.push(path);
history.push('/dashboard');
};

render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,4 @@ describe('>>> Detailed Page component tests', () => {
wrapper.find('[data-testid="go-home-button"]').simulate('click');
expect(historyMock.push.mock.calls[0]).toEqual(['/dashboard']);
});

it('should handle a dashboard button click when portal enabled', () => {
process.env.REACT_APP_API_PORTAL = true;
const historyMock = { push: jest.fn() };
const wrapper = shallow(<PageNotFound history={historyMock} />);
wrapper.find('[data-testid="go-home-button"]').simulate('click');
expect(historyMock.push.mock.calls[0]).toEqual(['/homepage']);
});
});

0 comments on commit 620f670

Please sign in to comment.