Skip to content

Commit

Permalink
add tests for mission general info initial form
Browse files Browse the repository at this point in the history
  • Loading branch information
aleckvincent committed Dec 10, 2024
1 parent 7d5d3ab commit ff97713
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

import { MissionTypeEnum } from '@common/types/env-mission-types'
import MissionGeneralInformationUlamFormNew from '../mission-general-information-ulam-form-new.tsx'
import { render, fireEvent, screen } from '../../../../../../test-utils.tsx'



describe('MissionGeneralInformationUlamFormNew', () => {
it('renders the form with initial values', () => {
render(
<MissionGeneralInformationUlamFormNew
startDateTimeUtc="2024-01-01T00:00:00Z"
endDateTimeUtc="2024-01-01T00:00:00Z"
missionType={[MissionTypeEnum.AIR]}
onClose={vi.fn()}
/>
)

expect(screen.getByText('Type de mission')).toBeInTheDocument()
})

it('check if form submitted', () => {
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});

render(
<MissionGeneralInformationUlamFormNew
startDateTimeUtc="2024-01-01T00:00:00Z"
endDateTimeUtc="2024-01-01T00:00:00Z"
missionType={[MissionTypeEnum.AIR]}
onClose={vi.fn()}
/>
);

fireEvent.click(screen.getByText('Créer le rapport'));

// TODO: a remplacer par le check d'un appel api
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('Form Submitted'), expect.any(Object));

consoleSpy.mockRestore();
});
})
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ const MissionGeneralInformationUlamFormNew: React.FC<MissionGeneralInformationUl


const handleSubmit = (values) => {
if (values.missionGeneralInfo.missionReportType !== MissionReportTypeEnum.EXTERNAL_REINFORCEMENT_TIME_REPORT) {
values.missionGeneralInfo.reinforcementType = null
if (
values?.missionGeneralInfo?.missionReportType !== MissionReportTypeEnum.EXTERNAL_REINFORCEMENT_TIME_REPORT
) {
values.missionGeneralInfo = values.missionGeneralInfo || {}
values.missionGeneralInfo.reinforcementType = null;
}
console.log('Form Submitted:', values)
}
console.log('Form Submitted:', values);
};


return (
<>
Expand Down

0 comments on commit ff97713

Please sign in to comment.