Skip to content

Commit

Permalink
[frontend] add test mouseOver MissionItem button export should display
Browse files Browse the repository at this point in the history
  • Loading branch information
aleckvincent committed Jul 24, 2024
1 parent 43a4e9e commit 5fc7c3c
Showing 1 changed file with 22 additions and 39 deletions.
61 changes: 22 additions & 39 deletions frontend/src/pam/mission/mission-item.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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(<MissionItem mission={completeMission} prefetchMission={vi.fn()} />)
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(<MissionItem mission={completeMission} prefetchMission={vi.fn()} />)
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(<MissionItem mission={mission} prefetchMission={vi.fn()} />)
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(<MissionItem mission={incompleteMission} prefetchMission={vi.fn()} />)
expect(screen.getByText('Exporter le rapport de mission', { exact: false })).not.toBeInTheDocument()
const { container } = render(<MissionItem mission={mission} prefetchMission={vi.fn()} />)
const missionItemElement = container.firstChild
fireEvent.mouseOver(missionItemElement)
expect(screen.queryByText('Exporter le rapport de la mission', { exact: false })).not.toBeInTheDocument()
})
})*/
})

0 comments on commit 5fc7c3c

Please sign in to comment.