mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* first part of transition * second part of transition * remove jest * bump up node version and playwright version * update all screenshots because of the new playwright version * fix tests * one more screenshot update
90 lines
2.1 KiB
TypeScript
90 lines
2.1 KiB
TypeScript
// @vitest-environment jsdom
|
|
|
|
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
import { renderHook } from 'vitest/lib';
|
|
|
|
import { useAddressClusters } from './useAddressClusters';
|
|
|
|
const { mockUseApiQuery } = vi.hoisted(() => ({
|
|
mockUseApiQuery: vi.fn(),
|
|
}));
|
|
|
|
vi.mock('lib/api/useApiQuery', () => ({
|
|
'default': mockUseApiQuery,
|
|
}));
|
|
|
|
vi.mock('configs/app', async() => {
|
|
return {
|
|
'default': {
|
|
UI: {
|
|
colorTheme: {},
|
|
homepage: {},
|
|
fonts: {},
|
|
},
|
|
features: {
|
|
nameServices: {
|
|
isEnabled: true,
|
|
ens: { isEnabled: true },
|
|
clusters: { isEnabled: true },
|
|
},
|
|
},
|
|
},
|
|
};
|
|
});
|
|
|
|
describe('useAddressClusters', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
mockUseApiQuery.mockReturnValue({ data: null, isLoading: false });
|
|
});
|
|
|
|
it('should call API with correct parameters', () => {
|
|
const addressHash = '0x1234567890123456789012345678901234567890';
|
|
|
|
renderHook(() => useAddressClusters(addressHash));
|
|
|
|
expect(mockUseApiQuery).toHaveBeenCalledWith('clusters:get_clusters_by_address', {
|
|
queryParams: {
|
|
input: JSON.stringify({
|
|
address: addressHash,
|
|
}),
|
|
},
|
|
queryOptions: {
|
|
enabled: true,
|
|
},
|
|
});
|
|
});
|
|
|
|
it('should be disabled when addressHash is empty', () => {
|
|
renderHook(() => useAddressClusters(''));
|
|
|
|
expect(mockUseApiQuery).toHaveBeenCalledWith('clusters:get_clusters_by_address', {
|
|
queryParams: {
|
|
input: JSON.stringify({
|
|
address: '',
|
|
}),
|
|
},
|
|
queryOptions: {
|
|
enabled: false,
|
|
},
|
|
});
|
|
});
|
|
|
|
it('should handle isEnabled parameter', () => {
|
|
const addressHash = '0x1234567890123456789012345678901234567890';
|
|
|
|
renderHook(() => useAddressClusters(addressHash, false));
|
|
|
|
expect(mockUseApiQuery).toHaveBeenCalledWith('clusters:get_clusters_by_address', {
|
|
queryParams: {
|
|
input: JSON.stringify({
|
|
address: addressHash,
|
|
}),
|
|
},
|
|
queryOptions: {
|
|
enabled: false,
|
|
},
|
|
});
|
|
});
|
|
});
|