TWNTY-4450 - Add tests for /modules/activities/emails (#4520)

* Add tests for `/modules/activities/emails`

Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: Thiago Nascimbeni <tnascimbeni@gmail.com>

* Fix tests

Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: Thiago Nascimbeni <tnascimbeni@gmail.com>

* Remove temporary changes

Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: Thiago Nascimbeni <tnascimbeni@gmail.com>

---------

Co-authored-by: gitstart-twenty <gitstart-twenty@users.noreply.github.com>
Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: Thiago Nascimbeni <tnascimbeni@gmail.com>
This commit is contained in:
gitstart-app[bot]
2024-03-18 17:10:07 +01:00
committed by GitHub
parent bdbd77c696
commit 872fb2bd49
15 changed files with 334 additions and 5 deletions

View File

@ -0,0 +1,100 @@
import { EmailThreadMessageParticipant } from '@/activities/emails/types/EmailThreadMessageParticipant';
import { getDisplayNameFromParticipant } from '../getDisplayNameFromParticipant';
describe('getDisplayNameFromParticipant', () => {
const participantWithName: EmailThreadMessageParticipant = {
displayName: '',
handle: '',
role: 'from',
person: {
id: '1',
createdAt: '',
updatedAt: '',
deletedAt: null,
name: {
firstName: 'John',
lastName: 'Doe',
},
avatarUrl: '',
jobTitle: '',
linkedinLink: {
url: '',
label: '',
},
xLink: {
url: '',
label: '',
},
city: '',
email: '',
phone: '',
companyId: '',
},
workspaceMember: {
id: '1',
name: {
firstName: 'Jane',
lastName: 'Smith',
},
locale: '',
createdAt: '',
updatedAt: '',
userEmail: '',
userId: '',
},
};
const participantWithHandle: any = {
displayName: '',
handle: 'user_handle',
role: 'from',
};
const participantWithDisplayName: any = {
displayName: 'User123',
handle: '',
role: 'from',
};
const participantWithoutInfo: any = {
displayName: '',
handle: '',
role: 'from',
};
it('should return full name when shouldUseFullName is true', () => {
expect(
getDisplayNameFromParticipant({
participant: participantWithName,
shouldUseFullName: true,
}),
).toBe('John Doe');
});
it('should return first name when shouldUseFullName is false', () => {
expect(
getDisplayNameFromParticipant({ participant: participantWithName }),
).toBe('John');
});
it('should return displayName if it is a non-empty string', () => {
expect(
getDisplayNameFromParticipant({
participant: participantWithDisplayName,
}),
).toBe('User123');
});
it('should return handle if displayName is not available', () => {
expect(
getDisplayNameFromParticipant({ participant: participantWithHandle }),
).toBe('user_handle');
});
it('should return Unknown if no suitable information is available', () => {
expect(
getDisplayNameFromParticipant({ participant: participantWithoutInfo }),
).toBe('Unknown');
});
});