Skip to content
Snippets Groups Projects
FluidButton.spec.tsx 1.74 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { render, screen } from '@testing-library/react'
    
    import { FluidState, FluidType } from 'enums'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import { GlobalState } from 'models'
    
    import React from 'react'
    
    import { Provider } from 'react-redux'
    
    import { createMockEcolyoStore, mockGlobalState } from 'tests/__mocks__/store'
    
    import FluidButton from './FluidButton'
    
    
    describe('FluidButton component', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      const store = createMockEcolyoStore()
    
      it('should be rendered correctly', async () => {
    
        const { container } = render(
    
          <Provider store={store}>
            <FluidButton fluidType={FluidType.ELECTRICITY} isActive={false} />
          </Provider>
    
        expect(container).toMatchSnapshot()
    
      })
    
      it('should render multifluidButton', () => {
    
          <Provider store={store}>
            <FluidButton fluidType={FluidType.MULTIFLUID} isActive={false} />
          </Provider>
        )
    
        expect(screen.getByText('FLUID.MULTIFLUID.LABEL')).toBeInTheDocument()
    
      it('should render active gas button', () => {
    
        const { container } = render(
    
          <Provider store={store}>
    
            <FluidButton fluidType={FluidType.GAS} isActive={true} />
    
        expect(container.getElementsByClassName('active').length).toBeTruthy()
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const updatedInitialState: GlobalState = {
          ...mockGlobalState,
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        updatedInitialState.fluidStatus[FluidType.GAS].status = FluidState.ERROR
        const store = createMockEcolyoStore({
          global: updatedInitialState,
    
        const { container } = render(
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
          <Provider store={store}>
    
            <FluidButton fluidType={FluidType.GAS} isActive={false} />
          </Provider>
        )
    
        const element = container.getElementsByClassName('notif-error').item(0)
        expect(element).toBeInTheDocument()