1
1
import type { IRoomWithRetentionPolicy } from '@rocket.chat/core-typings' ;
2
- import { mockAppRoot } from '@rocket.chat/mock-providers' ;
3
2
import { renderHook } from '@testing-library/react-hooks' ;
4
3
4
+ import { createRenteionPolicySettingsMock as createMock } from '../../tests/mocks/client/mockRetentionPolicySettings' ;
5
5
import { createFakeRoom } from '../../tests/mocks/data' ;
6
+ import { setDate } from '../../tests/mocks/mockDate' ;
6
7
import { usePruneWarningMessage } from './usePruneWarningMessage' ;
7
8
8
- const createMock = ( {
9
- enabled = true ,
10
- filesOnly = false ,
11
- doNotPrunePinned = false ,
12
- appliesToChannels = false ,
13
- TTLChannels = 60000 ,
14
- appliesToGroups = false ,
15
- TTLGroups = 60000 ,
16
- appliesToDMs = false ,
17
- TTLDMs = 60000 ,
18
- precision = '0' ,
19
- advancedPrecision = false ,
20
- advancedPrecisionCron = '*/30 * * * *' ,
21
- } = { } ) => {
22
- return mockAppRoot ( )
23
- . withTranslations ( 'en' , 'core' , {
24
- RetentionPolicy_RoomWarning_NextRunDate : '{{maxAge}} {{nextRunDate}}' ,
25
- RetentionPolicy_RoomWarning_Unpinned_NextRunDate : 'Unpinned {{maxAge}} {{nextRunDate}}' ,
26
- RetentionPolicy_RoomWarning_FilesOnly_NextRunDate : 'FilesOnly {{maxAge}} {{nextRunDate}}' ,
27
- RetentionPolicy_RoomWarning_UnpinnedFilesOnly_NextRunDate : 'UnpinnedFilesOnly {{maxAge}} {{nextRunDate}}' ,
28
- } )
29
- . withSetting ( 'RetentionPolicy_Enabled' , enabled )
30
- . withSetting ( 'RetentionPolicy_FilesOnly' , filesOnly )
31
- . withSetting ( 'RetentionPolicy_DoNotPrunePinned' , doNotPrunePinned )
32
- . withSetting ( 'RetentionPolicy_AppliesToChannels' , appliesToChannels )
33
- . withSetting ( 'RetentionPolicy_TTL_Channels' , TTLChannels )
34
- . withSetting ( 'RetentionPolicy_AppliesToGroups' , appliesToGroups )
35
- . withSetting ( 'RetentionPolicy_TTL_Groups' , TTLGroups )
36
- . withSetting ( 'RetentionPolicy_AppliesToDMs' , appliesToDMs )
37
- . withSetting ( 'RetentionPolicy_TTL_DMs' , TTLDMs )
38
- . withSetting ( 'RetentionPolicy_Precision' , precision )
39
- . withSetting ( 'RetentionPolicy_Advanced_Precision' , advancedPrecision )
40
- . withSetting ( 'RetentionPolicy_Advanced_Precision_Cron' , advancedPrecisionCron )
41
- . build ( ) ;
42
- } ;
43
-
44
9
jest . useFakeTimers ( ) ;
45
10
46
11
const getRetentionRoomProps = ( props : Partial < IRoomWithRetentionPolicy [ 'retention' ] > = { } ) => {
@@ -57,18 +22,6 @@ const getRetentionRoomProps = (props: Partial<IRoomWithRetentionPolicy['retentio
57
22
} ;
58
23
} ;
59
24
60
- const setDate = ( minutes = 1 , hours = 0 , date = 1 ) => {
61
- // June 12, 2024, 12:00 AM
62
- const fakeDate = new Date ( ) ;
63
- fakeDate . setFullYear ( 2024 ) ;
64
- fakeDate . setMonth ( 5 ) ;
65
- fakeDate . setDate ( date ) ;
66
- fakeDate . setHours ( hours ) ;
67
- fakeDate . setMinutes ( minutes ) ;
68
- fakeDate . setSeconds ( 0 ) ;
69
- jest . setSystemTime ( fakeDate ) ;
70
- } ;
71
-
72
25
describe ( 'usePruneWarningMessage hook' , ( ) => {
73
26
describe ( 'Cron timer and precision' , ( ) => {
74
27
it ( 'Should update the message after the nextRunDate has passaed' , async ( ) => {
0 commit comments