diff --git a/src/TitleDetails/AddPieceModal/ModalActionButtons/utils.test.js b/src/TitleDetails/AddPieceModal/ModalActionButtons/utils.test.js index 7c7241cf..30459882 100644 --- a/src/TitleDetails/AddPieceModal/ModalActionButtons/utils.test.js +++ b/src/TitleDetails/AddPieceModal/ModalActionButtons/utils.test.js @@ -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({}); @@ -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); + }); + }); });