diff --git a/src/packages/components/index.ts b/src/packages/components/index.ts index f79532e5b..58978f205 100644 --- a/src/packages/components/index.ts +++ b/src/packages/components/index.ts @@ -19,7 +19,6 @@ export * from './link/'; export * from './loading/loading'; export * from './new-button'; export * from './not-found'; -export * from './note-visualization'; export * from './page-title-block'; export * from './pagination'; export * from './picker-page'; diff --git a/src/packages/model/Dataset.ts b/src/packages/model/Dataset.ts index abcd1732e..387866a34 100644 --- a/src/packages/model/Dataset.ts +++ b/src/packages/model/Dataset.ts @@ -45,3 +45,17 @@ export type Distribution = { id?: string; validationState: ValidationState; }; + +export type PartialDistribution = { + id: string; + idDataset: string; + labelLg1: string; + labelLg2: string; + descriptionLg1: string; + descriptionLg2: string; + created: string; + updated: string; + format: string; + byteSize: string; + url: string; +}; diff --git a/src/packages/modules-classifications/item/notes.jsx b/src/packages/modules-classifications/item/notes.jsx index 915331246..b00478ba9 100644 --- a/src/packages/modules-classifications/item/notes.jsx +++ b/src/packages/modules-classifications/item/notes.jsx @@ -1,4 +1,4 @@ -import { NoteVisualization } from '../../components'; +import { NoteVisualization } from '../../components/note-visualization'; import { buildNotes } from '../utils/classification/notes'; import D, { D2 } from '../../deprecated-locales'; import { delPTags } from '../../utils/html-utils'; diff --git a/src/packages/modules-concepts/administration/dashboard/concepts/controls.spec.jsx b/src/packages/modules-concepts/administration/dashboard/concepts/controls.spec.tsx similarity index 100% rename from src/packages/modules-concepts/administration/dashboard/concepts/controls.spec.jsx rename to src/packages/modules-concepts/administration/dashboard/concepts/controls.spec.tsx diff --git a/src/packages/modules-concepts/administration/dashboard/concepts/controls.jsx b/src/packages/modules-concepts/administration/dashboard/concepts/controls.tsx similarity index 100% rename from src/packages/modules-concepts/administration/dashboard/concepts/controls.jsx rename to src/packages/modules-concepts/administration/dashboard/concepts/controls.tsx diff --git a/src/packages/modules-concepts/administration/home.jsx b/src/packages/modules-concepts/administration/home.tsx similarity index 100% rename from src/packages/modules-concepts/administration/home.jsx rename to src/packages/modules-concepts/administration/home.tsx diff --git a/src/packages/modules-concepts/visualization/home.jsx b/src/packages/modules-concepts/visualization/home.jsx index cd5312c0f..220838820 100644 --- a/src/packages/modules-concepts/visualization/home.jsx +++ b/src/packages/modules-concepts/visualization/home.jsx @@ -3,12 +3,8 @@ import ConceptVisualizationControls from './controls'; import ConceptGeneral from './general'; import ConceptLinks from './links'; import D from '../../deprecated-locales'; -import { - ErrorBloc, - PageTitleBlock, - CheckSecondLang, - NoteVisualization, -} from '../../components'; +import { ErrorBloc, PageTitleBlock, CheckSecondLang } from '../../components'; +import { NoteVisualization } from '../../components/note-visualization'; import { ModalRmes } from '../../components/modal-rmes/modal-rmes'; import { useTitle } from '../../utils/hooks/useTitle'; import { isOutOfDate } from '../../utils/date-utils'; diff --git a/src/packages/modules-datasets/datasets.ts b/src/packages/modules-datasets/datasets.ts index 97e9e600c..07cc7d7f4 100644 --- a/src/packages/modules-datasets/datasets.ts +++ b/src/packages/modules-datasets/datasets.ts @@ -1,5 +1,6 @@ import { useQuery } from '@tanstack/react-query'; import { DatasetsApi, DistributionApi } from '../sdk'; +import { PartialDistribution } from '../model/Dataset'; export const useDatasets = () => { return useQuery({ @@ -16,7 +17,7 @@ export const useDatasetsForDistributions = () => { }; export const useDistributions = () => { - return useQuery({ + return useQuery({ queryFn: () => DistributionApi.getAll(), queryKey: ['distributions'], }); diff --git a/src/packages/modules-datasets/distributions/home/home.tsx b/src/packages/modules-datasets/distributions/home/home.tsx index b9e42ccc7..df761ba18 100644 --- a/src/packages/modules-datasets/distributions/home/home.tsx +++ b/src/packages/modules-datasets/distributions/home/home.tsx @@ -1,8 +1,10 @@ +import { Loading, PageTitle, SearchableList } from '../../../components'; +import { Row } from '../../../components/layout'; import D from '../../../deprecated-locales/build-dictionary'; +import { PartialDistribution } from '../../../model/Dataset'; +import { useTitle } from '../../../utils/hooks/useTitle'; import { useDistributions } from '../../datasets'; import { HomePageMenu } from './menu'; -import { Loading, PageTitle, Row, SearchableList } from '../../../components'; -import { useTitle } from '../../../utils/hooks/useTitle'; export const Component = () => { const { data, isLoading } = useDistributions(); @@ -22,7 +24,9 @@ export const Component = () => { items={data ?? []} childPath="datasets/distributions" advancedSearch={false} - itemFormatter={(_: any, dataset: any) => dataset.labelLg1} + itemFormatter={(_: unknown, distribution: PartialDistribution) => + distribution.labelLg1 + } /> diff --git a/src/packages/utils/hooks/stamps.spec.tsx b/src/packages/utils/hooks/stamps.spec.tsx new file mode 100644 index 000000000..47ae932db --- /dev/null +++ b/src/packages/utils/hooks/stamps.spec.tsx @@ -0,0 +1,42 @@ +import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; +import { renderHook, waitFor } from '@testing-library/react'; +import { PropsWithChildren } from 'react'; +import { vi } from 'vitest'; +import { useStamps, useStampsOptions } from './stamps'; + +// Mock de l'API +vi.mock('../../sdk', () => ({ + StampsApi: { + getStamps: () => ['stamp1', 'stamp2'], + }, +})); + +const queryClient = new QueryClient(); +const wrapper = ({ children }: PropsWithChildren) => ( + {children} +); + +describe('useStamps', () => { + it('should fetch stamps', async () => { + const mockStamps = ['stamp1', 'stamp2']; + + const { result } = renderHook(() => useStamps(), { wrapper }); + + await waitFor(() => expect(result.current.isSuccess).toBe(true)); + + expect(result.current.data).toEqual(mockStamps); + }); +}); + +describe('useStampsOptions', () => { + it('should return stamps as options', async () => { + const { result } = renderHook(() => useStampsOptions(), { wrapper }); + + await waitFor(() => expect(result.current).toHaveLength(2)); + + expect(result.current).toEqual([ + { value: 'stamp1', label: 'stamp1' }, + { value: 'stamp2', label: 'stamp2' }, + ]); + }); +});