import React from 'react'; import { render, fireEvent, cleanup } from '@testing-library/react'; import { Projects } from '../components/Projects'; beforeEach(cleanup); jest.mock('../context', () => ({ useSelectedProjectValue: jest.fn(() => ({ setSelectedProject: jest.fn(() => 'INBOX'), })), useProjectsValue: jest.fn(() => ({ projects: [ { name: '🙌 THE OFFICE', projectId: '1', userId: 'jlIFXIwyAL3tzHMtzRbw', docId: 'michael-scott', }, ], })), })); describe(' { afterEach(() => { jest.clearAllMocks(); }); describe('Success', () => { it('renders the projects', () => { const { queryByTestId } = render(); expect(queryByTestId('project-action')).toBeTruthy(); }); it('renders the projects and selects an active project using onClick', () => { const { queryByTestId } = render(); expect(queryByTestId('project-action')).toBeTruthy(); fireEvent.click(queryByTestId('project-action')); expect( queryByTestId('project-action-parent').classList.contains('active') ).toBeTruthy(); }); it('renders the projects and selects an active project using onKeyDown', () => { const { queryByTestId } = render(); expect(queryByTestId('project-action')).toBeTruthy(); fireEvent.keyDown(queryByTestId('project-action'), { key: 'a', code: 65, }); expect( queryByTestId('project-action-parent').classList.contains('active') ).toBeFalsy(); fireEvent.keyDown(queryByTestId('project-action'), { key: 'Enter', code: 13, }); expect( queryByTestId('project-action-parent').classList.contains('active') ).toBeTruthy(); }); it('renders the projects with no active value', () => { const { queryByTestId } = render(); expect(queryByTestId('project-action')).toBeTruthy(); fireEvent.keyDown(queryByTestId('project-action'), { key: 'a', code: 65, }); expect( queryByTestId('project-action-parent').classList.contains('active') ).toBeFalsy(); fireEvent.keyDown(queryByTestId('project-action'), { key: 'Enter', code: 13, }); expect( queryByTestId('project-action-parent').classList.contains('active') ).toBeTruthy(); }); }); });