diff --git a/apps/meteor/client/components/InfoPanel/RetentionPolicyCallout.spec.tsx b/apps/meteor/client/components/InfoPanel/RetentionPolicyCallout.spec.tsx index 9a2e7eac4c45..fb97b0132f85 100644 --- a/apps/meteor/client/components/InfoPanel/RetentionPolicyCallout.spec.tsx +++ b/apps/meteor/client/components/InfoPanel/RetentionPolicyCallout.spec.tsx @@ -4,21 +4,22 @@ import '@testing-library/jest-dom/extend-expect'; import { createRenteionPolicySettingsMock as createMock } from '../../../tests/mocks/client/mockRetentionPolicySettings'; import { createFakeRoom } from '../../../tests/mocks/data'; -import { setDate } from '../../../tests/mocks/mockDate'; import RetentionPolicyCallout from './RetentionPolicyCallout'; jest.useFakeTimers(); +beforeEach(() => { + jest.setSystemTime(new Date(2024, 5, 1, 0, 0, 0)); +}); + describe('RetentionPolicyCallout', () => { it('Should render callout if settings are valid', () => { - setDate(); const fakeRoom = createFakeRoom({ t: 'c' }); render(, { wrapper: createMock({ appliesToChannels: true, TTLChannels: 60000 }) }); expect(screen.getByRole('alert')).toHaveTextContent('a minute June 1, 2024, 12:30 AM'); }); it('Should not render callout if settings are invalid', () => { - setDate(); const fakeRoom = createFakeRoom({ t: 'c' }); render(, { wrapper: createMock({ appliesToChannels: true, TTLChannels: 60000, advancedPrecisionCron: '* * * 12 *', advancedPrecision: true }), diff --git a/apps/meteor/client/hooks/usePruneWarningMessage.spec.ts b/apps/meteor/client/hooks/usePruneWarningMessage.spec.ts index 1ea3825c61ec..bb602cb81a3a 100644 --- a/apps/meteor/client/hooks/usePruneWarningMessage.spec.ts +++ b/apps/meteor/client/hooks/usePruneWarningMessage.spec.ts @@ -3,7 +3,6 @@ import { renderHook } from '@testing-library/react-hooks'; import { createRenteionPolicySettingsMock as createMock } from '../../tests/mocks/client/mockRetentionPolicySettings'; import { createFakeRoom } from '../../tests/mocks/data'; -import { setDate } from '../../tests/mocks/mockDate'; import { usePruneWarningMessage } from './usePruneWarningMessage'; jest.useFakeTimers(); @@ -22,10 +21,13 @@ const getRetentionRoomProps = (props: Partial { + jest.setSystemTime(new Date(2024, 5, 1, 0, 0, 0)); +}); + describe('usePruneWarningMessage hook', () => { describe('Cron timer and precision', () => { it('Should update the message after the nextRunDate has passaed', async () => { - setDate(); const fakeRoom = createFakeRoom({ t: 'c' }); const { result } = renderHook(() => usePruneWarningMessage(fakeRoom), { wrapper: createMock({ @@ -40,7 +42,6 @@ describe('usePruneWarningMessage hook', () => { it('Should return the default warning with precision set to every_hour', () => { const fakeRoom = createFakeRoom({ t: 'c' }); - setDate(); const { result } = renderHook(() => usePruneWarningMessage(fakeRoom), { wrapper: createMock({ appliesToChannels: true, @@ -53,7 +54,6 @@ describe('usePruneWarningMessage hook', () => { it('Should return the default warning with precision set to every_six_hours', () => { const fakeRoom = createFakeRoom({ t: 'c' }); - setDate(); const { result } = renderHook(() => usePruneWarningMessage(fakeRoom), { wrapper: createMock({ appliesToChannels: true, @@ -66,7 +66,6 @@ describe('usePruneWarningMessage hook', () => { it('Should return the default warning with precision set to every_day', () => { const fakeRoom = createFakeRoom({ t: 'c' }); - setDate(); const { result } = renderHook(() => usePruneWarningMessage(fakeRoom), { wrapper: createMock({ appliesToChannels: true, @@ -79,7 +78,6 @@ describe('usePruneWarningMessage hook', () => { it('Should return the default warning with advanced precision', () => { const fakeRoom = createFakeRoom({ t: 'c' }); - setDate(); const { result } = renderHook(() => usePruneWarningMessage(fakeRoom), { wrapper: createMock({ appliesToChannels: true, @@ -95,7 +93,6 @@ describe('usePruneWarningMessage hook', () => { describe('No override', () => { it('Should return the default warning', () => { const fakeRoom = createFakeRoom({ t: 'c' }); - setDate(); const { result } = renderHook(() => usePruneWarningMessage(fakeRoom), { wrapper: createMock({ appliesToChannels: true, @@ -107,7 +104,6 @@ describe('usePruneWarningMessage hook', () => { it('Should return the unpinned messages warning', () => { const fakeRoom = createFakeRoom({ t: 'c' }); - setDate(); const { result } = renderHook(() => usePruneWarningMessage(fakeRoom), { wrapper: createMock({ appliesToChannels: true, @@ -120,7 +116,6 @@ describe('usePruneWarningMessage hook', () => { it('Should return the files only warning', () => { const fakeRoom = createFakeRoom({ t: 'c' }); - setDate(); const { result } = renderHook(() => usePruneWarningMessage(fakeRoom), { wrapper: createMock({ @@ -134,7 +129,6 @@ describe('usePruneWarningMessage hook', () => { it('Should return the unpinned files only warning', () => { const fakeRoom = createFakeRoom({ t: 'c' }); - setDate(); const { result } = renderHook(() => usePruneWarningMessage(fakeRoom), { wrapper: createMock({ @@ -151,7 +145,6 @@ describe('usePruneWarningMessage hook', () => { describe('Overriden', () => { it('Should return the default warning', () => { const fakeRoom = createFakeRoom({ t: 'p', ...getRetentionRoomProps() }); - setDate(); const { result } = renderHook(() => usePruneWarningMessage(fakeRoom), { wrapper: createMock(), }); @@ -160,7 +153,6 @@ describe('usePruneWarningMessage hook', () => { it('Should return the unpinned messages warning', () => { const fakeRoom = createFakeRoom({ t: 'p', ...getRetentionRoomProps({ excludePinned: true }) }); - setDate(); const { result } = renderHook(() => usePruneWarningMessage(fakeRoom), { wrapper: createMock(), }); @@ -169,7 +161,6 @@ describe('usePruneWarningMessage hook', () => { it('Should return the files only warning', () => { const fakeRoom = createFakeRoom({ t: 'p', ...getRetentionRoomProps({ filesOnly: true }) }); - setDate(); const { result } = renderHook(() => usePruneWarningMessage(fakeRoom), { wrapper: createMock(), @@ -179,7 +170,6 @@ describe('usePruneWarningMessage hook', () => { it('Should return the unpinned files only warning', () => { const fakeRoom = createFakeRoom({ t: 'p', ...getRetentionRoomProps({ excludePinned: true, filesOnly: true }) }); - setDate(); const { result } = renderHook(() => usePruneWarningMessage(fakeRoom), { wrapper: createMock(), diff --git a/apps/meteor/client/views/room/body/RetentionPolicyWarning.spec.tsx b/apps/meteor/client/views/room/body/RetentionPolicyWarning.spec.tsx index 28a6eca3b283..a6c49c5537de 100644 --- a/apps/meteor/client/views/room/body/RetentionPolicyWarning.spec.tsx +++ b/apps/meteor/client/views/room/body/RetentionPolicyWarning.spec.tsx @@ -4,21 +4,22 @@ import '@testing-library/jest-dom/extend-expect'; import { createRenteionPolicySettingsMock as createMock } from '../../../../tests/mocks/client/mockRetentionPolicySettings'; import { createFakeRoom } from '../../../../tests/mocks/data'; -import { setDate } from '../../../../tests/mocks/mockDate'; import RetentionPolicyWarning from './RetentionPolicyWarning'; jest.useFakeTimers(); +beforeEach(() => { + jest.setSystemTime(new Date(2024, 5, 1, 0, 0, 0)); +}); + describe('RetentionPolicyWarning', () => { it('Should render callout if settings are valid', () => { - setDate(); const fakeRoom = createFakeRoom({ t: 'c' }); render(, { wrapper: createMock({ appliesToChannels: true, TTLChannels: 60000 }) }); expect(screen.getByRole('alert')).toHaveTextContent('a minute June 1, 2024, 12:30 AM'); }); it('Should not render callout if settings are invalid', () => { - setDate(); const fakeRoom = createFakeRoom({ t: 'c' }); render(, { wrapper: createMock({ appliesToChannels: true, TTLChannels: 60000, advancedPrecisionCron: '* * * 12 *', advancedPrecision: true }), diff --git a/apps/meteor/tests/mocks/mockDate.ts b/apps/meteor/tests/mocks/mockDate.ts deleted file mode 100644 index 6591dfdf7b1b..000000000000 --- a/apps/meteor/tests/mocks/mockDate.ts +++ /dev/null @@ -1,12 +0,0 @@ -// you must use jest.useFakeTimers for this to work. -export const setDate = (minutes = 1, hours = 0, date = 1) => { - // June 12, 2024, 12:00 AM - const fakeDate = new Date(); - fakeDate.setFullYear(2024); - fakeDate.setMonth(5); - fakeDate.setDate(date); - fakeDate.setHours(hours); - fakeDate.setMinutes(minutes); - fakeDate.setSeconds(0); - jest.setSystemTime(fakeDate); -};