Skip to content

Commit

Permalink
test: add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
alisher-epam committed Dec 14, 2023
1 parent ad8dcef commit 23a4176
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion src/TitleDetails/AddPieceModal/ModalActionButtons/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { PIECE_ACTIONS_BY_STATUS, PIECE_STATUS } from './constants';
import { getPieceActionMenu } from './utils';

const { expected, unReceivable, received } = PIECE_STATUS;

describe('getPieceActionMenus', () => {
it('should return empty array if status is not provided', () => {
const result = getPieceActionMenu({});
Expand All @@ -15,9 +17,59 @@ describe('getPieceActionMenus', () => {
});

it('should return array of action menus', () => {
const { expected } = PIECE_STATUS;
const result = getPieceActionMenu({ status: expected, disabled: false });

expect(result).toHaveLength(PIECE_ACTIONS_BY_STATUS[expected].length);
});

describe('delete action', () => {
it('should not return `delete` action menu if `isEditMode` is false', () => {
const result = getPieceActionMenu({ status: expected, disabled: false, isEditMode: false });

expect(result).toContain(null);
});

it('should `delete` button be disabled if `canDeletePiece` is false', () => {
const result = getPieceActionMenu({ status: expected, disabled: false, isEditMode: true, canDeletePiece: false });
const deleteButton = result.find(i => i.props['data-testid'] === 'delete-piece-button');

expect(deleteButton.props).toEqual(expect.objectContaining({ disabled: true }));
});
});

describe('expect action', () => {
it('should `onStatusChange` be called with `Expected` status value', () => {
const onStatusChange = jest.fn();
const result = getPieceActionMenu({ status: unReceivable, disabled: true, onStatusChange });
const expectButton = result.find(i => i.props['data-testid'] === 'expect-piece-button');

expectButton.props.onClick();

expect(onStatusChange).toHaveBeenCalledWith(PIECE_STATUS.expected);
});
});

describe('unReceive action', () => {
it('should `onStatusChange` be called with `Expected` status value', () => {
const onStatusChange = jest.fn();
const result = getPieceActionMenu({ status: received, disabled: false, onStatusChange });
const receiveButton = result.find(i => i.props['data-testid'] === 'unReceive-piece-button');

receiveButton.props.onClick();

expect(onStatusChange).toHaveBeenCalledWith(PIECE_STATUS.expected);
});
});

describe('unReceivable action', () => {
it('should `onStatusChange` be called with `Unreceivable` status value', () => {
const onStatusChange = jest.fn();
const result = getPieceActionMenu({ status: expected, disabled: false, onStatusChange });
const receiveButton = result.find(i => i.props['data-testid'] === 'unReceivable-piece-button');

receiveButton.props.onClick();

expect(onStatusChange).toHaveBeenCalledWith(PIECE_STATUS.unReceivable);
});
});
});

0 comments on commit 23a4176

Please sign in to comment.