-
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 #1042 from InseeFr/feat/add-unit-test
Feat/add unit test
- Loading branch information
Showing
4 changed files
with
61 additions
and
14 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,13 +1,31 @@ | ||
import { AdvancedSearchControls } from './controls'; | ||
import { render } from '@testing-library/react'; | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
|
||
describe('concepts-advanced-search-controls', () => { | ||
it('renders without crashing', () => { | ||
const mockOnClickReturn = vi.fn(); | ||
const mockInitializeState = vi.fn(); | ||
|
||
beforeEach(() => { | ||
render( | ||
<AdvancedSearchControls | ||
onClickReturn={vi.fn()} | ||
initializeState={vi.fn()} | ||
onClickReturn={mockOnClickReturn} | ||
initializeState={mockInitializeState} | ||
/>, | ||
); | ||
}); | ||
|
||
it('should render ReturnButton and ResetButton', () => { | ||
screen.getByRole('button', { name: /back/i }); | ||
screen.getByRole('button', { name: /reinitialize/i }); | ||
}); | ||
|
||
it('should call onClickReturn when ReturnButton is clicked', () => { | ||
fireEvent.click(screen.getByRole('button', { name: /back/i })); | ||
expect(mockOnClickReturn).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should call initializeState when ResetButton is clicked', () => { | ||
fireEvent.click(screen.getByRole('button', { name: /reinitialize/i })); | ||
expect(mockInitializeState).toHaveBeenCalled(); | ||
}); | ||
}); |
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
37 changes: 37 additions & 0 deletions
37
src/packages/modules-concepts/utils/build-payload-creation-update/shared.spec.ts
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,37 @@ | ||
import { processGeneral } from './shared'; | ||
|
||
describe('processGeneral', () => { | ||
it('should process general object correctly', () => { | ||
const input = { | ||
valid: 'T12:00:00.000Z', | ||
additionalMaterial: 'http://example.com/resource', | ||
}; | ||
const keys = ['valid', 'additionalMaterial']; | ||
|
||
const expectedOutput = { | ||
valid: 'T00:00:00.000Z', | ||
additionalMaterial: 'http://example.com/resource', | ||
}; | ||
|
||
const result = processGeneral(input, keys); | ||
|
||
expect(result).toEqual(expectedOutput); | ||
}); | ||
|
||
it('should handle missing additionalMaterial', () => { | ||
const input = { | ||
valid: 'T12:00:00.000Z', | ||
additionalMaterial: undefined, | ||
}; | ||
const keys = ['valid', 'additionalMaterial']; | ||
|
||
const expectedOutput = { | ||
valid: 'T00:00:00.000Z', | ||
additionalMaterial: '', | ||
}; | ||
|
||
const result = processGeneral(input, keys); | ||
|
||
expect(result).toEqual(expectedOutput); | ||
}); | ||
}); |
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