-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1078 from InseeFr/1075-quand-je-recherche-une-sri…
…e-recherche-avance-le-type-dopration-slectionn-ne-reste-pas-affich-dans-le-champ fix: type code was not initialized and back button not work on export
- Loading branch information
Showing
5 changed files
with
154 additions
and
41 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
src/packages/modules-concepts/collections/export/home-container.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { Mock, vi } from 'vitest'; | ||
import { Component } from './home-container'; | ||
import { | ||
useCollections, | ||
useCollectionExporter, | ||
} from '../../../utils/hooks/collections'; | ||
import { useTitle } from '../../../utils/hooks/useTitle'; | ||
import { Picker } from '../../../components'; | ||
import D from '../../../deprecated-locales/build-dictionary'; | ||
|
||
// Mock des hooks | ||
vi.mock('../../../utils/hooks/collections', () => ({ | ||
useCollections: vi.fn(), | ||
useCollectionExporter: vi.fn(), | ||
})); | ||
|
||
vi.mock('../../../utils/hooks/useTitle', () => ({ | ||
useTitle: vi.fn(), | ||
})); | ||
|
||
vi.mock('../../../components', () => ({ | ||
Picker: vi.fn(() => <div data-testid="picker-mock" />), | ||
Loading: () => <div data-testid="loading-mock" />, | ||
})); | ||
|
||
describe('Component', () => { | ||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it('displays the loader while loading collections', () => { | ||
(useCollections as Mock).mockReturnValue({ | ||
data: [], | ||
isLoading: true, | ||
}); | ||
(useCollectionExporter as Mock).mockReturnValue({ | ||
mutate: vi.fn(), | ||
isPending: false, | ||
}); | ||
|
||
render(<Component />); | ||
|
||
screen.getByTestId('loading-mock'); | ||
}); | ||
|
||
it('displays the loader during export', () => { | ||
(useCollections as Mock).mockReturnValue({ | ||
data: [], | ||
isLoading: false, | ||
}); | ||
(useCollectionExporter as Mock).mockReturnValue({ | ||
mutate: vi.fn(), | ||
isPending: true, | ||
}); | ||
|
||
render(<Component />); | ||
|
||
screen.getByTestId('loading-mock'); | ||
}); | ||
|
||
it('displays Picker with the correct props after loading', () => { | ||
const collectionsMock = [{ id: 1, label: 'Collection 1' }]; | ||
(useCollections as Mock).mockReturnValue({ | ||
data: collectionsMock, | ||
isLoading: false, | ||
}); | ||
(useCollectionExporter as Mock).mockReturnValue({ | ||
mutate: vi.fn(), | ||
isPending: false, | ||
}); | ||
|
||
render(<Component />); | ||
|
||
screen.getByTestId('picker-mock'); | ||
expect(Picker).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
items: collectionsMock, | ||
title: D.exportTitle, | ||
panelTitle: D.collectionsExportPanelTitle, | ||
labelWarning: D.hasNotCollectionToExport, | ||
context: 'concepts/collections', | ||
disabled: true, // ids.length < 1 | ||
}), | ||
{}, | ||
); | ||
}); | ||
|
||
it('calls useTitle with the correct titles', () => { | ||
render(<Component />); | ||
|
||
expect(useTitle).toHaveBeenCalledWith(D.collectionsTitle, D.exportTitle); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/packages/modules-operations/series/search/typeCodeInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Select } from '../../../components/select-rmes'; | ||
import D from '../../../deprecated-locales'; | ||
import { Option } from '../../../model/SelectOption'; | ||
import { CL_SOURCE_CATEGORY } from '../../../redux/actions/constants/codeList'; | ||
import { useCodesList } from '../../../utils/hooks/codeslist'; | ||
|
||
type TypeCodeInputTypes = { | ||
value: string; | ||
onChange: (value: string) => void; | ||
}; | ||
export const TypeCodeInput = ({ | ||
value, | ||
onChange, | ||
}: Readonly<TypeCodeInputTypes>) => { | ||
const categories = useCodesList(CL_SOURCE_CATEGORY); | ||
const options: Option[] = categories?.codes?.map((cat) => { | ||
return { value: cat.code, label: cat.labelLg1 }; | ||
}); | ||
|
||
return ( | ||
<label className="w-100"> | ||
{D.operationType} | ||
|
||
<Select | ||
placeholder="" | ||
value={value} | ||
options={options} | ||
onChange={onChange} | ||
/> | ||
</label> | ||
); | ||
}; |