diff --git a/bloglist_frontend/src/components/BlogForm.test.js b/bloglist_frontend/src/components/BlogForm.test.js new file mode 100644 index 0000000000000000000000000000000000000000..e0aee0c35785e74fd98886ec7d0ef364d26c9171 --- /dev/null +++ b/bloglist_frontend/src/components/BlogForm.test.js @@ -0,0 +1,30 @@ +import React from 'react' +import '@testing-library/jest-dom/extend-expect' +import { render, screen } from '@testing-library/react' +import userEvent from '@testing-library/user-event' +import BlogForm from './BlogForm' + +test('<BlogForm /> calls propsfunction when blog is created', async () => { + const addBlog = jest.fn() + + render(<BlogForm createBlog={addBlog} />) + + const titleInput = screen.getByPlaceholderText('write title here') + const authorInput = screen.getByPlaceholderText('write author here') + const urlInput = screen.getByPlaceholderText('write url here') + + await userEvent.type(titleInput, 'Test title') + await userEvent.type(authorInput, 'Test author') + await userEvent.type(urlInput, 'http://example.com') + + const submitButton = screen.getByText('create') + await userEvent.click(submitButton) + + expect(addBlog).toHaveBeenCalledTimes(1) + expect(addBlog).toHaveBeenCalledWith({ + title: 'Test title', + author: 'Test author', + url: 'http://example.com', + likes: 0 + }) +}) \ No newline at end of file