Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some Quality #1058

Merged
merged 5 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/packages/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
14 changes: 14 additions & 0 deletions src/packages/model/Dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
2 changes: 1 addition & 1 deletion src/packages/modules-classifications/item/notes.jsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
8 changes: 2 additions & 6 deletions src/packages/modules-concepts/visualization/home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
3 changes: 2 additions & 1 deletion src/packages/modules-datasets/datasets.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -16,7 +17,7 @@ export const useDatasetsForDistributions = () => {
};

export const useDistributions = () => {
return useQuery({
return useQuery<PartialDistribution[]>({
queryFn: () => DistributionApi.getAll(),
queryKey: ['distributions'],
});
Expand Down
10 changes: 7 additions & 3 deletions src/packages/modules-datasets/distributions/home/home.tsx
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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
}
/>
</div>
</Row>
Expand Down
42 changes: 42 additions & 0 deletions src/packages/utils/hooks/stamps.spec.tsx
Original file line number Diff line number Diff line change
@@ -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<unknown>) => (
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
);

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' },
]);
});
});
Loading