Cleanup - unused files / unused exports / duplicate exports
[ProtonMail-WebClient.git] / packages / shared / test / contacts / contactGroups.spec.ts
blob38ea128554e38a5e8266b9e73bba1f74d50ad897
1 import { getContactGroupsDelayedSaveChanges } from '@proton/shared/lib/contacts/helpers/contactGroup';
2 import type { MailSettings } from '@proton/shared/lib/interfaces';
3 import type { ContactEmail } from '@proton/shared/lib/interfaces/contacts';
4 import { MAX_RECIPIENTS } from '@proton/shared/lib/mail/mailSettings';
6 const group1 = 'group1';
8 const getUserContactEmails = (numberOfContacts: number) => {
9     const contactEmails: ContactEmail[] = [];
11     for (let i = 0; i < numberOfContacts; i++) {
12         const contact = { ID: `contact${i}`, Email: `email${i}@pm.me`, LabelIDs: [group1] } as ContactEmail;
13         contactEmails.push(contact);
14     }
16     return contactEmails;
19 const initialModel = {
20     group1: 0,
23 const model = {
24     group1: 1,
27 const changes = {
28     group1: true,
31 const onLimitReached = jasmine.createSpy();
33 describe('contactGroups', () => {
34     describe('getContactGroupsDelayedSaveChanges', () => {
35         it('should be possible to add the contact to the contact group', () => {
36             const userContactEmails = getUserContactEmails(99);
38             const updatedChanges = getContactGroupsDelayedSaveChanges({
39                 userContactEmails,
40                 changes,
41                 initialModel,
42                 model,
43                 onLimitReached,
44                 mailSettings: { RecipientLimit: MAX_RECIPIENTS } as MailSettings,
45             });
47             expect(updatedChanges).toEqual(changes);
48         });
49     });
51     describe('getContactGroupsDelayedSaveChanges', () => {
52         it('should not be possible to add the contact to the contact group', () => {
53             const userContactEmails = getUserContactEmails(100);
55             const updatedChanges = getContactGroupsDelayedSaveChanges({
56                 userContactEmails,
57                 changes,
58                 initialModel,
59                 model,
60                 onLimitReached,
61                 mailSettings: {} as MailSettings,
62             });
64             expect(updatedChanges).toEqual({});
65             expect(onLimitReached).toHaveBeenCalled();
66         });
67     });
68 });