Skip to content

Commit

Permalink
UIREQ-1040 - Hide Actions menu on closed request of DCB Transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
Terala-Priyanka committed Nov 17, 2023
1 parent 7dc3f62 commit 0329503
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 130 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Hide all actions except "Cancel Request" in Action menu (Lending library). Refs UIREQ-1032.
* Hide all actions except "Cancel Request" in Action menu and DCB item links (Borrowing library). Refs UIREQ-1034.
* Hide all actions except "Cancel Request" in Action menu and DCB item links (Pickup library). Refs UIREQ-1035.
* Hide Actions menu on closed request of DCB Transaction. Refs UIREQ-1040.

## [9.0.0](https://github.com/folio-org/ui-requests/tree/v9.0.0) (2023-10-12)
[Full Changelog](https://github.com/folio-org/ui-requests/compare/v8.0.2...v9.0.0)
Expand Down
32 changes: 14 additions & 18 deletions src/ViewRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,32 +513,28 @@ class ViewRequest extends React.Component {
const showActionMenu = stripes.hasPerm('ui-requests.create')
|| stripes.hasPerm('ui-requests.edit')
|| stripes.hasPerm('ui-requests.moveRequest')
|| stripes.hasPerm('ui-requests.reorderQueue');
|| stripes.hasPerm('ui-requests.reorderQueue') || !isDCBTransaction;

const actionMenu = ({ onToggle }) => {
if (isRequestClosed) {
if (!isRequestValid || (requestLevel === REQUEST_LEVEL_TYPES.TITLE && !titleLevelRequestsFeatureEnabled)) {
if (!isRequestValid || (requestLevel === REQUEST_LEVEL_TYPES.TITLE && !titleLevelRequestsFeatureEnabled) || isDCBTransaction) {
return null;
}

return (
<IfPermission perm="ui-requests.create">
{
!isDCBTransaction && (
<Button
id="duplicate-request"
onClick={() => {
onToggle();
this.props.onDuplicate(request);
}}
buttonStyle="dropdownItem"
>
<Icon icon="duplicate">
<FormattedMessage id="ui-requests.actions.duplicateRequest" />
</Icon>
</Button>
)
}
<Button
id="duplicate-request"
onClick={() => {
onToggle();
this.props.onDuplicate(request);
}}
buttonStyle="dropdownItem"
>
<Icon icon="duplicate">
<FormattedMessage id="ui-requests.actions.duplicateRequest" />
</Icon>
</Button>
</IfPermission>
);
}
Expand Down
184 changes: 72 additions & 112 deletions src/ViewRequest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,37 @@ describe('ViewRequest', () => {
},
},
};
const defaultDCBLendingProps = {
...defaultProps,
resources: {
selectedRequest: {
hasLoaded: true,
records: [
mockedRequestWithDCBUser,
],
},
}
};
const defaultDCBBorrowingProps = {
...defaultProps,
resources: {
selectedRequest: {
hasLoaded: true,
records: [
mockedRequestWithVirtualItem,
],
},
}
};
const renderViewRequest = (props) => render(
<CommandList commands={defaultKeyboardShortcuts}>
<ViewRequest {...props} />
</CommandList>
);

describe('Non DCB Transactions', () => {
beforeEach(() => {
render(
<CommandList commands={defaultKeyboardShortcuts}>
<ViewRequest {...defaultProps} />
</CommandList>
);
renderViewRequest(defaultProps);
});

afterEach(() => {
Expand Down Expand Up @@ -212,11 +235,7 @@ describe('ViewRequest', () => {
};

beforeEach(() => {
render(
<CommandList commands={defaultKeyboardShortcuts}>
<ViewRequest {...props} />
</CommandList>
);
renderViewRequest(props);
});

it('should not render "Duplicate" button', () => {
Expand All @@ -243,11 +262,7 @@ describe('ViewRequest', () => {
};

beforeEach(() => {
render(
<CommandList commands={defaultKeyboardShortcuts}>
<ViewRequest {...props} />
</CommandList>
);
renderViewRequest(props);
});

it('actions menu should show all possible actions', () => {
Expand Down Expand Up @@ -277,11 +292,7 @@ describe('ViewRequest', () => {
};

beforeEach(() => {
render(
<CommandList commands={defaultKeyboardShortcuts}>
<ViewRequest {...props} />
</CommandList>
);
renderViewRequest(props);
});

it('should render action menu with only "Cancel request" button', () => {
Expand Down Expand Up @@ -314,54 +325,37 @@ describe('ViewRequest', () => {
});

describe('when virtual patron-DCB Lending flow', () => {
const alteredProps = {
...defaultProps,
resources: {
selectedRequest: {
hasLoaded: true,
records: [
mockedRequestWithDCBUser,
],
},
}
};

describe('when in request detail', () => {
beforeAll(() => {
mockedLocation.search = null;
});

describe('when current lending request is closed', () => {
const openValidRequest = {
describe("when current lending request status starts with 'Closed'", () => {
const closedStatuses = [requestStatuses.FILLED, requestStatuses.CANCELLED, requestStatuses.PICKUP_EXPIRED, requestStatuses.UNFILLED];
const closedRequests = closedStatuses.map(cStatus => ({
...mockedRequestWithDCBUser,
status: requestStatuses.FILLED,
};

const props = {
...alteredProps,
status: cStatus,
}));
const closedRequestsProps = closedRequests.map(cReq => ({
...defaultDCBLendingProps,
resources: {
selectedRequest: {
hasLoaded: true,
records: [
{
...alteredProps.resources.selectedRequest.records,
...openValidRequest,
...defaultDCBLendingProps.resources.selectedRequest.records,
...cReq,
},
],
},
},
};

beforeEach(() => {
render(
<CommandList commands={defaultKeyboardShortcuts}>
<ViewRequest {...props} />
</CommandList>
);
});
}
}));

it('should not render "Duplicate" button', () => {
expect(screen.queryByText(labelIds.duplicateRequest)).not.toBeInTheDocument();
closedRequestsProps.forEach(props => {
it(`should not render action menu when request status is ${props?.resources?.selectedRequest?.records[0]?.status}`, () => {
renderViewRequest(props);
expect(screen.queryByRole('button', { name: 'Actions' })).toBeNull();
});
});
});

Expand All @@ -372,13 +366,13 @@ describe('ViewRequest', () => {
};

const props = {
...alteredProps,
...defaultDCBLendingProps,
resources: {
selectedRequest: {
hasLoaded: true,
records: [
{
...alteredProps.resources.selectedRequest.records,
...defaultDCBLendingProps.resources.selectedRequest.records,
...openValidRequest,
},
],
Expand All @@ -387,11 +381,7 @@ describe('ViewRequest', () => {
};

beforeEach(() => {
render(
<CommandList commands={defaultKeyboardShortcuts}>
<ViewRequest {...props} />
</CommandList>
);
renderViewRequest(props);
});

it('should render action menu with only "Cancel request" button', () => {
Expand All @@ -406,11 +396,7 @@ describe('ViewRequest', () => {

describe('Keyboard shortcuts', () => {
beforeEach(() => {
render(
<CommandList commands={defaultKeyboardShortcuts}>
<ViewRequest {...alteredProps} />
</CommandList>
);
renderViewRequest(defaultDCBLendingProps);
});
it('should check permission when duplicating', () => {
duplicateRecordShortcut(document.body);
Expand All @@ -425,71 +411,53 @@ describe('ViewRequest', () => {
});

describe('when virtual item-DCB Borrowing flow', () => {
const alteredProps = {
...defaultProps,
resources: {
selectedRequest: {
hasLoaded: true,
records: [
mockedRequestWithVirtualItem,
],
},
}
};

describe('when in request detail', () => {
beforeAll(() => {
mockedLocation.search = null;
});

describe('when current lending request is closed', () => {
const openValidRequest = {
describe('when current borrowing request status starts with "Closed"', () => {
const closedStatuses = [requestStatuses.FILLED, requestStatuses.CANCELLED, requestStatuses.PICKUP_EXPIRED, requestStatuses.UNFILLED];
const closedRequests = closedStatuses.map(cStatus => ({
...mockedRequestWithDCBUser,
status: requestStatuses.FILLED,
};

const props = {
...alteredProps,
status: cStatus,
}));
const closedRequestsProps = closedRequests.map(cReq => ({
...defaultDCBBorrowingProps,
resources: {
selectedRequest: {
hasLoaded: true,
records: [
{
...alteredProps.resources.selectedRequest.records,
...openValidRequest,
...defaultDCBBorrowingProps.resources.selectedRequest.records,
...cReq,
},
],
},
},
};

beforeEach(() => {
render(
<CommandList commands={defaultKeyboardShortcuts}>
<ViewRequest {...props} />
</CommandList>
);
});

it('should not render "Duplicate" button', () => {
expect(screen.queryByText(labelIds.duplicateRequest)).not.toBeInTheDocument();
}
}));
closedRequestsProps.forEach(props => {
it(`should not render action menu when request status is ${props?.resources?.selectedRequest?.records[0]?.status}`, () => {
renderViewRequest(props);
expect(screen.queryByRole('button', { name: 'Actions' })).toBeNull();
});
});
});

describe('when current lending request is open', () => {
describe('when current borrowing request is open', () => {
const openValidRequest = {
...mockedRequestWithDCBUser,
status: requestStatuses.NOT_YET_FILLED,
};

const props = {
...alteredProps,
...defaultDCBBorrowingProps,
resources: {
selectedRequest: {
hasLoaded: true,
records: [
{
...alteredProps.resources.selectedRequest.records,
...defaultDCBBorrowingProps.resources.selectedRequest.records,
...openValidRequest,
},
],
Expand All @@ -498,11 +466,7 @@ describe('ViewRequest', () => {
};

beforeEach(() => {
render(
<CommandList commands={defaultKeyboardShortcuts}>
<ViewRequest {...props} />
</CommandList>
);
renderViewRequest(props);
});

it('should render action menu with only "Cancel request" button', () => {
Expand All @@ -517,11 +481,7 @@ describe('ViewRequest', () => {

describe('Keyboard shortcuts', () => {
beforeEach(() => {
render(
<CommandList commands={defaultKeyboardShortcuts}>
<ViewRequest {...alteredProps} />
</CommandList>
);
renderViewRequest(defaultDCBBorrowingProps);
});
it('should check permission when duplicating', () => {
duplicateRecordShortcut(document.body);
Expand Down

0 comments on commit 0329503

Please sign in to comment.