Fix aggregate operation update on dates on kanban views (#12115)

Fixes https://github.com/twentyhq/core-team-issues/issues/968
This commit is contained in:
Marie
2025-05-19 13:19:38 +01:00
committed by GitHub
parent 52ad789e7a
commit a8753113a7
2 changed files with 57 additions and 1 deletions

View File

@ -0,0 +1,56 @@
import { AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/AggregateOperations';
import { DATE_AGGREGATE_OPERATIONS } from '@/object-record/record-table/constants/DateAggregateOperations';
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';
import { useUpdateView } from '@/views/hooks/useUpdateView';
import { renderHook } from '@testing-library/react';
import { useSetRecoilState } from 'recoil';
import { useUpdateViewAggregate } from '../useUpdateViewAggregate';
jest.mock(
'@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2',
);
jest.mock('@/views/hooks/useUpdateView');
jest.mock('recoil');
describe('useUpdateViewAggregate', () => {
const mockCurrentViewId = 'test-view-id';
const mockUpdateView = jest.fn();
const mockSetRecordIndexKanbanAggregateOperationState = jest.fn();
beforeEach(() => {
jest.clearAllMocks();
(useRecoilComponentValueV2 as jest.Mock).mockReturnValue(mockCurrentViewId);
(useUpdateView as jest.Mock).mockReturnValue({
updateView: mockUpdateView,
});
(useSetRecoilState as jest.Mock).mockReturnValue(
mockSetRecordIndexKanbanAggregateOperationState,
);
});
describe('Aggregate operations on dates', () => {
it('should update view with rightfully converted values', () => {
const { result } = renderHook(() => useUpdateViewAggregate());
result.current.updateViewAggregate({
kanbanAggregateOperationFieldMetadataId: 'test-field-id',
kanbanAggregateOperation: DATE_AGGREGATE_OPERATIONS.earliest,
});
// updateView is called with 'EARLIEST' converted to 'MIN'
expect(mockUpdateView).toHaveBeenCalledWith({
id: mockCurrentViewId,
kanbanAggregateOperationFieldMetadataId: 'test-field-id',
kanbanAggregateOperation: AGGREGATE_OPERATIONS.min,
});
// setAggregateOperation is called with 'EARLIEST'
expect(
mockSetRecordIndexKanbanAggregateOperationState,
).toHaveBeenCalledWith({
operation: DATE_AGGREGATE_OPERATIONS.earliest,
fieldMetadataId: 'test-field-id',
});
});
});
});

View File

@ -36,7 +36,7 @@ export const useUpdateViewAggregate = () => {
});
setRecordIndexKanbanAggregateOperationState({
operation: convertedKanbanAggregateOperation,
operation: kanbanAggregateOperation,
fieldMetadataId: kanbanAggregateOperationFieldMetadataId,
});
},