From 5fc7c3cde6bca428fcf9391502b25252442e246b Mon Sep 17 00:00:00 2001 From: aleckvincent Date: Wed, 24 Jul 2024 10:29:26 +0200 Subject: [PATCH] [frontend] add test mouseOver MissionItem button export should display --- .../src/pam/mission/mission-item.test.tsx | 61 +++++++------------ 1 file changed, 22 insertions(+), 39 deletions(-) diff --git a/frontend/src/pam/mission/mission-item.test.tsx b/frontend/src/pam/mission/mission-item.test.tsx index d8cefe551..df361b157 100644 --- a/frontend/src/pam/mission/mission-item.test.tsx +++ b/frontend/src/pam/mission/mission-item.test.tsx @@ -5,9 +5,10 @@ import {Mission} from '../../types/mission-types.ts' import { CompletenessForStatsStatusEnum, MissionStatusEnum } from '../../types/mission-types.ts' import MissionItem from './mission-item.tsx' import { fireEvent } from '@testing-library/react' +import useIsMissionCompleteForStats from './use-is-mission-complete-for-stats.tsx' -const completeMission = { +const mission = { id: 3, startDateTimeUtc: '2022-08-07T12:00:00Z', endDateTimeUtc: '2022-08-19T12:00:00Z', @@ -17,49 +18,31 @@ const completeMission = { } } as unknown as Mission -const incompleteMission = { - id: 3, - startDateTimeUtc: '2022-08-07T12:00:00Z', - endDateTimeUtc: '2022-08-19T12:00:00Z', - status: MissionStatusEnum.ENDED, - completenessForStats: { - status: CompletenessForStatsStatusEnum.INCOMPLETE - } -} as unknown as Mission - -describe('MissionsItem component', () => { - test('should render the Complété status', () => { - render() - expect(screen.getByText('Complété', { exact: false })).toBeInTheDocument() - }) -}) -/*describe('Export mission odt button', () => { - test('should render the Exporter le rapport de mission button', () => { - // Render the MissionItem component - const { container } = render() +vi.mock('./use-is-mission-complete-for-stats'); +const mockedUseIsMissionCompleteForStats = useIsMissionCompleteForStats as jest.Mock; - // Find the root element of the MissionItem component - const missionItemElement = container.firstChild - // Ensure the button is not in the document before the hover event - expect(screen.queryByText('Exporter le rapport de mission', { exact: false })).not.toBeInTheDocument() +describe('Export mission odt button', () => { + test('should render the Exporter le rapport de mission button on mouse over', () => { + mockedUseIsMissionCompleteForStats.mockReturnValue(true); - // Ensure the element is not null before firing the mouseOver event - if (missionItemElement) { - fireEvent.mouseOver(missionItemElement) - } else { - throw new Error('MissionItem element not found') - } + const { container } = render() + const missionItemElement = container.firstChild - // Expect the button to be in the document after the hover event - expect(screen.getByText('Exporter le rapport de mission', { exact: false })).toBeInTheDocument() + expect(screen.queryByText('Exporter le rapport de la mission', { exact: false })).not.toBeInTheDocument() + fireEvent.mouseOver(missionItemElement) + expect(screen.getByText('Exporter le rapport de la mission', { exact: false })).toBeInTheDocument() }) -})*/ +}) + +describe('Export mission odt button not available', () => { + test('should not render the Exporter le rapport de mission button on mouse over', () => { + mockedUseIsMissionCompleteForStats.mockReturnValue(false); -/*describe('Export mission odt button not available', () => { - test('should render the Exporter le rapport de mission button', () => { - render() - expect(screen.getByText('Exporter le rapport de mission', { exact: false })).not.toBeInTheDocument() + const { container } = render() + const missionItemElement = container.firstChild + fireEvent.mouseOver(missionItemElement) + expect(screen.queryByText('Exporter le rapport de la mission', { exact: false })).not.toBeInTheDocument() }) -})*/ +})