1 import type { Recipient } from '@proton/shared/lib/interfaces';
4 findRecipientsWithSpaceSeparator,
8 } from '@proton/shared/lib/mail/recipient';
10 const address1 = 'address1@pm.me';
11 const address2 = 'address2@pm.me';
13 const addessName = 'Address';
15 describe('splitBySeparator', () => {
16 it('should omit separators present at the beginning and the end', () => {
17 const input = ',plus@debye.proton.black, visionary@debye.proton.black; pro@debye.proton.black,';
18 const result = splitBySeparator(input);
19 expect(result).toEqual(['plus@debye.proton.black', 'visionary@debye.proton.black', 'pro@debye.proton.black']);
22 it('should omit empty values', () => {
23 const input = 'plus@debye.proton.black, visionary@debye.proton.black, iamblueuser@gmail.com,,';
24 const result = splitBySeparator(input);
25 expect(result).toEqual(['plus@debye.proton.black', 'visionary@debye.proton.black', 'iamblueuser@gmail.com']);
29 describe('clearValue', () => {
30 it('should trim the value', () => {
31 const input = ' panda@proton.me ';
32 const result = clearValue(input);
33 expect(result).toEqual('panda@proton.me');
36 it('should remove surrounding chevrons', () => {
37 const input = '<panda@proton.me>';
38 const result = clearValue(input);
39 expect(result).toEqual('panda@proton.me');
42 it('should keep chevrons when needed', () => {
43 const input = 'Panda <panda@proton.me>';
44 const result = clearValue(input);
45 expect(result).toEqual('Panda <panda@proton.me>');
49 describe('inputToRecipient', () => {
50 it('should return a recipient with the email as the name and address if the input is an email', () => {
51 const input = 'panda@proton.me';
52 const result = inputToRecipient(input);
53 expect(result).toEqual({ Name: input, Address: input });
56 it('should extract the email address surrounded by brackets', () => {
57 const input = '<domain@debye.proton.black>';
58 const result = inputToRecipient(input);
59 expect(result).toEqual({ Name: '', Address: 'domain@debye.proton.black' });
62 it('should extract name and email address', () => {
63 const input = 'Panda <panda@proton.me>';
64 const result = inputToRecipient(input);
65 expect(result).toEqual({ Name: 'Panda', Address: 'panda@proton.me' });
69 describe('findRecipientsWithSpaceSeparator', () => {
70 it('should detect recipients with space separator', () => {
71 const input = `${address1} ${address2}`;
72 const result = findRecipientsWithSpaceSeparator(input);
74 expect(result).toEqual([address1, address2]);
77 it('should not split recipients from space separator when separator is a coma', () => {
78 const input1 = `${address1}, ${address2}`;
79 const input2 = `Address1 <${address1}>, Address2 <${address2}></address2>`;
81 expect(findRecipientsWithSpaceSeparator(input1)).toEqual([]);
82 expect(findRecipientsWithSpaceSeparator(input2)).toEqual([]);
85 it('should not split recipients when input does not contain a space', () => {
86 expect(findRecipientsWithSpaceSeparator(address1)).toEqual([]);
90 describe('recipientToInput', () => {
91 it('should return the expected input', () => {
101 const expected1 = `${addessName} <${address1}>`;
102 const expected2 = address1;
104 expect(recipientToInput(recipient1)).toEqual(expected1);
105 expect(recipientToInput(recipient2)).toEqual(expected2);