2022-08-26 19:16:45 +00:00
|
|
|
import React from 'react';
|
2024-02-26 10:43:02 +00:00
|
|
|
import { fireEvent, render, screen } from '@testing-library/react-native';
|
2022-08-26 19:16:45 +00:00
|
|
|
|
|
|
|
import i18n from '../../../i18n';
|
2024-02-26 10:43:02 +00:00
|
|
|
import { SwitchItemEncrypted } from './SwitchItemEncrypted';
|
2022-08-26 19:16:45 +00:00
|
|
|
|
|
|
|
const onPressMock = jest.fn((value: boolean) => value);
|
|
|
|
|
|
|
|
describe('SwitchItemEncrypted', () => {
|
2024-02-26 10:43:02 +00:00
|
|
|
const testEncrypted = {
|
|
|
|
encrypted: false,
|
|
|
|
encryptionEnabled: false,
|
|
|
|
isTeam: false,
|
|
|
|
onValueChangeEncrypted: onPressMock,
|
|
|
|
type: false,
|
|
|
|
testSwitchID: 'create-channel-encrypted',
|
|
|
|
testLabelID: `create-channel-encrypted-hint`
|
|
|
|
};
|
|
|
|
|
|
|
|
it('should not render the Encrypted Switch component', () => {
|
|
|
|
render(
|
|
|
|
<SwitchItemEncrypted
|
2022-08-26 19:16:45 +00:00
|
|
|
encrypted={testEncrypted.encrypted}
|
|
|
|
encryptionEnabled={testEncrypted.encryptionEnabled}
|
|
|
|
isTeam={testEncrypted.isTeam}
|
|
|
|
onValueChangeEncrypted={value => testEncrypted.onValueChangeEncrypted(value)}
|
|
|
|
type={testEncrypted.type}
|
|
|
|
/>
|
|
|
|
);
|
2024-02-26 10:43:02 +00:00
|
|
|
const component = screen.queryByTestId(testEncrypted.testSwitchID);
|
|
|
|
expect(component).toBeNull();
|
2022-08-26 19:16:45 +00:00
|
|
|
});
|
2024-02-26 10:43:02 +00:00
|
|
|
|
|
|
|
it('should render the Encrypted Switch component', () => {
|
2022-08-26 19:16:45 +00:00
|
|
|
testEncrypted.encryptionEnabled = true;
|
2024-02-26 10:43:02 +00:00
|
|
|
render(
|
|
|
|
<SwitchItemEncrypted
|
2022-08-26 19:16:45 +00:00
|
|
|
encrypted={testEncrypted.encrypted}
|
|
|
|
encryptionEnabled={testEncrypted.encryptionEnabled}
|
|
|
|
isTeam={testEncrypted.isTeam}
|
|
|
|
onValueChangeEncrypted={value => testEncrypted.onValueChangeEncrypted(value)}
|
|
|
|
type={testEncrypted.type}
|
|
|
|
/>
|
|
|
|
);
|
2024-02-26 10:43:02 +00:00
|
|
|
const component = screen.queryByTestId(testEncrypted.testSwitchID);
|
2022-08-26 19:16:45 +00:00
|
|
|
expect(component).toBeTruthy();
|
|
|
|
});
|
2024-02-26 10:43:02 +00:00
|
|
|
|
|
|
|
it('should change value of switch', () => {
|
|
|
|
render(
|
|
|
|
<SwitchItemEncrypted
|
2022-08-26 19:16:45 +00:00
|
|
|
encrypted={testEncrypted.encrypted}
|
|
|
|
encryptionEnabled={testEncrypted.encryptionEnabled}
|
|
|
|
isTeam={testEncrypted.isTeam}
|
|
|
|
onValueChangeEncrypted={value => testEncrypted.onValueChangeEncrypted(value)}
|
|
|
|
type={testEncrypted.type}
|
|
|
|
/>
|
|
|
|
);
|
2024-02-26 10:43:02 +00:00
|
|
|
const component = screen.queryByTestId(testEncrypted.testSwitchID);
|
|
|
|
if (component) {
|
|
|
|
fireEvent(component, 'valueChange', { value: true });
|
|
|
|
expect(onPressMock).toHaveReturnedWith({ value: !testEncrypted.encrypted });
|
|
|
|
}
|
2022-08-26 19:16:45 +00:00
|
|
|
});
|
2024-02-26 10:43:02 +00:00
|
|
|
|
|
|
|
it('label when encrypted and isTeam are false and is a public channel', () => {
|
|
|
|
render(
|
|
|
|
<SwitchItemEncrypted
|
2022-08-26 19:16:45 +00:00
|
|
|
encrypted={testEncrypted.encrypted}
|
|
|
|
encryptionEnabled={testEncrypted.encryptionEnabled}
|
|
|
|
isTeam={testEncrypted.isTeam}
|
|
|
|
onValueChangeEncrypted={value => testEncrypted.onValueChangeEncrypted(value)}
|
|
|
|
type={testEncrypted.type}
|
|
|
|
/>
|
|
|
|
);
|
2024-02-26 10:43:02 +00:00
|
|
|
const component = screen.queryByTestId(testEncrypted.testLabelID);
|
|
|
|
expect(component?.props.children).toBe(i18n.t('Channel_hint_encrypted_not_available'));
|
2022-08-26 19:16:45 +00:00
|
|
|
});
|
2024-02-26 10:43:02 +00:00
|
|
|
|
|
|
|
it('label when encrypted and isTeam are true and is a private team', () => {
|
2022-08-26 19:16:45 +00:00
|
|
|
testEncrypted.isTeam = true;
|
|
|
|
testEncrypted.type = true;
|
|
|
|
testEncrypted.encrypted = true;
|
2024-02-26 10:43:02 +00:00
|
|
|
render(
|
|
|
|
<SwitchItemEncrypted
|
2022-08-26 19:16:45 +00:00
|
|
|
encrypted={testEncrypted.encrypted}
|
|
|
|
encryptionEnabled={testEncrypted.encryptionEnabled}
|
|
|
|
isTeam={testEncrypted.isTeam}
|
|
|
|
onValueChangeEncrypted={value => testEncrypted.onValueChangeEncrypted(value)}
|
|
|
|
type={testEncrypted.type}
|
|
|
|
/>
|
|
|
|
);
|
2024-02-26 10:43:02 +00:00
|
|
|
const component = screen.queryByTestId(testEncrypted.testLabelID);
|
|
|
|
expect(component?.props.children).toBe(i18n.t('Team_hint_encrypted'));
|
2022-08-26 19:16:45 +00:00
|
|
|
});
|
|
|
|
});
|