-
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 #1083 from InseeFr/feat/add-unit-test-concepts
feat: add unit test
- Loading branch information
Showing
5 changed files
with
88 additions
and
15 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/packages/modules-concepts/collections/export-buttons/export-buttons.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,49 @@ | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import { vi } from 'vitest'; | ||
import ExportButtons from './'; | ||
import D from '../../../deprecated-locales/build-dictionary'; | ||
|
||
describe('ExportButtons Component', () => { | ||
it('should render all buttons with the correct labels', () => { | ||
render(<ExportButtons exportHandler={vi.fn()} disabled={false} />); | ||
|
||
screen.getByText(D.btnOdsExporter); | ||
screen.getByText(D.btnOdtLg1Exporter); | ||
screen.getByText(D.btnOdtLg2Exporter); | ||
screen.getByText(D.btnCollectionConceptExporter); | ||
}); | ||
|
||
it('should call exportHandler with correct arguments when buttons are clicked', () => { | ||
const mockExportHandler = vi.fn(); | ||
|
||
render( | ||
<ExportButtons exportHandler={mockExportHandler} disabled={false} />, | ||
); | ||
|
||
fireEvent.click(screen.getByText(D.btnOdsExporter)); | ||
expect(mockExportHandler).toHaveBeenCalledWith('ods', false); | ||
|
||
fireEvent.click(screen.getByText(D.btnOdtLg1Exporter)); | ||
expect(mockExportHandler).toHaveBeenCalledWith('odt', false); | ||
|
||
fireEvent.click(screen.getByText(D.btnOdtLg2Exporter)); | ||
expect(mockExportHandler).toHaveBeenCalledWith('odt', false, 'lg2'); | ||
|
||
fireEvent.click(screen.getByText(D.btnCollectionConceptExporter)); | ||
expect(mockExportHandler).toHaveBeenCalledWith('odt', true); | ||
}); | ||
|
||
it('should disable buttons when disabled is true', () => { | ||
render(<ExportButtons exportHandler={vi.fn()} disabled={true} />); | ||
|
||
const button = screen.getByText('Export') as HTMLButtonElement; | ||
expect(button.getAttribute('disabled')).toBeDefined(); | ||
}); | ||
|
||
it('should enable buttons when disabled is false', () => { | ||
render(<ExportButtons exportHandler={vi.fn()} disabled={false} />); | ||
|
||
const button = screen.getByText('Export') as HTMLButtonElement; | ||
expect(button.getAttribute('disabled')).toBeNull(); | ||
}); | ||
}); |
15 changes: 14 additions & 1 deletion
15
...epts/collections/export-buttons/index.jsx → ...epts/collections/export-buttons/index.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
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
18 changes: 18 additions & 0 deletions
18
src/packages/modules-operations/msd/pages/sims-creation/menu.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,18 @@ | ||
import { ActionToolbar } from '../../../../components/action-toolbar'; | ||
import { | ||
CancelButton, | ||
SaveButton, | ||
} from '../../../../components/buttons/buttons-with-icons'; | ||
|
||
type MenuTypes = { | ||
goBackUrl: () => void; | ||
handleSubmit: () => void; | ||
}; | ||
export const Menu = ({ goBackUrl, handleSubmit }: Readonly<MenuTypes>) => { | ||
return ( | ||
<ActionToolbar> | ||
<CancelButton action={goBackUrl} /> | ||
<SaveButton action={handleSubmit} /> | ||
</ActionToolbar> | ||
); | ||
}; |