Add jest tests for twenty-front (#2983)

* Add jest tests for twenty-front

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

* Fix tests

---------

Co-authored-by: gitstart-twenty <gitstart-twenty@users.noreply.github.com>
Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
gitstart-twenty
2023-12-15 17:53:20 +08:00
committed by GitHub
parent af9d3fb217
commit 5f7442cf23
27 changed files with 693 additions and 2 deletions

View File

@ -0,0 +1,27 @@
import { EntityForSelect } from '@/object-record/relation-picker/types/EntityForSelect';
import { flatMapAndSortEntityForSelectArrayOfArrayByName } from '../flatMapAndSortEntityForSelectArrayByName';
describe('flatMapAndSortEntityForSelectArrayOfArrayByName', () => {
it('should return the correct value', () => {
const entityForSelectArray = [
[
{ id: 1, name: 'xRya' },
{ id: 2, name: 'BrcA' },
],
[
{ id: 3, name: 'aCxd' },
{ id: 4, name: 'kp7u' },
],
] as unknown as EntityForSelect[][];
const res =
flatMapAndSortEntityForSelectArrayOfArrayByName(entityForSelectArray);
expect(res).toHaveLength(4);
expect(res[0].id).toBe(3);
expect(res[1].id).toBe(2);
expect(res[2].id).toBe(4);
expect(res[3].id).toBe(1);
});
});

View File

@ -0,0 +1,47 @@
import { ActivityTargetableEntity } from '@/activities/types/ActivityTargetableEntity';
import { getTargetableEntitiesWithParents } from '@/activities/utils/getTargetableEntitiesWithParents';
describe('getTargetableEntitiesWithParents', () => {
it('should return the correct value', () => {
const entities: ActivityTargetableEntity[] = [
{
id: '1',
type: 'Person',
relatedEntities: [
{
id: '2',
type: 'Company',
},
],
},
{
id: '4',
type: 'Company',
},
{
id: '3',
type: 'Custom',
relatedEntities: [
{
id: '6',
type: 'Person',
},
{
id: '5',
type: 'Company',
},
],
},
];
const res = getTargetableEntitiesWithParents(entities);
expect(res).toHaveLength(6);
expect(res[0].id).toBe('1');
expect(res[1].id).toBe('2');
expect(res[2].id).toBe('4');
expect(res[3].id).toBe('3');
expect(res[4].id).toBe('6');
expect(res[5].id).toBe('5');
});
});