diff --git a/apps/meteor/client/NavBarV2/NavBarPagesGroup/actions/CreateChannelModal.tsx b/apps/meteor/client/NavBarV2/NavBarPagesGroup/actions/CreateChannelModal.tsx index bc3b71fcbfcfc..0cd417c2e3b0d 100644 --- a/apps/meteor/client/NavBarV2/NavBarPagesGroup/actions/CreateChannelModal.tsx +++ b/apps/meteor/client/NavBarV2/NavBarPagesGroup/actions/CreateChannelModal.tsx @@ -315,7 +315,7 @@ const CreateChannelModal = ({ teamId = '', onClose, reload }: CreateChannelModal )} /> - {getEncryptedHint({ isPrivate, broadcast, encrypted })} + {getEncryptedHint({ isPrivate, encrypted })} diff --git a/apps/meteor/client/NavBarV2/NavBarPagesGroup/actions/useEncryptedRoomDescription.spec.tsx b/apps/meteor/client/NavBarV2/NavBarPagesGroup/actions/useEncryptedRoomDescription.spec.tsx new file mode 100644 index 0000000000000..e775e384460f4 --- /dev/null +++ b/apps/meteor/client/NavBarV2/NavBarPagesGroup/actions/useEncryptedRoomDescription.spec.tsx @@ -0,0 +1,87 @@ +import { mockAppRoot } from '@rocket.chat/mock-providers'; +import { renderHook } from '@testing-library/react'; + +import { useEncryptedRoomDescription } from './useEncryptedRoomDescription'; +import { useEncryptedRoomDescription as useEncryptedRoomDescriptionOld } from '../../../sidebar/header/hooks/useEncryptedRoomDescription'; + +type Hook = typeof useEncryptedRoomDescription | typeof useEncryptedRoomDescriptionOld; + +const wrapper = mockAppRoot(); + +describe.each([ + ['useEncryptedRoomDescription in NavBarV2', useEncryptedRoomDescription], + ['useEncryptedRoomDescription', useEncryptedRoomDescriptionOld], +] as const)('%s', (_name, useEncryptedRoomDescriptionHook: Hook) => { + beforeEach(() => { + jest.clearAllMocks(); + }); + + describe.each(['channel', 'team'] as const)('roomType=%s', (roomType) => { + it('returns "Not_available_for_this_workspace" when E2E is disabled', () => { + const { result } = renderHook(() => useEncryptedRoomDescriptionHook(roomType), { + wrapper: wrapper.withSetting('E2E_Enable', false).build(), + }); + const describe = result.current; + + expect(describe({ isPrivate: true, broadcast: false, encrypted: true })).toBe('Not_available_for_this_workspace'); + }); + + it('returns "Encrypted_not_available" when room is not private', () => { + const { result } = renderHook(() => useEncryptedRoomDescriptionHook(roomType), { + wrapper: wrapper.withSetting('E2E_Enable', true).build(), + }); + const describe = result.current; + + expect(describe({ isPrivate: false, broadcast: false, encrypted: false })).toBe(`Encrypted_not_available`); + }); + + it('returns "Not_available_for_broadcast" when broadcast=true (even if encrypted is true)', () => { + const { result } = renderHook(() => useEncryptedRoomDescriptionHook(roomType), { + wrapper: wrapper.withSetting('E2E_Enable', true).build(), + }); + const describe = result.current; + + expect(describe({ isPrivate: true, broadcast: true, encrypted: true })).toBe(`Not_available_for_broadcast`); + + expect(describe({ isPrivate: true, broadcast: true, encrypted: false })).toBe(`Not_available_for_broadcast`); + }); + + it('returns "Encrypted_messages" when private, not broadcast, and encrypted is true', () => { + const { result } = renderHook(() => useEncryptedRoomDescriptionHook(roomType), { + wrapper: wrapper.withSetting('E2E_Enable', true).build(), + }); + const describe = result.current; + + expect(describe({ isPrivate: true, broadcast: false, encrypted: true })).toBe(`Encrypted_messages`); + }); + + it('returns "Encrypted_messages_false" when private, not broadcast, and encrypted is false', () => { + const { result } = renderHook(() => useEncryptedRoomDescriptionHook(roomType), { + wrapper: wrapper.withSetting('E2E_Enable', true).build(), + }); + const describe = result.current; + + expect(describe({ isPrivate: true, broadcast: false, encrypted: false })).toBe('Encrypted_messages_false'); + }); + + describe('when broadcast is undefined', () => { + it('returns "Encrypted_messages" if private and encrypted is true and broadcast is undefined', () => { + const { result } = renderHook(() => useEncryptedRoomDescriptionHook(roomType), { + wrapper: wrapper.withSetting('E2E_Enable', true).build(), + }); + const describe = result.current; + + expect(describe({ isPrivate: true, encrypted: true })).toBe(`Encrypted_messages`); + }); + + it('returns "Encrypted_messages_false" if private and encrypted is false and broadcast is undefined', () => { + const { result } = renderHook(() => useEncryptedRoomDescriptionHook(roomType), { + wrapper: wrapper.withSetting('E2E_Enable', true).build(), + }); + const describe = result.current; + + expect(describe({ isPrivate: true, encrypted: false })).toBe('Encrypted_messages_false'); + }); + }); + }); +}); diff --git a/apps/meteor/client/NavBarV2/NavBarPagesGroup/actions/useEncryptedRoomDescription.tsx b/apps/meteor/client/NavBarV2/NavBarPagesGroup/actions/useEncryptedRoomDescription.tsx index 0cef06d391737..4a193aed413cb 100644 --- a/apps/meteor/client/NavBarV2/NavBarPagesGroup/actions/useEncryptedRoomDescription.tsx +++ b/apps/meteor/client/NavBarV2/NavBarPagesGroup/actions/useEncryptedRoomDescription.tsx @@ -4,19 +4,19 @@ import { useTranslation } from 'react-i18next'; export const useEncryptedRoomDescription = (roomType: 'channel' | 'team') => { const { t } = useTranslation(); const e2eEnabled = useSetting('E2E_Enable'); - const e2eEnabledForPrivateByDefault = useSetting('E2E_Enabled_Default_PrivateRooms'); - return ({ isPrivate, broadcast, encrypted }: { isPrivate: boolean; broadcast: boolean; encrypted: boolean }) => { + return ({ isPrivate, broadcast, encrypted }: { isPrivate: boolean; broadcast?: boolean; encrypted: boolean }) => { if (!e2eEnabled) { return t('Not_available_for_this_workspace'); } if (!isPrivate) { return t('Encrypted_not_available', { roomType }); } - if (broadcast) { + // TODO: This case will be removed once we enable E2E for broadcast teams in teams creation modal + if (broadcast !== undefined && broadcast) { return t('Not_available_for_broadcast', { roomType }); } - if (e2eEnabledForPrivateByDefault || encrypted) { + if (encrypted) { return t('Encrypted_messages', { roomType }); } return t('Encrypted_messages_false'); diff --git a/apps/meteor/client/sidebar/header/CreateChannel/CreateChannelModal.tsx b/apps/meteor/client/sidebar/header/CreateChannel/CreateChannelModal.tsx index 1fe7b6bafe37c..b72a848961b3e 100644 --- a/apps/meteor/client/sidebar/header/CreateChannel/CreateChannelModal.tsx +++ b/apps/meteor/client/sidebar/header/CreateChannel/CreateChannelModal.tsx @@ -311,7 +311,7 @@ const CreateChannelModal = ({ teamId = '', mainRoom, onClose, reload }: CreateCh )} /> - {getEncryptedHint({ isPrivate, broadcast, encrypted })} + {getEncryptedHint({ isPrivate, encrypted })} diff --git a/apps/meteor/client/sidebar/header/hooks/useEncryptedRoomDescription.tsx b/apps/meteor/client/sidebar/header/hooks/useEncryptedRoomDescription.tsx index 0cef06d391737..4a193aed413cb 100644 --- a/apps/meteor/client/sidebar/header/hooks/useEncryptedRoomDescription.tsx +++ b/apps/meteor/client/sidebar/header/hooks/useEncryptedRoomDescription.tsx @@ -4,19 +4,19 @@ import { useTranslation } from 'react-i18next'; export const useEncryptedRoomDescription = (roomType: 'channel' | 'team') => { const { t } = useTranslation(); const e2eEnabled = useSetting('E2E_Enable'); - const e2eEnabledForPrivateByDefault = useSetting('E2E_Enabled_Default_PrivateRooms'); - return ({ isPrivate, broadcast, encrypted }: { isPrivate: boolean; broadcast: boolean; encrypted: boolean }) => { + return ({ isPrivate, broadcast, encrypted }: { isPrivate: boolean; broadcast?: boolean; encrypted: boolean }) => { if (!e2eEnabled) { return t('Not_available_for_this_workspace'); } if (!isPrivate) { return t('Encrypted_not_available', { roomType }); } - if (broadcast) { + // TODO: This case will be removed once we enable E2E for broadcast teams in teams creation modal + if (broadcast !== undefined && broadcast) { return t('Not_available_for_broadcast', { roomType }); } - if (e2eEnabledForPrivateByDefault || encrypted) { + if (encrypted) { return t('Encrypted_messages', { roomType }); } return t('Encrypted_messages_false');