|
| 1 | +import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations'; |
| 2 | +import { DATE_AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/DateAggregateOperations'; |
| 3 | +import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2'; |
| 4 | +import { useUpdateView } from '@/views/hooks/useUpdateView'; |
| 5 | +import { renderHook } from '@testing-library/react'; |
| 6 | +import { useSetRecoilState } from 'recoil'; |
| 7 | +import { useUpdateViewAggregate } from '../useUpdateViewAggregate'; |
| 8 | + |
| 9 | +jest.mock( |
| 10 | + '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2', |
| 11 | +); |
| 12 | +jest.mock('@/views/hooks/useUpdateView'); |
| 13 | +jest.mock('recoil'); |
| 14 | + |
| 15 | +describe('useUpdateViewAggregate', () => { |
| 16 | + const mockCurrentViewId = 'test-view-id'; |
| 17 | + const mockUpdateView = jest.fn(); |
| 18 | + const mockSetRecordIndexKanbanAggregateOperationState = jest.fn(); |
| 19 | + |
| 20 | + beforeEach(() => { |
| 21 | + jest.clearAllMocks(); |
| 22 | + (useRecoilComponentValueV2 as jest.Mock).mockReturnValue(mockCurrentViewId); |
| 23 | + (useUpdateView as jest.Mock).mockReturnValue({ |
| 24 | + updateView: mockUpdateView, |
| 25 | + }); |
| 26 | + (useSetRecoilState as jest.Mock).mockReturnValue( |
| 27 | + mockSetRecordIndexKanbanAggregateOperationState, |
| 28 | + ); |
| 29 | + }); |
| 30 | + |
| 31 | + describe('Aggregate operations on dates', () => { |
| 32 | + it('should update view with rightfully converted values', () => { |
| 33 | + const { result } = renderHook(() => useUpdateViewAggregate()); |
| 34 | + |
| 35 | + result.current.updateViewAggregate({ |
| 36 | + kanbanAggregateOperationFieldMetadataId: 'test-field-id', |
| 37 | + kanbanAggregateOperation: DATE_AGGREGATE_OPERATIONS.earliest, |
| 38 | + }); |
| 39 | + |
| 40 | + // updateView is called with 'EARLIEST' converted to 'MIN' |
| 41 | + expect(mockUpdateView).toHaveBeenCalledWith({ |
| 42 | + id: mockCurrentViewId, |
| 43 | + kanbanAggregateOperationFieldMetadataId: 'test-field-id', |
| 44 | + kanbanAggregateOperation: AGGREGATE_OPERATIONS.min, |
| 45 | + }); |
| 46 | + |
| 47 | + // setAggregateOperation is called with 'EARLIEST' |
| 48 | + expect( |
| 49 | + mockSetRecordIndexKanbanAggregateOperationState, |
| 50 | + ).toHaveBeenCalledWith({ |
| 51 | + operation: DATE_AGGREGATE_OPERATIONS.earliest, |
| 52 | + fieldMetadataId: 'test-field-id', |
| 53 | + }); |
| 54 | + }); |
| 55 | + }); |
| 56 | +}); |
0 commit comments