Skip to content

Commit

Permalink
refactor: hide button for shadow users
Browse files Browse the repository at this point in the history
  • Loading branch information
alisher-epam committed Oct 10, 2023
1 parent 42680c2 commit 71b105f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 56 deletions.
15 changes: 1 addition & 14 deletions src/components/LostItemsLink/LostItemsLink.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import { useHistory } from 'react-router-dom';

Expand All @@ -14,13 +13,9 @@ import {
LOST_ITEM_STATUSES,
} from '../../views/LostItems/constants';

const LostItemsLink = ({ disabled }) => {
const LostItemsLink = () => {
const history = useHistory();

if (disabled) {
return null;
}

return (
<IfPermission perm="ui-users.lost-items.requiring-actual-cost">
<Button
Expand All @@ -43,12 +38,4 @@ const LostItemsLink = ({ disabled }) => {
);
};

LostItemsLink.propTypes = {
disabled: PropTypes.bool,
};

LostItemsLink.defaultProps = {
disabled: false,
};

export default LostItemsLink;
30 changes: 10 additions & 20 deletions src/components/LostItemsLink/LostItemsLink.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,30 @@ const labelIds = {
lostItems: 'ui-users.actionMenu.lostItems',
};

const renderLostItemsLink = ({ disabled = false }) => {
const history = createMemoryHistory();
render(
<Router history={history}>
<LostItemsLink disabled={disabled} />
</Router>
);
};

describe('LostItemsLink', () => {
beforeEach(() => {
const history = createMemoryHistory();

render(
<Router history={history}>
<LostItemsLink />
</Router>
);
});

it('should be rendered', () => {
renderLostItemsLink({ disabled: false });
const lostItemsLink = screen.getByTestId(testIds.lostItemsLink);

expect(lostItemsLink).toBeInTheDocument();
});

it('should have correct label', () => {
renderLostItemsLink({ disabled: false });
const lostItemsLabel = screen.getByText(labelIds.lostItems);

expect(lostItemsLabel).toBeInTheDocument();
});

it('should trigger "Button" with correct props', () => {
renderLostItemsLink({ disabled: false });

const expectedProps = {
buttonStyle: 'dropdownItem',
to: {
Expand All @@ -64,11 +61,4 @@ describe('LostItemsLink', () => {

expect(Button).toHaveBeenCalledWith(expect.objectContaining(expectedProps), {});
});

it('should button be disabled', () => {
renderLostItemsLink({ disabled: true });
const lostItemsLink = screen.queryByRole('button');

expect(lostItemsLink).toBeNull();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class RequestFeeFineBlockButtons extends React.Component {
onToggle: PropTypes.func,
userId: PropTypes.string,
location: PropTypes.object,
disabled: PropTypes.bool,
};

render() {
Expand All @@ -26,14 +25,9 @@ class RequestFeeFineBlockButtons extends React.Component {
onToggle,
userId,
location,
disabled,
} = this.props;
const createRequestUrl = getRequestUrl(barcode, userId);

if (disabled) {
return null;
}

return (
<div data-test-actions-menu>
<IfPermission perm="ui-requests.all">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ describe('RequestFeeFineBlockButtons', () => {
expect(screen.queryByText('ui-users.accounts.chargeManual')).toBeInTheDocument();
expect(screen.queryByText('ui-users.blocks.buttons.add')).toBeInTheDocument();
});

it('should createRequest button to be disabled', () => {
renderRequestFeeFineBlockButtons({ disabled: true });
const buttonElement = screen.queryByRole('button');

expect(buttonElement).toBeNull();
});
});

describe('without ui-requests.all permission', () => {
Expand Down
20 changes: 11 additions & 9 deletions src/views/UserDetail/UserDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,22 +446,24 @@ class UserDetail extends React.Component {
if (showActionMenu) {
return (
<>
<IfInterface name="feesfines">
<RequestFeeFineBlockButtons
barcode={barcode}
onToggle={onToggle}
userId={this.props.match.params.id}
disabled={isShadowUser}
/>
</IfInterface>
{!isShadowUser && (
<IfInterface name="feesfines">
<RequestFeeFineBlockButtons
barcode={barcode}
onToggle={onToggle}
userId={this.props.match.params.id}
disabled={isShadowUser}
/>
</IfInterface>
)}
<ActionMenuEditButton
id={this.props.match.params.id}
suppressList={this.props.resources.suppressEdit}
onToggle={onToggle}
goToEdit={this.goToEdit}
editButton={this.editButton}
/>
<LostItemsLink disabled={isShadowUser} />
{!isShadowUser && <LostItemsLink />}
<IfInterface name="feesfines">
<ExportFeesFinesReportButton
feesFinesReportData={feesFinesReportData}
Expand Down

0 comments on commit 71b105f

Please sign in to comment.