Skip to content

finish #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: task
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified backend/db.sqlite3
Binary file not shown.
49 changes: 49 additions & 0 deletions src/components/Calendar/Calendar.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React, { Component } from 'react';
import { shallow, mount } from 'enzyme';
import { Table } from 'semantic-ui-react'
import Calendar from './Calendar';


it('should render Calendar', () => {
const component = shallow(<Calendar/>);
const wrapper = component.find('Table');
//const wrapper = component.find('.Calendar');
expect(wrapper.length).toBe(1);
});
it('should build dates properly', () => {
const component = shallow(Calendar({
year: 2020,
month: 10,
todos: [],
}));
const wrapper = component.find('.date');
expect(wrapper.length).toBe(31);
});
it('should handle clicks for done todos', () => {
const mockClickDone = jest.fn();
const component = shallow(Calendar({
year: 2020,
month: 10,
todos: [{id: 1, year: 2020, month: 9, date: 8, done: true,},
{id: 2, year: 2020, month: 9, date: 8, done: false,},
],
clickDone: mockClickDone,
}))
const wrapper = component.find('.done');
wrapper.simulate('click');
expect(mockClickDone).toHaveBeenCalledTimes(1);
});
it('should handle clicks for undone todos', () => {
const mockClickDone = jest.fn();
const component = shallow(Calendar({
year: 2020,
month: 10,
todos: [{id: 1, year: 2020, month: 9, date: 8, done: true,},
{id: 2, year: 2020, month: 9, date: 8, done: false,},
],
clickDone: mockClickDone,
}))
const wrapper = component.find('.notdone');
wrapper.simulate('click');
expect(mockClickDone).toHaveBeenCalledTimes(1);
});
76 changes: 76 additions & 0 deletions src/containers/TodoCalendar/TodoCalendar.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { ConnectedRouter } from 'connected-react-router';
import { mount } from 'enzyme';
import { Provider } from 'react-redux';
import React, { Component } from 'react';
import { Route, Switch } from 'react-router';
import { history } from '../../store/store';
import { getMockStore } from '../../test-utils/mocks';
import TodoCalendar from "./TodoCalendar";
import Calendar from '../../components/Calendar/Calendar';
import * as actionCreators from '../../store/actions/todo';

jest.mock('../../components/Calendar/Calendar', () => {
return jest.fn(props => {
return (
<div>
<div className = "year">{props.year}</div>
<div className = "month">{props.month}</div>
<div>{props.todos}</div>
<div className = "clickDone" onClick = {props.clickDone}/>
</div>
);
});
});

const stubInitialState = {
// Same with state from TodoCalendar
year: 2019,
month: 10,
}

const mockStore = getMockStore(stubInitialState);

describe('<TodoCalendar />', () => {
let todoCalendar;
beforeEach(() => {
todoCalendar = (
<Provider store = {mockStore}>
<ConnectedRouter history = {history}>
<Switch>
<Route path = '/' exact render = {() => <TodoCalendar/>}/>
</Switch>
</ConnectedRouter>
</Provider>
);
});

it('should render TodoCalendar', () => {
const component = mount(todoCalendar);
const wrapper = component.find('TodoCalendar');
// const wrapper = component.find('.TodoCalendar');
expect(wrapper.length).toBe(1);
});
it('should call handleClickPrev', () => {
const component = mount(todoCalendar);
//const wrapper = component.find('.clickPrev');
const wrapper = component.find('button').at(0);
for(let i=0; i<12; i++)wrapper.simulate('click');
const year = parseInt(component.find(Calendar).find('.year').text());
expect(year).toBe(stubInitialState.year - 1);
});
it('should call handleClickNext', () => {
const component = mount(todoCalendar);
const wrapper = component.find('button').at(1);
for(let i=0; i<12; i++)wrapper.simulate('click');
const year = parseInt(component.find(Calendar).find('.year').text());
expect(year).toBe(stubInitialState.year + 1);
});
it('should call clickDone', () => {
const spyToggleTodo = jest.spyOn(actionCreators, 'toggleTodo')
.mockImplementation(id => { return dispatch => {}; });
const component = mount(todoCalendar);
const wrapper = component.find('.clickDone').at(0);
wrapper.simulate('click');
expect(spyToggleTodo).toHaveBeenCalledTimes(1);
});
});
35 changes: 34 additions & 1 deletion src/containers/TodoList/NewTodo/NewTodo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ describe('<NewTodo />', () => {
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').at(0);
wrapper.simulate('change', { target: { value: title } });
const newTodoInstance = component.find(NewTodo.WrappedComponent).instance();
expect(newTodoInstance.state.title).toEqual(title);
expect(newTodoInstance.state.content).toEqual('');
//expect(newTodoInstance.state.dueDate).toEqual({"date": 8, "month": 10, "year": 2020});
});

it(`should set state properly on content input`, () => {
Expand All @@ -68,7 +69,39 @@ describe('<NewTodo />', () => {
const newTodoInstance = component.find(NewTodo.WrappedComponent).instance();
expect(newTodoInstance.state.title).toEqual('');
expect(newTodoInstance.state.content).toEqual(content);
//expect(newTodoInstance.state.dueDate).toEqual({"date": 8, "month": 10, "year": 2020});
});

it(`should set state properly on year input`, () => {
const year = 2020;
const component = mount(newTodo);
const wrapper = component.find('input').at(1);
wrapper.simulate('change', { target: { value: year } });
const newTodoInstance = component.find(NewTodo.WrappedComponent).instance();
expect(newTodoInstance.state.dueDate.year).toEqual(year);
expect(newTodoInstance.state.content).toEqual('');
});

it(`should set state properly on month input`, () => {
const month = 10;
const component = mount(newTodo);
const wrapper = component.find('input').at(2);
wrapper.simulate('change', { target: { value: month } });
const newTodoInstance = component.find(NewTodo.WrappedComponent).instance();
expect(newTodoInstance.state.dueDate.month).toEqual(month);
expect(newTodoInstance.state.content).toEqual('');
});

it(`should set state properly on date input`, () => {
const date = 8;
const component = mount(newTodo);
const wrapper = component.find('input').at(3);
wrapper.simulate('change', { target: { value: date } });
const newTodoInstance = component.find(NewTodo.WrappedComponent).instance();
expect(newTodoInstance.state.dueDate.date).toEqual(date);
expect(newTodoInstance.state.content).toEqual('');
});

});


7 changes: 6 additions & 1 deletion src/store/actions/todo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: 11,
date: 8
}
};

describe('ActionCreators', () => {
Expand Down
Loading