First batch of modules/activities tests (#4446)
Co-authored-by: gitstart-twenty <gitstart-twenty@users.noreply.github.com> Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Matheus <matheus_benini@hotmail.com> Co-authored-by: Thiago Nascimbeni <tnascimbeni@gmail.com>
This commit is contained in:
@ -0,0 +1,51 @@
|
||||
import { renderHook } from '@testing-library/react';
|
||||
|
||||
import { useAttachments } from '../useAttachments';
|
||||
|
||||
jest.mock('@/object-record/hooks/useFindManyRecords', () => ({
|
||||
useFindManyRecords: jest.fn(),
|
||||
}));
|
||||
|
||||
describe('useAttachments', () => {
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('fetches attachments correctly for a given targetableObject', () => {
|
||||
const mockAttachments = [
|
||||
{ id: '1', name: 'Attachment 1' },
|
||||
{ id: 2, name: 'Attachment 2' },
|
||||
];
|
||||
const mockTargetableObject = {
|
||||
id: '1',
|
||||
targetObjectNameSingular: 'SomeObject',
|
||||
};
|
||||
|
||||
const useFindManyRecordsMock = jest.requireMock(
|
||||
'@/object-record/hooks/useFindManyRecords',
|
||||
);
|
||||
useFindManyRecordsMock.useFindManyRecords.mockReturnValue({
|
||||
records: mockAttachments,
|
||||
});
|
||||
|
||||
const { result } = renderHook(() => useAttachments(mockTargetableObject));
|
||||
|
||||
expect(result.current.attachments).toEqual(mockAttachments);
|
||||
});
|
||||
|
||||
it('handles case when there are no attachments', () => {
|
||||
const mockTargetableObject = {
|
||||
id: '1',
|
||||
targetObjectNameSingular: 'SomeObject',
|
||||
};
|
||||
|
||||
const useFindManyRecordsMock = jest.requireMock(
|
||||
'@/object-record/hooks/useFindManyRecords',
|
||||
);
|
||||
useFindManyRecordsMock.useFindManyRecords.mockReturnValue({ records: [] });
|
||||
|
||||
const { result } = renderHook(() => useAttachments(mockTargetableObject));
|
||||
|
||||
expect(result.current.attachments).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user