Increase test coverage for /modules/ui (#3314)

* Increase test coverage for `/modules/ui`

Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: FellipeMTX <fellipefacdir@gmail.com>
Co-authored-by: Fellipe Montes <102544529+FellipeMTX@users.noreply.github.com>

* Merge main

Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: FellipeMTX <fellipefacdir@gmail.com>
Co-authored-by: Fellipe Montes <102544529+FellipeMTX@users.noreply.github.com>

* Fix tests

* Fix tests

* Fix

---------

Co-authored-by: gitstart-twenty <gitstart-twenty@users.noreply.github.com>
Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: FellipeMTX <fellipefacdir@gmail.com>
Co-authored-by: Fellipe Montes <102544529+FellipeMTX@users.noreply.github.com>
Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
gitstart-twenty
2024-01-11 08:51:36 +01:00
committed by GitHub
parent f34516d422
commit ebe8698910
48 changed files with 1652 additions and 55 deletions

View File

@ -0,0 +1,40 @@
import { renderHook } from '@testing-library/react';
import * as recoil from 'recoil';
import { Icon123, IconBuildingSkyscraper, IconUser } from '@/ui/display/icon';
import { useIcons } from '@/ui/display/icon/hooks/useIcons';
describe('useIcons', () => {
const mockedStateIcons = {
IconUser,
Icon123,
IconBuildingSkyscraper,
};
jest
.spyOn(recoil, 'useRecoilValue')
.mockImplementationOnce(() => mockedStateIcons);
const { result } = renderHook(() => useIcons(), {
wrapper: recoil.RecoilRoot,
});
it('returns default icon when no icon key is provided', () => {
expect(result.current.getIcon()).toEqual(Icon123);
});
it('returns the specified icon if the icon key exists in the iconsState', () => {
expect(result.current.getIcon('Icon123')).toEqual(Icon123);
expect(result.current.getIcon('IconUser')).toEqual(IconUser);
expect(result.current.getIcon('IconBuildingSkyscraper')).toEqual(
IconBuildingSkyscraper,
);
});
it('returns default icon if the specified icon key does not exist in the iconsState', () => {
expect(result.current.getIcon('nonExistentKey')).toEqual(Icon123);
});
it('returns all icons in getIcons', () => {
expect(result.current.getIcons()).toEqual(mockedStateIcons);
expect(Object.keys(result.current.getIcons())).toHaveLength(3);
});
});