Skip to content
Snippets Groups Projects
Navbar.spec.tsx 1.75 KiB
Newer Older
  • Learn to ignore specific revisions
  • Bastien DUMONT's avatar
    Bastien DUMONT committed
    import { render, screen } from '@testing-library/react'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import Navbar from 'components/Navbar/Navbar'
    import React from 'react'
    
    Yoan VALLET's avatar
    Yoan VALLET committed
    import { Provider } from 'react-redux'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import { BrowserRouter } from 'react-router-dom'
    
    import { createMockEcolyoStore } from 'tests/__mocks__/store'
    
    
    describe('Navbar component', () => {
    
    Yoan VALLET's avatar
    Yoan VALLET committed
      it('should be rendered correctly with 5 navlink', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const store = createMockEcolyoStore()
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        render(
    
    Yoan VALLET's avatar
    Yoan VALLET committed
          <Provider store={store}>
            <BrowserRouter>
              <Navbar />
            </BrowserRouter>
          </Provider>
        )
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        expect(screen.getAllByRole('link').length).toBe(5)
    
    Yoan VALLET's avatar
    Yoan VALLET committed
      })
    
    
      it('should be rendered correctly with notifications', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const store = createMockEcolyoStore({
          global: {
            challengeExplorationNotification: true,
            challengeActionNotification: false,
            challengeDuelNotification: false,
            analysisNotification: true,
    
    Yoan VALLET's avatar
    Yoan VALLET committed
          },
        })
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const { container } = render(
    
    Yoan VALLET's avatar
    Yoan VALLET committed
          <Provider store={store}>
            <BrowserRouter>
              <Navbar />
            </BrowserRouter>
          </Provider>
        )
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const notifElements = container.getElementsByClassName('nb-notif')
        expect(notifElements.length).toBe(2)
    
      })
    
      it('should be rendered correctly without notifications', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const store = createMockEcolyoStore({
          global: {
            challengeExplorationNotification: false,
            challengeActionNotification: false,
            challengeDuelNotification: false,
            analysisNotification: false,
    
    Yoan VALLET's avatar
    Yoan VALLET committed
          },
        })
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const { container } = render(
    
    Yoan VALLET's avatar
    Yoan VALLET committed
          <Provider store={store}>
            <BrowserRouter>
              <Navbar />
            </BrowserRouter>
          </Provider>
        )
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const notifElements = container.getElementsByClassName('nb-notif')
        expect(notifElements.length).toBe(0)