Newer
Older
import { render, screen, waitFor } from '@testing-library/react'
import { userEvent } from '@testing-library/user-event'
import { FluidType } from 'enums'
import { Provider } from 'react-redux'
import { graphData } from 'tests/__mocks__/chartData.mock'
import { createMockEcolyoStore } from 'tests/__mocks__/store'
import MaxConsumptionCard from './MaxConsumptionCard'
const mockGetGraphData = jest.fn(() => graphData)
jest.mock('services/consumption.service', () => {
getGraphData: mockGetGraphData,
}))
describe('MaxConsumptionCard component', () => {
it('should be rendered correctly', async () => {
<Provider store={store}>
<MaxConsumptionCard
fluidsWithData={[FluidType.ELECTRICITY, FluidType.GAS]}
/>
await waitFor(() => null, { container })
expect(container).toMatchSnapshot()
it('should be rendered with one fluid and not display arrows', async () => {
<Provider store={store}>
<MaxConsumptionCard fluidsWithData={[FluidType.ELECTRICITY]} />
expect(
screen.getByLabelText('consumption.accessibility.button_previous_value')
).toBeDisabled()
expect(
screen.getByLabelText('consumption.accessibility.button_next_value')
).toBeDisabled()
})
it('should be rendered with several fluids and click navigate between fluid', async () => {
<Provider store={store}>
<MaxConsumptionCard
fluidsWithData={[FluidType.ELECTRICITY, FluidType.GAS]}
/>
const prevButton = screen.getByLabelText(
'consumption.accessibility.button_previous_value'
)
const nextButton = screen.getByLabelText(
'consumption.accessibility.button_next_value'
)
expect(screen.getByText('FLUID.GAS.LABEL')).toBeInTheDocument()
expect(screen.getByText('FLUID.ELECTRICITY.LABEL')).toBeInTheDocument()
expect(screen.getByText('FLUID.GAS.LABEL')).toBeInTheDocument()
expect(screen.getByText('FLUID.ELECTRICITY.LABEL')).toBeInTheDocument()