Skip to content

Commit

Permalink
fix usePruneWarningMessage tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriellsh authored and ggazzo committed Jul 16, 2024
1 parent b76280c commit 524e178
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('RetentionPolicyCallout', () => {
setDate();
const fakeRoom = createFakeRoom({ t: 'c' });
render(<RetentionPolicyCallout room={fakeRoom} />, { wrapper: createMock({ appliesToChannels: true, TTLChannels: 60000 }) });
expect(screen.getByRole('alert')).toHaveTextContent('a minute June 1, 2024, 12:30 AM');
expect(screen.getByRole('alert')).toHaveTextContent('a minute June 1, 2024 at 12:30 AM');
});

it('Should not render callout if settings are invalid', () => {
Expand Down
31 changes: 17 additions & 14 deletions apps/meteor/client/hooks/usePruneWarningMessage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const getRetentionRoomProps = (props: Partial<IRoomWithRetentionPolicy['retentio
};
};

// Warning: The dates are formated using date-fns/intlFormat, which itself uses the JS Intl API
// The resulting formatted date can change depending on node version. These tests may break or the results
// may be different when running on the browser.
describe('usePruneWarningMessage hook', () => {
describe('Cron timer and precision', () => {
it('Should update the message after the nextRunDate has passaed', async () => {
Expand All @@ -33,9 +36,9 @@ describe('usePruneWarningMessage hook', () => {
TTLChannels: 60000,
}),
});
expect(result.current).toEqual('a minute June 1, 2024, 12:30 AM');
expect(result.current).toEqual('a minute June 1, 2024 at 12:30 AM');
jest.advanceTimersByTime(31 * 60 * 1000);
expect(result.current).toEqual('a minute June 1, 2024, 1:00 AM');
expect(result.current).toEqual('a minute June 1, 2024 at 1:00 AM');
});

it('Should return the default warning with precision set to every_hour', () => {
Expand All @@ -48,7 +51,7 @@ describe('usePruneWarningMessage hook', () => {
precision: '1',
}),
});
expect(result.current).toEqual('a minute June 1, 2024, 1:00 AM');
expect(result.current).toEqual('a minute June 1, 2024 at 1:00 AM');
});

it('Should return the default warning with precision set to every_six_hours', () => {
Expand All @@ -61,7 +64,7 @@ describe('usePruneWarningMessage hook', () => {
precision: '2',
}),
});
expect(result.current).toEqual('a minute June 1, 2024, 6:00 AM');
expect(result.current).toEqual('a minute June 1, 2024 at 6:00 AM');
});

it('Should return the default warning with precision set to every_day', () => {
Expand All @@ -74,7 +77,7 @@ describe('usePruneWarningMessage hook', () => {
precision: '3',
}),
});
expect(result.current).toEqual('a minute June 2, 2024, 12:00 AM');
expect(result.current).toEqual('a minute June 2, 2024 at 12:00 AM');
});

it('Should return the default warning with advanced precision', () => {
Expand All @@ -88,7 +91,7 @@ describe('usePruneWarningMessage hook', () => {
advancedPrecisionCron: '0 0 1 */1 *',
}),
});
expect(result.current).toEqual('a minute July 1, 2024, 12:00 AM');
expect(result.current).toEqual('a minute July 1, 2024 at 12:00 AM');
});
});

Expand All @@ -102,7 +105,7 @@ describe('usePruneWarningMessage hook', () => {
TTLChannels: 60000,
}),
});
expect(result.current).toEqual('a minute June 1, 2024, 12:30 AM');
expect(result.current).toEqual('a minute June 1, 2024 at 12:30 AM');
});

it('Should return the unpinned messages warning', () => {
Expand All @@ -115,7 +118,7 @@ describe('usePruneWarningMessage hook', () => {
doNotPrunePinned: true,
}),
});
expect(result.current).toEqual('Unpinned a minute June 1, 2024, 12:30 AM');
expect(result.current).toEqual('Unpinned a minute June 1, 2024 at 12:30 AM');
});

it('Should return the files only warning', () => {
Expand All @@ -129,7 +132,7 @@ describe('usePruneWarningMessage hook', () => {
filesOnly: true,
}),
});
expect(result.current).toEqual('FilesOnly a minute June 1, 2024, 12:30 AM');
expect(result.current).toEqual('FilesOnly a minute June 1, 2024 at 12:30 AM');
});

it('Should return the unpinned files only warning', () => {
Expand All @@ -144,7 +147,7 @@ describe('usePruneWarningMessage hook', () => {
doNotPrunePinned: true,
}),
});
expect(result.current).toEqual('UnpinnedFilesOnly a minute June 1, 2024, 12:30 AM');
expect(result.current).toEqual('UnpinnedFilesOnly a minute June 1, 2024 at 12:30 AM');
});
});

Expand All @@ -155,7 +158,7 @@ describe('usePruneWarningMessage hook', () => {
const { result } = renderHook(() => usePruneWarningMessage(fakeRoom), {
wrapper: createMock(),
});
expect(result.current).toEqual('30 days June 1, 2024, 12:30 AM');
expect(result.current).toEqual('30 days June 1, 2024 at 12:30 AM');
});

it('Should return the unpinned messages warning', () => {
Expand All @@ -164,7 +167,7 @@ describe('usePruneWarningMessage hook', () => {
const { result } = renderHook(() => usePruneWarningMessage(fakeRoom), {
wrapper: createMock(),
});
expect(result.current).toEqual('Unpinned 30 days June 1, 2024, 12:30 AM');
expect(result.current).toEqual('Unpinned 30 days June 1, 2024 at 12:30 AM');
});

it('Should return the files only warning', () => {
Expand All @@ -174,7 +177,7 @@ describe('usePruneWarningMessage hook', () => {
const { result } = renderHook(() => usePruneWarningMessage(fakeRoom), {
wrapper: createMock(),
});
expect(result.current).toEqual('FilesOnly 30 days June 1, 2024, 12:30 AM');
expect(result.current).toEqual('FilesOnly 30 days June 1, 2024 at 12:30 AM');
});

it('Should return the unpinned files only warning', () => {
Expand All @@ -184,7 +187,7 @@ describe('usePruneWarningMessage hook', () => {
const { result } = renderHook(() => usePruneWarningMessage(fakeRoom), {
wrapper: createMock(),
});
expect(result.current).toEqual('UnpinnedFilesOnly 30 days June 1, 2024, 12:30 AM');
expect(result.current).toEqual('UnpinnedFilesOnly 30 days June 1, 2024 at 12:30 AM');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('RetentionPolicyWarning', () => {
setDate();
const fakeRoom = createFakeRoom({ t: 'c' });
render(<RetentionPolicyWarning room={fakeRoom} />, { wrapper: createMock({ appliesToChannels: true, TTLChannels: 60000 }) });
expect(screen.getByRole('alert')).toHaveTextContent('a minute June 1, 2024, 12:30 AM');
expect(screen.getByRole('alert')).toHaveTextContent('a minute June 1, 2024 at 12:30 AM');
});

it('Should not render callout if settings are invalid', () => {
Expand Down

0 comments on commit 524e178

Please sign in to comment.