Add tests for modules/object-record/object-sort-dropdown (#3398)
Co-authored-by: gitstart-twenty <gitstart-twenty@users.noreply.github.com> Co-authored-by: RubensRafael <rubensrafael2@live.com>
This commit is contained in:
@ -19,7 +19,7 @@ const sortDefinitions: SortDefinition[] = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
describe('useSortDropdown', () => {
|
describe('useSortDropdown', () => {
|
||||||
it('should set availableSortDefinitions', () => {
|
it('should set availableSortDefinitions', async () => {
|
||||||
const { result } = renderHook(
|
const { result } = renderHook(
|
||||||
() => useSortDropdown({ sortDropdownId }),
|
() => useSortDropdown({ sortDropdownId }),
|
||||||
renderHookConfig,
|
renderHookConfig,
|
||||||
@ -29,12 +29,12 @@ describe('useSortDropdown', () => {
|
|||||||
result.current.setAvailableSortDefinitions(sortDefinitions);
|
result.current.setAvailableSortDefinitions(sortDefinitions);
|
||||||
});
|
});
|
||||||
|
|
||||||
waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(result.current.availableSortDefinitions).toEqual(sortDefinitions);
|
expect(result.current.availableSortDefinitions).toEqual(sortDefinitions);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set isSortSelected', () => {
|
it('should set isSortSelected', async () => {
|
||||||
const { result } = renderHook(
|
const { result } = renderHook(
|
||||||
() => useSortDropdown({ sortDropdownId }),
|
() => useSortDropdown({ sortDropdownId }),
|
||||||
renderHookConfig,
|
renderHookConfig,
|
||||||
@ -46,13 +46,14 @@ describe('useSortDropdown', () => {
|
|||||||
result.current.setIsSortSelected(true);
|
result.current.setIsSortSelected(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(result.current.isSortSelected).toBe(true);
|
expect(result.current.isSortSelected).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set onSortSelect', () => {
|
it('should set onSortSelect', async () => {
|
||||||
const mockOnSortSelect = jest.fn();
|
const OnSortSelectFunction = () => {};
|
||||||
|
const mockOnSortSelect = jest.fn(() => OnSortSelectFunction);
|
||||||
const { result } = renderHook(
|
const { result } = renderHook(
|
||||||
() => useSortDropdown({ sortDropdownId }),
|
() => useSortDropdown({ sortDropdownId }),
|
||||||
renderHookConfig,
|
renderHookConfig,
|
||||||
@ -64,13 +65,13 @@ describe('useSortDropdown', () => {
|
|||||||
result.current.setOnSortSelect(mockOnSortSelect);
|
result.current.setOnSortSelect(mockOnSortSelect);
|
||||||
});
|
});
|
||||||
|
|
||||||
waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(result.current.onSortSelect).toBe(mockOnSortSelect);
|
expect(result.current.onSortSelect).toBe(OnSortSelectFunction);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call onSortSelect when a sort option is selected', () => {
|
it('should call onSortSelect when a sort option is selected', async () => {
|
||||||
const mockOnSortSelect = jest.fn();
|
const mockOnSortSelect = jest.fn(() => jest.fn());
|
||||||
const sort: Sort = {
|
const sort: Sort = {
|
||||||
fieldMetadataId: 'id',
|
fieldMetadataId: 'id',
|
||||||
direction: 'asc',
|
direction: 'asc',
|
||||||
@ -87,8 +88,12 @@ describe('useSortDropdown', () => {
|
|||||||
result.current.onSortSelect?.(sort);
|
result.current.onSortSelect?.(sort);
|
||||||
});
|
});
|
||||||
|
|
||||||
waitFor(() => {
|
act(() => {
|
||||||
expect(mockOnSortSelect).toHaveBeenCalledWith(sort);
|
result.current.onSortSelect?.(sort);
|
||||||
|
});
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(mockOnSortSelect.mock.results[0].value).toHaveBeenCalledWith(sort);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user