Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ const CreateChannelModal = ({ teamId = '', onClose, reload }: CreateChannelModal
)}
/>
</FieldRow>
<FieldDescription id={`${encryptedId}-hint`}>{getEncryptedHint({ isPrivate, broadcast, encrypted })}</FieldDescription>
<FieldDescription id={`${encryptedId}-hint`}>{getEncryptedHint({ isPrivate, encrypted })}</FieldDescription>
</Field>
<Field>
<FieldRow>
Expand Down
Original file line number Diff line number Diff line change
@@ -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');
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ const CreateChannelModal = ({ teamId = '', mainRoom, onClose, reload }: CreateCh
)}
/>
</FieldRow>
<FieldDescription id={`${encryptedId}-hint`}>{getEncryptedHint({ isPrivate, broadcast, encrypted })}</FieldDescription>
<FieldDescription id={`${encryptedId}-hint`}>{getEncryptedHint({ isPrivate, encrypted })}</FieldDescription>
</Field>
<Field>
<FieldRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Loading