Skip to content

Commit a875311

Browse files
authored
Fix aggregate operation update on dates on kanban views (#12115)
Fixes twentyhq/core-team-issues#968
1 parent 52ad789 commit a875311

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
});

packages/twenty-front/src/modules/views/hooks/useUpdateViewAggregate.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const useUpdateViewAggregate = () => {
3636
});
3737

3838
setRecordIndexKanbanAggregateOperationState({
39-
operation: convertedKanbanAggregateOperation,
39+
operation: kanbanAggregateOperation,
4040
fieldMetadataId: kanbanAggregateOperationFieldMetadataId,
4141
});
4242
},

0 commit comments

Comments
 (0)