Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
usavkov-epam committed Dec 18, 2024
1 parent 9e29736 commit 340e7c7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/TitleDetails/TitleDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,10 @@ const TitleDetails = ({

const expectedPiecesActions = useMemo(() => (
<TitleDetailsExpectedActions
actionsHidden={expectedPiecesProtectedActions}
applyFilters={applyExpectedPiecesFilters}
filters={expectedPiecesFilters}
hasReceive={hasReceive}
hiddenActions={expectedPiecesProtectedActions}
openReceiveList={onReceivePieces}
onPieceCreate={onPieceCreate}
titleId={titleId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import {
} from '../../Piece';

export function TitleDetailsExpectedActions({
actionsDisabled,
actionsHidden,
applyFilters,
disabledActions,
filters,
hiddenActions,
onPieceCreate,
openReceiveList,
hasReceive,
Expand All @@ -48,27 +48,27 @@ export function TitleDetailsExpectedActions({
label={intl.formatMessage({ id: 'stripes-components.paneMenuActionsToggleLabel' })}
id="expected-pieces-menu-actions"
>
{(!hiddenActions?.[EXPECTED_PIECES_ACTION_NAMES.addPiece]) && (
{(!actionsHidden?.[EXPECTED_PIECES_ACTION_NAMES.addPiece]) && (
<Button
data-testid="add-piece-button"
data-test-add-piece-button
buttonStyle="dropdownItem"
onClick={onPieceCreate}
disabled={disabledActions?.[EXPECTED_PIECES_ACTION_NAMES.addPiece]}
disabled={actionsDisabled?.[EXPECTED_PIECES_ACTION_NAMES.addPiece]}
>
<Icon size="small" icon="plus-sign">
<FormattedMessage id="ui-receiving.piece.button.addPiece" />
</Icon>
</Button>
)}

{(!hiddenActions?.[EXPECTED_PIECES_ACTION_NAMES.receive]) && (
{(!actionsHidden?.[EXPECTED_PIECES_ACTION_NAMES.receive]) && (
<Button
data-testid="receive-button"
data-test-title-receive-button
buttonStyle="dropdownItem"
onClick={openReceiveList}
disabled={disabledActions?.[EXPECTED_PIECES_ACTION_NAMES.receive]}
disabled={actionsDisabled?.[EXPECTED_PIECES_ACTION_NAMES.receive]}
>
<Icon size="small" icon="receive">
<FormattedMessage id="ui-receiving.title.details.button.receive" />
Expand Down Expand Up @@ -100,11 +100,11 @@ export function TitleDetailsExpectedActions({
}

TitleDetailsExpectedActions.propTypes = {
actionsDisabled: PropTypes.object,
actionsHidden: PropTypes.object,
applyFilters: PropTypes.func.isRequired,
disabledActions: PropTypes.object,
filters: PropTypes.object.isRequired,
hasReceive: PropTypes.bool.isRequired,
hiddenActions: PropTypes.object,
onPieceCreate: PropTypes.func.isRequired,
openReceiveList: PropTypes.func.isRequired,
toggleColumn: PropTypes.func.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import {
} from '@folio/jest-config-stripes/testing-library/react';
import user from '@folio/jest-config-stripes/testing-library/user-event';

import { EXPECTED_PIECE_VISIBLE_COLUMNS } from '../../Piece';
import {
EXPECTED_PIECE_VISIBLE_COLUMNS,
EXPECTED_PIECES_ACTION_NAMES,
} from '../../Piece';
import { TitleDetailsExpectedActions } from './TitleDetailsExpectedActions';

const defaultProps = {
Expand Down Expand Up @@ -57,23 +60,55 @@ describe('TitleDetailsExpectedActions', () => {

it('should not call openReceiveList when receive button is pressed and actions are disabled', async () => {
defaultProps.openReceiveList.mockClear();
renderTitleDetailsExpectedActions({ ...defaultProps, disabled: true });
renderTitleDetailsExpectedActions({
actionsDisabled: {
[EXPECTED_PIECES_ACTION_NAMES.receive]: true,
},
});

await user.click(screen.getByTestId('expected-pieces-action-dropdown'));
await user.click(screen.getByTestId('receive-button'));

expect(defaultProps.openReceiveList).not.toHaveBeenCalled();
});

it('should not render "Receive" button when the action is hidden', async () => {
renderTitleDetailsExpectedActions({
actionsHidden: {
[EXPECTED_PIECES_ACTION_NAMES.receive]: true,
},
});

await user.click(screen.getByTestId('expected-pieces-action-dropdown'));

expect(screen.queryByTestId('receive-button')).not.toBeInTheDocument();
});

it('should not call onPieceCreate when add piece button is pressed and actions are disabled', async () => {
defaultProps.onPieceCreate.mockClear();
renderTitleDetailsExpectedActions({ ...defaultProps, disabled: true });
renderTitleDetailsExpectedActions({
actionsDisabled: {
[EXPECTED_PIECES_ACTION_NAMES.addPiece]: true,
},
});

await user.click(screen.getByTestId('expected-pieces-action-dropdown'));
await user.click(screen.getByTestId('add-piece-button'));

expect(defaultProps.onPieceCreate).not.toHaveBeenCalled();
});

it('should not render "Add piece" button when the action is hidden', async () => {
renderTitleDetailsExpectedActions({
actionsHidden: {
[EXPECTED_PIECES_ACTION_NAMES.addPiece]: true,
},
});

await user.click(screen.getByTestId('expected-pieces-action-dropdown'));

expect(screen.queryByTestId('add-piece-button')).not.toBeInTheDocument();
});
});

describe('TitleDetailsExpectedActions filters', () => {
Expand Down

0 comments on commit 340e7c7

Please sign in to comment.