Skip to content

Commit

Permalink
UICHKIN-398 - Hide 'new fee/fine' menu item for dcb user (#606)
Browse files Browse the repository at this point in the history
* UICHKIN-398 - Hide 'new fee/fine' menu item for dcb user

* UICHKIN-398 - add unit tests

* UICHKIN-398 - hide 'FeeFine details' button when borrower is virtual user, add unit test

* UICHKIN-398 - fix comments
  • Loading branch information
Terala-Priyanka authored Nov 24, 2023
1 parent 8760b10 commit 8874366
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 9.1.0 IN PROGRESS
* Also support `feesfines` interface version `19.0`. Refs UICHKIN-401.
* Hide fee/fine action menu items when requester is virtual user. Refs UICHKIN-398.

## [9.0.1] (https://github.com/folio-org/ui-checkin/tree/v9.0.1) (2023-10-23)
[Full Changelog](https://github.com/folio-org/ui-checkin/compare/v9.0.0...v9.0.1)
Expand Down
5 changes: 4 additions & 1 deletion src/CheckIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import CheckInFooter from './components/CheckInFooter';
import {
convertToSlipData,
getCheckinSettings,
isDcbUser,
} from './util';

import styles from './checkin.css';
Expand Down Expand Up @@ -308,6 +309,7 @@ class CheckIn extends React.Component {
const isCheckInNote = element => element.noteType === 'Check in';
const checkinNotePresent = get(loan.item, ['circulationNotes'], []).some(isCheckInNote);
const loanOpenRequest = loan?.staffSlipContext?.request ?? {};
const isVirtualUser = isDcbUser(loan?.borrower);

const trigger = ({ getTriggerProps, triggerRef }) => (
<IconButton
Expand Down Expand Up @@ -393,12 +395,13 @@ class CheckIn extends React.Component {
}
<IfPermission perm="accounts.collection.get">
<FeeFineDetailsButton
isVirtualUser={isVirtualUser}
userId={loan.userId}
itemId={loan.itemId}
mutator={this.props.mutator}
/>
</IfPermission>
{loan.userId &&
{loan.userId && !isVirtualUser &&
<Button
role="menuitem"
buttonStyle="dropdownItem"
Expand Down
8 changes: 7 additions & 1 deletion src/components/FeeFineDetailsButton/FeeFineDetailsButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const FEE_FINES_STATUSES = {

class FeeFineDetailsButton extends React.Component {
static propTypes = {
isVirtualUser: PropTypes.bool,
userId: PropTypes.string,
itemId: PropTypes.string,
mutator: PropTypes.shape({
Expand Down Expand Up @@ -116,12 +117,13 @@ class FeeFineDetailsButton extends React.Component {
const {
userId,
itemId,
isVirtualUser,
} = this.props;
const {
feeFinesCount,
} = this.state;

return !userId || !itemId || !feeFinesCount;
return isVirtualUser || !userId || !itemId || !feeFinesCount;
};

render() {
Expand All @@ -148,4 +150,8 @@ class FeeFineDetailsButton extends React.Component {
}
}

FeeFineDetailsButton.defaultProps = {
isVirtualUser: false,
};

export default FeeFineDetailsButton;
19 changes: 19 additions & 0 deletions src/components/FeeFineDetailsButton/FeeFineDetailsButton.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { account as accountFixture } from '../../../test/jest/fixtures/account';
import { loan as loanFixture } from '../../../test/jest/fixtures/loan';
import FeeFineDetailsButton from './FeeFineDetailsButton';
import { DCB_USER } from '../../consts';

const mockedQueryUpdate = jest.fn();
const labelIds = {
Expand Down Expand Up @@ -193,4 +194,22 @@ describe('FeeFineDetailsButton', () => {
});
});
});

describe('when borrower is virtual user', () => {
it('should not render FeeFineDetails button', () => {
const alteredLoanFixture = {
...loanFixture,
loan: {
...loanFixture.loan,
borrower: {
...loanFixture.loan.borrower,
lastName: DCB_USER.lastName,
}
}
};
renderFeeFineDetailsButton(alteredLoanFixture, accountFixture);

expect(screen.queryByText(labelIds.feeFineDetails)).toBeNull();
});
});
});
4 changes: 4 additions & 0 deletions src/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ export const cancelFeeClaimReturned = {
};

export const MAX_RECORDS = '1000';

export const DCB_USER = {
lastName: 'DcbSystem',
};
7 changes: 6 additions & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import {
includes,
} from 'lodash';

import { statuses } from './consts';
import {
DCB_USER,
statuses,
} from './consts';

export const escapeValue = (val) => {
if (typeof val === 'string' && val.startsWith('<Barcode>') && val.endsWith('</Barcode>')) {
Expand Down Expand Up @@ -164,4 +167,6 @@ export function shouldConfirmStatusModalBeShown(item) {
], item?.status?.name);
}

export const isDcbUser = (user) => user?.lastName === DCB_USER.lastName;

export default {};
20 changes: 20 additions & 0 deletions src/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import {
escapeValue,
getCheckinSettings,
shouldConfirmStatusModalBeShown,
isDcbUser,
} from './util';

import {
DCB_USER,
statuses,
} from './consts';

Expand Down Expand Up @@ -318,3 +320,21 @@ describe('shouldConfirmStatusModalBeShown', () => {
});
});
});

describe('isDcbUser', () => {
it('should return true when user has lastName as "DcbSystem"', () => {
const user = {
lastName: DCB_USER.lastName,
};

expect(isDcbUser(user)).toBeTruthy();
});

it('should return false when user does not have lastName as "DcbSystem"', () => {
const user = {
lastName: 'test',
};

expect(isDcbUser(user)).toBeFalsy();
});
});

0 comments on commit 8874366

Please sign in to comment.