-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Title missing in thread list for threads starting with attachmen…
…t in E2EE rooms (#33375)
- Loading branch information
1 parent
0b5dd94
commit 50bfa4a
Showing
3 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@rocket.chat/meteor": patch | ||
--- | ||
|
||
Fixes title missing in thread list for threads starting with attachment in E2EE rooms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { isE2EEMessage } from '@rocket.chat/core-typings'; | ||
import { renderHook, waitFor } from '@testing-library/react'; | ||
|
||
import { e2e } from '../../app/e2e/client/rocketchat.e2e'; | ||
import { useDecryptedMessage } from './useDecryptedMessage'; | ||
|
||
// Mock the dependencies | ||
jest.mock('@rocket.chat/core-typings', () => ({ | ||
isE2EEMessage: jest.fn(), | ||
})); | ||
|
||
jest.mock('../../app/e2e/client/rocketchat.e2e', () => ({ | ||
e2e: { | ||
decryptMessage: jest.fn(), | ||
}, | ||
})); | ||
|
||
jest.mock('react-i18next', () => ({ | ||
useTranslation: () => ({ | ||
t: (key: string) => key, | ||
}), | ||
})); | ||
|
||
describe('useDecryptedMessage', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should return the original message for non-E2EE messages', () => { | ||
(isE2EEMessage as jest.MockedFunction<typeof isE2EEMessage>).mockReturnValue(false); | ||
const message = { msg: 'Hello, world!' }; | ||
|
||
const { result } = renderHook(() => useDecryptedMessage(message as any), { legacyRoot: true }); | ||
|
||
expect(result.current).toBe('Hello, world!'); | ||
expect(e2e.decryptMessage).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should return decrypted message for E2EE messages', async () => { | ||
(isE2EEMessage as jest.MockedFunction<typeof isE2EEMessage>).mockReturnValue(true); | ||
(e2e.decryptMessage as jest.Mock).mockResolvedValue({ msg: 'Decrypted message' }); | ||
const message = { msg: 'Encrypted message' }; | ||
const { result } = renderHook(() => useDecryptedMessage(message as any), { legacyRoot: true }); | ||
|
||
await waitFor(() => { | ||
expect(result.current).not.toBe('E2E_message_encrypted_placeholder'); | ||
}); | ||
|
||
expect(result.current).toBe('Decrypted message'); | ||
expect(e2e.decryptMessage).toHaveBeenCalledWith(message); | ||
}); | ||
|
||
it('should handle E2EE messages with attachments', async () => { | ||
(isE2EEMessage as jest.MockedFunction<typeof isE2EEMessage>).mockReturnValue(true); | ||
(e2e.decryptMessage as jest.Mock).mockResolvedValue({ | ||
attachments: [{ description: 'Attachment description' }], | ||
}); | ||
const message = { msg: 'Encrypted message with attachment' }; | ||
|
||
const { result } = renderHook(() => useDecryptedMessage(message as any), { legacyRoot: true }); | ||
|
||
await waitFor(() => { | ||
expect(result.current).toBe('E2E_message_encrypted_placeholder'); | ||
}); | ||
|
||
expect(result.current).toBe('Attachment description'); | ||
expect(e2e.decryptMessage).toHaveBeenCalledWith(message); | ||
}); | ||
|
||
it('should handle E2EE messages with attachments but no description', async () => { | ||
(isE2EEMessage as jest.MockedFunction<typeof isE2EEMessage>).mockReturnValue(true); | ||
(e2e.decryptMessage as jest.Mock).mockResolvedValue({ | ||
attachments: [{}], | ||
}); | ||
const message = { msg: 'Encrypted message with attachment' }; | ||
|
||
const { result } = renderHook(() => useDecryptedMessage(message as any), { legacyRoot: true }); | ||
|
||
await waitFor(() => { | ||
expect(result.current).toBe('E2E_message_encrypted_placeholder'); | ||
}); | ||
|
||
expect(result.current).toBe('Message_with_attachment'); | ||
expect(e2e.decryptMessage).toHaveBeenCalledWith(message); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters