1 import type { SimpleMap } from '@proton/shared/lib/interfaces';
2 import type { ContactEmail } from '@proton/shared/lib/interfaces/contacts';
4 import type { DisplayNameEmail } from '../containers/calendar/interface';
5 import { getOrganizerDisplayData } from './attendees';
7 const generateDummyContactEmail = ({
15 contactEmailID: string;
18 const result: ContactEmail = {
33 describe('getOrganizerDisplayData()', () => {
34 const testEmail = 'te_st.E-mail@proton.me';
35 const organizer = { email: testEmail, cn: 'The organizer' };
36 const isOrganizer = false;
39 { name: 'Unexpected match', email: testEmail, contactEmailID: '2', contactID: 'unexpected' },
41 name: 'Canonicalized match',
42 email: 'testemail@proton.me',
44 contactID: 'internal',
46 { name: 'A gmail match', email: 'te_ste-mail@proton,me', contactEmailID: '4', contactID: 'gmail' },
47 { name: 'A lonely contact', email: 'lonely@proton.me', contactEmailID: '5', contactID: 'other' },
48 { name: 'Expected match', email: 'te_st.e-mail@proton.me', contactEmailID: '1', contactID: 'expected' },
51 // keys in contactsEmailMap are emails canonicalized with the generic scheme
52 const contactsEmailMap = contacts.reduce<SimpleMap<ContactEmail>>((acc, contact) => {
53 acc[contact.email] = generateDummyContactEmail(contact);
57 // keys in displayNameEmailMap are emails canonicalized by guess. In particular all Proton ones are canonicalized internally
58 const displayNameEmailMap: SimpleMap<DisplayNameEmail> = {
59 'testemail@proton.me': { displayName: "It's me", displayEmail: 'test.email@proton.me' },
60 'lonely@proton.me': { displayName: 'Lone star', displayEmail: 'Lonely@proton.me' },
63 test('Distinguishes dots, hyphens and underscores, but not capitalization, to return correct contactId', () => {
64 const { contactID } = getOrganizerDisplayData(organizer, isOrganizer, contactsEmailMap, displayNameEmailMap);
65 expect(contactID).toEqual('expected');
68 test('Neither distinguishes dots, hyphens, underscores or capitalization, to return correct display name', () => {
69 const { title, name } = getOrganizerDisplayData(organizer, isOrganizer, contactsEmailMap, displayNameEmailMap);
70 expect(name).toEqual("It's me");
71 expect(title).toEqual("It's me <te_st.E-mail@proton.me>");
74 test('Neither distinguishes dots, hyphens, underscores or capitalization, to return correct initials', () => {
75 const { initials } = getOrganizerDisplayData(organizer, isOrganizer, contactsEmailMap, displayNameEmailMap);
76 expect(initials).toEqual('IM');
79 describe('when user is organiser', () => {
80 const isOrganizer = true;
82 test('Neither distinguish dots, hyphens, underscores nor capitalization, to return correct display name', () => {
83 expect(getOrganizerDisplayData(organizer, isOrganizer, contactsEmailMap, displayNameEmailMap)).toEqual({
86 contactID: 'expected',