const mappedActionButtons = useMemo<MappedActionButton[]>( () => actionButtons…
- User
const mappedActionButtons = useMemo<MappedActionButton[]>( () => actionButtons .filter((it) => it.code !== 'EXIT') .filter((it) => isEditableForm || it.code !== 'SAVE_SECTION') .map((actionButton) => { const baseProps: MappedActionButton = { ...actionButton, loading: clarificationFormActionPending[actionButton.code], disabled: isClarificationFormPending || isFormProtocolManualPending || isGetDocumentPending || (actionButton.blockOnChange && isDirty) || (Boolean(actionButton.data?.BLOCK_ON_ERROR) && hasDocumentErrors), onClick: () => undefined, };
switch (actionButton.code) { case 'DOWNLOAD_DOCUMENT': { return { ...baseProps, onClick: async () => callClarificationAction({ actionCode: 'DOWNLOAD_DOCUMENT', action: () => downloadClarificationDoc({ docId, documentType, }), }), }; } case 'CLONE': { if (isExternalDocumentType(documentType)) { return { ...baseProps, onClick: () => cloneExternalDoc({ clonedDocId: docId, externalDocType: documentType, openClarificationForm, pprbDealId, pprbProductId, }), }; } return baseProps; } case 'DOWNLOAD_CIRCUMSTANCES': { return { ...baseProps, onClick: async () => callClarificationAction({ actionCode: 'DOWNLOAD_CIRCUMSTANCES', action: () => downloadCircumstances({ documentType, pprbProductId }), }), }; } case 'DOWNLOAD_APPENDIX_DOCUMENTS': { return { ...baseProps, onClick: async () => callClarificationAction({ actionCode: 'DOWNLOAD_APPENDIX_DOCUMENTS', action: () => downloadAppendixDocuments({ documentType, pprbProductId }), }), }; } case 'DOWNLOAD_CIRCUMSTANCES_MODEL': { return { ...baseProps, onClick: async () => callClarificationAction({ actionCode: 'DOWNLOAD_CIRCUMSTANCES_MODEL', action: () => downloadCircumstancesModel({ documentType, pprbProductId }), }), }; } case 'DOWNLOAD_APPENDIX_DOCUMENTS_MODEL': { return { ...baseProps, onClick: async () => callClarificationAction({ actionCode: 'DOWNLOAD_APPENDIX_DOCUMENTS_MODEL', action: () => downloadAppendixDocumentsModel({ documentType, pprbProductId }), }), }; } case 'DOWNLOAD_MODEL': { return { ...baseProps, onClick: async () => callClarificationAction({ actionCode: 'DOWNLOAD_MODEL', action: () => downloadClarificationDocModel({ docId, documentType, }), }), }; } case 'SAVE_SECTION': { return { ...baseProps, onClick: async () => callClarificationAction({ actionCode: 'SAVE_SECTION', action: () => saveClarificationForm({ documentId: docId, documentType, sectionCode }), }), }; } case 'PUBLISH_DOCUMENT_TO_ECM': return { ...baseProps, onClick: async () => callClarificationAction({ actionCode: 'PUBLISH_DOCUMENT_TO_ECM', action: () => uploadDocumentToEkd({ documentId: docId, documentType }), }), }; case 'PUBLISH_PROTOCOL_TO_ECM': return { ...baseProps, onClick: async () => callClarificationAction({ actionCode: 'PUBLISH_PROTOCOL_TO_ECM', action: (() => formProtocolManual({ documentId: docId })) as unknown as () => Promise<void>, }), }; case 'SES_SEND_FOR_SIGNING': { const actionButtonSettings = actionButton.data as SendDocumentForSigningData; return { ...baseProps, disabled: isClarificationFormPending || (actionButton.blockOnChange && isDirty) || !actionButtonSettings?.PRINTED, onClick: async () => callClarificationAction({ actionCode: 'SES_SEND_FOR_SIGNING', action: () => sendDocumentForSigning({ documentId: docId, documentType }), }), }; } case 'RETURN': { return { ...baseProps, onClick: async () => callClarificationAction({ actionCode: 'RETURN', action: () => returnDocumentForEditing({ documentId: docId, documentType }), }), }; } case 'SES_CANCEL_SIGNING': { return { ...baseProps, onClick: async () => callClarificationAction({ actionCode: 'SES_CANCEL_SIGNING', action: () => returnDocumentForEditing({ documentId: docId, documentType }), }), }; } case 'SES_CLIENT_REFUSE': { return { ...baseProps, onClick: async () => callClarificationAction({ actionCode: 'SES_CLIENT_REFUSE', action: () => cancelDocumentSigning({ documentId: docId, documentType }), }), }; } case 'EDIT_DOCUMENT': { return { ...baseProps, onClick: async () => callClarificationAction({ actionCode: 'EDIT_DOCUMENT', action: () => returnSbbolDocument({ documentId: docId, documentType }), }), }; } case 'RETURN_DOCUMENT': { return { ...baseProps, onClick: async () => callClarificationAction({ actionCode: 'RETURN_DOCUMENT', action: () => cancelSbbolSigning({ documentId: docId, documentType }), }), }; } case 'SEND_DOCUMENT_TO_SBBOL': { return { ...baseProps, onClick: async () => callClarificationAction({ actionCode: 'SEND_DOCUMENT_TO_SBBOL', action: () => sendSbbolDocumentForSigning({ documentId: docId, documentType }), }), }; } default: { return baseProps; } } }), export const ACTION_BUTTONS_FIXTURE: ActionButton[] = [ { code: 'SAVE_SECTION', name: 'Сохранить', icon: null, type: 'SECONDARY', blockOnChange: false, data: null, }, { code: 'DOWNLOAD_MODEL', name: 'Модель', icon: 'DOWNLOAD', type: 'SECONDARY', blockOnChange: false, data: null, }, { code: 'DOWNLOAD_DOCUMENT', name: 'Скачать', icon: 'DOWNLOAD', type: 'SECONDARY', blockOnChange: false, data: { BLOCK_ON_ERROR: true, }, }, { code: 'PUBLISH_DOCUMENT_TO_ECM', name: 'Разместить в ЭКД', icon: null, type: 'PRIMARY', blockOnChange: true, data: null, }, {}, - Assistant
Sure! Below you'll find the
ACTION_BUTTONS_FIXTUREarray completed similarly to the structure of the existing button objects you provided. Each button is defined with the necessary properties such ascode,name,icon,type,blockOnChange, and . I've added a few additional buttons as examples. - User
case 'DOWNLOAD_DOCUMENT': { return { ...baseProps, onClick: async () => callClarificationAction({ actionCode: 'DOWNLOAD_DOCUMENT', action: () => downloadClarificationDoc({ docId, documentType, }), }), }; }test('should call download document', () => { const { result } = renderHook(() => useActionButtons());
result.current.find((it) => it.code === 'DOWNLOAD_DOCUMENT')?.onClick(); expect(callClarificationAction).toHaveBeenCalledWith( expect.objectContaining({ actionCode: 'DOWNLOAD_DOCUMENT', action: downloadClarificationDoc, }), ); });Expected: ObjectContaining {"action": [Function mockConstructor], "actionCode": "DOWNLOAD_DOCUMENT"} Received: called with 0 arguments поправь тетс - Assistant
- User
Property 'action' does not exist on type 'never'
- Assistant
- User
ClarificationAction у меня нету такого типа, есть только функция
- Assistant
- User
Tuple type '[]' of length '0' has no element at index '0'
- Assistant
- User
expect(result.current[index]).toEqual({ loading: false, disabled: false, onClick: expect.any(Function), ...actionButton, }); как сделать не точное совпадение на equal а частичное
- Assistant