diff --git a/src/components/Calendar/Calendar.test.js b/src/components/Calendar/Calendar.test.js new file mode 100644 index 0000000..1f227ca --- /dev/null +++ b/src/components/Calendar/Calendar.test.js @@ -0,0 +1,51 @@ +import React from "react"; +import { mount } from "enzyme"; + +import Calendar from "./Calendar"; + +describe("", () => { + let calendar; + const mockClickDone = jest.fn(); + + beforeEach(() => { + calendar = + }); + + afterEach(jest.clearAllMocks); + + it("should render without errors", () => { + const component = mount(calendar); + const wrapper = component.find(Calendar); + expect(wrapper.length).toBe(1); + }); + + it("should click todos properly", () => { + const component = mount(calendar); + const wrapper = component.find(".todoTitle.done"); + wrapper.simulate("click"); + expect(mockClickDone).toHaveBeenCalledTimes(1); + }); +}); diff --git a/src/containers/TodoCalendar/TodoCalendar.js b/src/containers/TodoCalendar/TodoCalendar.js index 91b24ca..3237890 100644 --- a/src/containers/TodoCalendar/TodoCalendar.js +++ b/src/containers/TodoCalendar/TodoCalendar.js @@ -38,9 +38,9 @@ class TodoCalendar extends Component {
See TodoList
- + {this.state.year}.{this.state.month} - +
{ + return jest.fn(props => { + return ( + + ); + }); +}); + +const stubInitialState = { + year: 2020, + month: 10, +}; + +const mockStore = getMockStore(stubInitialState); + +describe("", () => { + let todoCalendar; + + beforeEach(() => { + todoCalendar = ( + + + + + + + + ); + }); + + it("should render without errors", () => { + const component = mount(todoCalendar); + const wrapper = component.find(TodoCalendar); + expect(wrapper.length).toBe(1); + }); + + it("should properly handle clicking prev month button", () => { + const component = mount(todoCalendar); + const wrapper = component.find(".prev"); + for (let i = 0; i < 10; i++) + wrapper.simulate("click"); + const todoCalendarInstance = component.find(TodoCalendar.WrappedComponent).instance(); + expect(todoCalendarInstance.state.month).toEqual(12); + }); + + it("should properly handle clicking next month button", () => { + const component = mount(todoCalendar); + const wrapper = component.find(".next"); + for (let i = 0; i < 3; i++) + wrapper.simulate("click"); + const todoCalendarInstance = component.find(TodoCalendar.WrappedComponent).instance(); + expect(todoCalendarInstance.state.month).toEqual(1); + }); + + it("should toggle todo", () => { + const spyToggleTodo = jest.spyOn(actionCreators, 'toggleTodo') + .mockImplementation(id => { + return dispatch => { }; + }); + const component = mount(todoCalendar); + const wrapper = component.find(".toggle"); + wrapper.simulate("click"); + expect(spyToggleTodo).toHaveBeenCalledTimes(1); + }); +}); diff --git a/src/containers/TodoList/NewTodo/NewTodo.js b/src/containers/TodoList/NewTodo/NewTodo.js index 1ce93bc..11dec66 100644 --- a/src/containers/TodoList/NewTodo/NewTodo.js +++ b/src/containers/TodoList/NewTodo/NewTodo.js @@ -39,6 +39,7 @@ class NewTodo extends Component {

Add a New Todo!

this.setState({ title: event.target.value })} @@ -50,24 +51,27 @@ class NewTodo extends Component { year this.setState({ - dueDate: {...this.state.dueDate, year: event.target.value } + dueDate: { ...this.state.dueDate, year: event.target.value } })} > month this.setState({ - dueDate: {...this.state.dueDate, month: event.target.value } + dueDate: { ...this.state.dueDate, month: event.target.value } })} > date this.setState({ - dueDate: {...this.state.dueDate, date: event.target.value } + dueDate: { ...this.state.dueDate, date: event.target.value } })} > @@ -79,7 +83,7 @@ class NewTodo extends Component { const mapDispatchToProps = dispatch => { return { onStoreTodo: (title, content, dueDate) => - dispatch(actionCreators.postTodo({ title: title, content: content, dueDate: dueDate})), + dispatch(actionCreators.postTodo({ title: title, content: content, dueDate: dueDate })), } }; diff --git a/src/containers/TodoList/NewTodo/NewTodo.test.js b/src/containers/TodoList/NewTodo/NewTodo.test.js index 5696dc7..2d7eea3 100644 --- a/src/containers/TodoList/NewTodo/NewTodo.test.js +++ b/src/containers/TodoList/NewTodo/NewTodo.test.js @@ -11,9 +11,9 @@ import * as actionCreators from '../../../store/actions/todo'; const stubInitialState = { todos: [ - {id: 1, title: 'TODO_TEST_TITLE_1', done: false}, - {id: 2, title: 'TODO_TEST_TITLE_2', done: false}, - {id: 3, title: 'TODO_TEST_TITLE_3', done: false}, + { id: 1, title: 'TODO_TEST_TITLE_1', done: false }, + { id: 2, title: 'TODO_TEST_TITLE_2', done: false }, + { id: 3, title: 'TODO_TEST_TITLE_3', done: false }, ], selectedTodo: null, }; @@ -27,9 +27,9 @@ describe('', () => { newTodo = ( - - - + + + ); @@ -43,17 +43,17 @@ describe('', () => { it(`should call 'postTodo'`, () => { const spyPostTodo = jest.spyOn(actionCreators, 'postTodo') - .mockImplementation(td => { return dispatch => {}; }); + .mockImplementation(td => { return dispatch => { }; }); const component = mount(newTodo); const wrapper = component.find('button'); wrapper.simulate('click'); expect(spyPostTodo).toHaveBeenCalledTimes(1); }); - + it(`should set state properly on title input`, () => { const title = 'TEST_TITLE' const component = mount(newTodo); - const wrapper = component.find('input'); + const wrapper = component.find('input.title'); wrapper.simulate('change', { target: { value: title } }); const newTodoInstance = component.find(NewTodo.WrappedComponent).instance(); expect(newTodoInstance.state.title).toEqual(title); @@ -69,6 +69,21 @@ describe('', () => { expect(newTodoInstance.state.title).toEqual(''); expect(newTodoInstance.state.content).toEqual(content); }); + + it(`should set state properly on due date input`, () => { + const year = '2021' + const month = '12' + const date = '25' + const component = mount(newTodo); + const wrapper_year = component.find('input.year'); + const wrapper_month = component.find('input.month'); + const wrapper_date = component.find('input.date'); + wrapper_year.simulate('change', { target: { value: year } }); + wrapper_month.simulate('change', { target: { value: month } }); + wrapper_date.simulate('change', { target: { value: date } }); + const newTodoInstance = component.find(NewTodo.WrappedComponent).instance(); + expect(newTodoInstance.state.dueDate).toEqual({ year, month, date }); + }); }); diff --git a/src/store/actions/todo.test.js b/src/store/actions/todo.test.js index ff84a79..36eb04d 100644 --- a/src/store/actions/todo.test.js +++ b/src/store/actions/todo.test.js @@ -7,7 +7,12 @@ import store from '../store'; const stubTodo = { id: 0, title: 'title 1', - content: 'content 1' + content: 'content 1', + dueDate: { + year: 2020, + month: 10, + date: 9, + } }; describe('ActionCreators', () => {