Download todoist/src/__tests__/AddProject.spec.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 4.34 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/todoist/src/__tests__/AddProject.spec.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/todoist/src/__tests__/AddProject.spec.js
-
curl -L -o AddProject.spec.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/todoist/src/__tests__/AddProject.spec.js
4.34 kB
| import React from 'react'; | |
| import { render, cleanup, fireEvent } from '@testing-library/react'; | |
| import { AddProject } from '../components/AddProject'; | |
| jest.mock('../context', () => ({ | |
| useSelectedProjectValue: jest.fn(), | |
| useProjectsValue: jest.fn(() => ({ | |
| projects: [ | |
| { | |
| name: '๐ THE OFFICE', | |
| projectId: '1', | |
| userId: 'jlIFXIwyAL3tzHMtzRbw', | |
| docId: 'michael-scott', | |
| }, | |
| { | |
| name: '๐ DAILY', | |
| projectId: '2', | |
| userId: 'jlIFXIwyAL3tzHMtzRbw', | |
| docId: 'daily-office', | |
| }, | |
| { | |
| name: '๐ฏ FUTURE', | |
| projectId: '3', | |
| userId: 'jlIFXIwyAL3tzHMtzRbw', | |
| docId: 'wake-up', | |
| }, | |
| { | |
| name: '๐ WORDS', | |
| projectId: '4', | |
| userId: 'jlIFXIwyAL3tzHMtzRbw', | |
| docId: 'arcade-fire', | |
| }, | |
| { | |
| name: '๐ต MUSIC', | |
| projectId: '5', | |
| userId: 'jlIFXIwyAL3tzHMtzRbw', | |
| docId: 'bella-ciao', | |
| }, | |
| ], | |
| setProjects: jest.fn(), | |
| })), | |
| })); | |
| jest.mock('../firebase', () => ({ | |
| firebase: { | |
| firestore: jest.fn(() => ({ | |
| collection: jest.fn(() => ({ | |
| add: jest.fn(() => Promise.resolve('I am resolved!')), | |
| })), | |
| })), | |
| }, | |
| })); | |
| beforeEach(cleanup); | |
| describe('<AddProject />', () => { | |
| describe('Success', () => { | |
| it('renders <AddProject />', () => { | |
| const { queryByTestId } = render(<AddProject />); | |
| expect(queryByTestId('add-project')).toBeTruthy(); | |
| }); | |
| it('renders <AddProject /> and adds a project using onClick', () => { | |
| const { queryByTestId } = render(<AddProject shouldShow />); | |
| expect(queryByTestId('add-project')).toBeTruthy(); | |
| fireEvent.change(queryByTestId('project-name'), { | |
| target: { value: 'Best project in the world!' }, | |
| }); | |
| expect(queryByTestId('project-name').value).toBe( | |
| 'Best project in the world!' | |
| ); | |
| fireEvent.click(queryByTestId('add-project-submit')); | |
| }); | |
| it('hides the project overlay when cancelled using onClick', () => { | |
| const { queryByTestId, getByText } = render(<AddProject shouldShow />); | |
| expect(queryByTestId('add-project')).toBeTruthy(); | |
| expect(queryByTestId('add-project-inner')).toBeTruthy(); | |
| fireEvent.click(getByText('Cancel')); | |
| expect(queryByTestId('add-project')).toBeTruthy(); | |
| expect(queryByTestId('add-project-inner')).toBeFalsy(); | |
| }); | |
| it('hides the project overlay when cancelled onKeyDown', () => { | |
| const { queryByTestId, getByText } = render(<AddProject shouldShow />); | |
| expect(queryByTestId('add-project')).toBeTruthy(); | |
| expect(queryByTestId('add-project-inner')).toBeTruthy(); | |
| fireEvent.keyDown(getByText('Cancel'), { | |
| key: 'a', | |
| code: 65, | |
| }); | |
| expect(queryByTestId('add-project')).toBeTruthy(); | |
| expect(queryByTestId('add-project-inner')).toBeTruthy(); | |
| fireEvent.keyDown(getByText('Cancel'), { | |
| key: 'Enter', | |
| code: 13, | |
| }); | |
| expect(queryByTestId('add-project')).toBeTruthy(); | |
| expect(queryByTestId('add-project-inner')).toBeFalsy(); | |
| }); | |
| it('hides the project overlay using onClick singular and reverse action', () => { | |
| const { queryByTestId } = render(<AddProject shouldShow />); | |
| expect(queryByTestId('add-project')).toBeTruthy(); | |
| expect(queryByTestId('add-project-inner')).toBeTruthy(); | |
| fireEvent.click(queryByTestId('add-project-action')); | |
| expect(queryByTestId('add-project')).toBeTruthy(); | |
| expect(queryByTestId('add-project-inner')).toBeFalsy(); | |
| }); | |
| it('hides the project overlay using onKeyDown singular and reverse action', () => { | |
| const { queryByTestId } = render(<AddProject shouldShow />); | |
| expect(queryByTestId('add-project')).toBeTruthy(); | |
| expect(queryByTestId('add-project-inner')).toBeTruthy(); | |
| fireEvent.keyDown(queryByTestId('add-project-action'), { | |
| key: 'a', | |
| code: 65, | |
| }); | |
| expect(queryByTestId('add-project')).toBeTruthy(); | |
| expect(queryByTestId('add-project-inner')).toBeTruthy(); | |
| fireEvent.keyDown(queryByTestId('add-project-action'), { | |
| key: 'Enter', | |
| code: 13, | |
| }); | |
| expect(queryByTestId('add-project')).toBeTruthy(); | |
| expect(queryByTestId('add-project-inner')).toBeFalsy(); | |
| }); | |
| }); | |
| }); | |