From c9504925e6728ba92fb46934534b2ee9787c6fce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Espino=20Garc=C3=ADa?= Date: Fri, 14 Mar 2025 12:03:13 +0100 Subject: [PATCH] Fix user post box indicator flaky test (#30480) --- .../use_post_box_indicator.test.tsx | 36 +++++++++++++++++++ webapp/channels/src/tests/setup_jest.ts | 5 +++ 2 files changed, 41 insertions(+) diff --git a/webapp/channels/src/components/advanced_text_editor/use_post_box_indicator.test.tsx b/webapp/channels/src/components/advanced_text_editor/use_post_box_indicator.test.tsx index 19f19c367a..4fd02c3b64 100644 --- a/webapp/channels/src/components/advanced_text_editor/use_post_box_indicator.test.tsx +++ b/webapp/channels/src/components/advanced_text_editor/use_post_box_indicator.test.tsx @@ -20,6 +20,12 @@ function getBaseState(): DeepPartial { type: 'D', name: 'current_user_id__teammate_user_id', }, + dm_near_timezone: { + id: 'dm_same_timezone', + teammate_id: 'teammate_near_timezone_id', + type: 'D', + name: 'current_user_id__teammate_near_timezone_id', + }, bot_dm_channel_id: { id: 'bot_dm_channel_id', teammate_id: 'bot_user_id', @@ -49,6 +55,18 @@ function getBaseState(): DeepPartial { manualTimezone: '', }, }, + teammate_near_timezone_id: { + id: 'teammate_near_timezone_id', + username: 'teammate_near_timezone_username', + nickname: 'teammate_near_timezone_nickname', + first_name: 'teammate_near_timezone_first_name', + last_name: 'teammate_near_timezone_last_name', + timezone: { + useAutomaticTimezone: 'false', + automaticTimezone: '', + manualTimezone: 'CET', + }, + }, bot_user_id: { id: 'bot_user_id', username: 'bot_username', @@ -77,6 +95,11 @@ function getBaseState(): DeepPartial { } describe('useTimePostBoxIndicator', () => { + beforeAll(() => { + jest.useFakeTimers(); + jest.setSystemTime(new Date('2021-01-01T18:00:00Z').getTime()); + }); + it('should pass base case', () => { const {result: {current}} = renderHookWithContext(() => useTimePostBoxIndicator('dm_channel_id'), getBaseState()); @@ -90,6 +113,19 @@ describe('useTimePostBoxIndicator', () => { expect(current.teammateTimezone.automaticTimezone).toBe('IST'); }); + it('should not show if within working hours', () => { + const {result: {current}} = renderHookWithContext(() => useTimePostBoxIndicator('dm_near_timezone'), getBaseState()); + + expect(current.isDM).toBe(true); + expect(current.showDndWarning).toBe(false); + expect(current.isSelfDM).toBe(false); + expect(current.isBot).toBe(false); + expect(current.showRemoteUserHour).toBe(false); + expect(current.isScheduledPostEnabled).toBe(true); + expect(current.teammateTimezone.useAutomaticTimezone).toBe(false); + expect(current.teammateTimezone.manualTimezone).toBe('CET'); + }); + it('should work for DM with bots', () => { const {result: {current}} = renderHookWithContext(() => useTimePostBoxIndicator('bot_dm_channel_id'), getBaseState()); diff --git a/webapp/channels/src/tests/setup_jest.ts b/webapp/channels/src/tests/setup_jest.ts index c1e135efe8..432f9939d8 100644 --- a/webapp/channels/src/tests/setup_jest.ts +++ b/webapp/channels/src/tests/setup_jest.ts @@ -15,6 +15,11 @@ import './react-intl_mock'; import './react-router-dom_mock'; import './react-tippy_mock'; +module.exports = async () => { + // eslint-disable-next-line no-process-env + process.env.TZ = 'UTC'; +}; + configure({adapter: new (Adapter as any)()}); global.window = Object.create(window);