diff --git a/__tests__/actions/Todo.test.js b/__tests__/actions/Todo.test.js deleted file mode 100644 index 7b84672..0000000 --- a/__tests__/actions/Todo.test.js +++ /dev/null @@ -1,29 +0,0 @@ -// @flow - -import configureStore from 'redux-mock-store'; - -import { ADD_TODO, addTodo } from '../../app/redux/modules/todo'; - -const store = configureStore()(); - -describe('Todo Actions', () => { - beforeEach(() => store.clearActions()); - - test('should create an action to add a new todo', () => { - const text = 'Hello World!'; - - store.dispatch(addTodo(text)); - - expect(store.getActions()[0]).toEqual( - expect.objectContaining({ - type: ADD_TODO, - payload: { - text, - id: expect.any(String), - editing: false, - createdAt: expect.any(Number), - }, - }), - ); - }); -}); diff --git a/__tests__/actions/WalletSummary.test.js b/__tests__/actions/WalletSummary.test.js new file mode 100644 index 0000000..3a53f05 --- /dev/null +++ b/__tests__/actions/WalletSummary.test.js @@ -0,0 +1,21 @@ +// @flow + +import configureStore from 'redux-mock-store'; + +import { LOAD_WALLET_SUMMARY, loadWalletSummary } from '../../app/redux/modules/wallet'; + +const store = configureStore()(); + +describe('WalletSummary Actions', () => { + beforeEach(() => store.clearActions()); + + test('should create an action to load wallet summary', () => { + store.dispatch(loadWalletSummary()); + + expect(store.getActions()[0]).toEqual( + expect.objectContaining({ + type: LOAD_WALLET_SUMMARY, + }), + ); + }); +}); diff --git a/__tests__/reducers/Todo.test.js b/__tests__/reducers/Todo.test.js deleted file mode 100644 index 560eb5c..0000000 --- a/__tests__/reducers/Todo.test.js +++ /dev/null @@ -1,30 +0,0 @@ -// @flow - -import todoReducer, { ADD_TODO } from '../../app/redux/modules/todo'; - -describe('Todo Reducer', () => { - test('should return the valid initial state', () => { - const initialState = []; - const action = { - type: 'UNKNOWN_ACTION', - payload: {}, - }; - - expect(todoReducer(undefined, action)).toEqual(initialState); - }); - - test('should add a new todo', () => { - const action = { - type: ADD_TODO, - payload: { - id: 'abc123', - text: 'Hello World!', - editing: false, - createdAt: new Date().getTime(), - }, - }; - const expectedState = [action.payload]; - - expect(todoReducer(undefined, action)).toEqual(expectedState); - }); -}); diff --git a/__tests__/reducers/WalletSummary.test.js b/__tests__/reducers/WalletSummary.test.js new file mode 100644 index 0000000..ecc5907 --- /dev/null +++ b/__tests__/reducers/WalletSummary.test.js @@ -0,0 +1,31 @@ +// @flow +import walletSummaryReducer, { LOAD_WALLET_SUMMARY } from '../../app/redux/modules/wallet'; + +describe('WalletSummary Reducer', () => { + test('should return the valid initial state', () => { + const initialState = []; + const action = { + type: 'UNKNOWN_ACTION', + payload: {}, + }; + + expect(walletSummaryReducer(undefined, action)).toEqual(initialState); + }); + + test('should load the wallet summary', () => { + const action = { + type: LOAD_WALLET_SUMMARY, + payload: {}, + }; + const expectedState = { + total: 0, + shielded: 0, + transparent: 0, + error: null, + isLoading: true, + dollarValue: 0, + }; + + expect(walletSummaryReducer(undefined, action)).toEqual(expectedState); + }); +}); diff --git a/app/components/todo-edit-input.js b/app/components/todo-edit-input.js deleted file mode 100644 index dcc1122..0000000 --- a/app/components/todo-edit-input.js +++ /dev/null @@ -1,68 +0,0 @@ -// @flow - -import React, { Component } from 'react'; -import type { TodoType } from '../types/todo'; - -type Props = { - updateTodo: Function, - todo: TodoType, - cancelUpdateTodo: Function, -}; - -type State = { - value: string, -}; - -export default class TodoEditInput extends Component { - constructor(props: Props) { - super(props); - - this.state = { - value: props.todo.text || '', - }; - } - - handleSubmit = (event: SyntheticInputEvent, id: string) => { - const { value } = this.state; - const { updateTodo } = this.props; - const trimValue = value.trim(); - - event.preventDefault(); - - if (trimValue !== '') { - updateTodo(id, trimValue); - this.setState({ value: '' }); - } - }; - - handleCancel = (id: string) => { - const { cancelUpdateTodo } = this.props; - cancelUpdateTodo(id); - }; - - handleInputChange = (event: SyntheticInputEvent) => { - const { - target: { value }, - } = event; - this.setState({ value }); - }; - - render() { - const { value } = this.state; - const { todo } = this.props; - - return ( -
-
this.handleSubmit(e, todo.id)}> - - -
- -
- ); - } -} diff --git a/app/components/todo-input.js b/app/components/todo-input.js deleted file mode 100644 index ae71f0e..0000000 --- a/app/components/todo-input.js +++ /dev/null @@ -1,50 +0,0 @@ -// @flow - -import React, { Component } from 'react'; - -type Props = { - addTodo: Function, -}; - -type State = { - value: string, -}; - -export default class TodoInput extends Component { - state = { - value: '', - }; - - handleSubmit = (event: SyntheticInputEvent) => { - const { value } = this.state; - const { addTodo } = this.props; - const trimValue = value.trim(); - - event.preventDefault(); - - if (trimValue !== '') { - addTodo(trimValue); - this.setState({ value: '' }); - } - }; - - handleInputChange = (event: SyntheticInputEvent) => { - const { - target: { value }, - } = event; - this.setState({ value }); - }; - - render() { - const { value } = this.state; - - return ( -
- - -
- ); - } -} diff --git a/app/components/todo-list-item.js b/app/components/todo-list-item.js deleted file mode 100644 index d668f40..0000000 --- a/app/components/todo-list-item.js +++ /dev/null @@ -1,55 +0,0 @@ -// @flow - -import React, { PureComponent } from 'react'; -import type { TodoType } from '../types/todo'; - -type Props = { - todo: TodoType, - deleteTodo: Function, - toggleEdit: Function, -}; - -export default class TodoListItem extends PureComponent { - handleDelete = (id: string) => { - if (!id) return; - - const { deleteTodo } = this.props; - deleteTodo(id); - }; - - handleEditToggle = (id: string) => { - if (!id) return; - - const { toggleEdit } = this.props; - toggleEdit(id); - }; - - render() { - const { todo } = this.props; - - return ( -
- {todo.text} -
- - -
-
- ); - } -} diff --git a/app/components/todo-list.js b/app/components/todo-list.js deleted file mode 100644 index 244a6c2..0000000 --- a/app/components/todo-list.js +++ /dev/null @@ -1,52 +0,0 @@ -// @flow - -import React, { PureComponent } from 'react'; -import TodoEditInput from './todo-edit-input'; -import TodoListItem from './todo-list-item'; -import type { TodoType } from '../types/todo'; - -type Props = { - todos: Array, - deleteTodo: Function, - toggleEdit: Function, - updateTodo: Function, - cancelUpdateTodo: Function, -}; - -export default class TodoList extends PureComponent { - renderTodoView = (todo: TodoType) => { - const { deleteTodo, toggleEdit } = this.props; - - return ; - }; - - renderEditView = (todo: TodoType) => { - const { updateTodo, cancelUpdateTodo } = this.props; - - return ; - }; - - renderList = () => { - const { todos } = this.props; - const sortTodosByTime = todos.sort((a, b) => b.createdAt - a.createdAt); - - return ( -
    - {sortTodosByTime.map(todo => ( -
  • - {todo.editing ? this.renderEditView(todo) : this.renderTodoView(todo)} -
  • - ))} -
- ); - }; - - renderEmptyState = () =>

No todos right now

; - - render() { - const { todos } = this.props; - const hasTodos = todos.length; - - return hasTodos ? this.renderList() : this.renderEmptyState(); - } -} diff --git a/app/containers/todo.js b/app/containers/todo.js deleted file mode 100644 index 6d32347..0000000 --- a/app/containers/todo.js +++ /dev/null @@ -1,27 +0,0 @@ -// @flow - -import { connect } from 'react-redux'; -import TodoView from '../views/todo'; -import { - addTodo, deleteTodo, toggleEdit, updateTodo, cancelUpdateTodo, -} from '../redux/modules/todo'; - -import type { AppState } from '../types/app-state'; -import type { Dispatch } from '../types/redux'; - -const mapStateToProps = (state: AppState) => ({ - todos: state.todos, -}); - -const mapDispatchToProps = (dispatch: Dispatch) => ({ - addTodo: text => dispatch(addTodo(text)), - deleteTodo: id => dispatch(deleteTodo(id)), - toggleEdit: id => dispatch(toggleEdit(id)), - updateTodo: (id, text) => dispatch(updateTodo(id, text)), - cancelUpdateTodo: id => dispatch(cancelUpdateTodo(id)), -}); - -export default connect( - mapStateToProps, - mapDispatchToProps, -)(TodoView); diff --git a/app/redux/modules/todo.js b/app/redux/modules/todo.js deleted file mode 100644 index fea3072..0000000 --- a/app/redux/modules/todo.js +++ /dev/null @@ -1,78 +0,0 @@ -// @flow - -import UUID from 'uuid/v4'; - -import { getTimestamp } from '../../utils/timestamp'; - -import type { Action } from '../../types/redux'; -import type { TodoType } from '../../types/todo'; - -// Actions -export const ADD_TODO = 'ADD_TODO'; -export const DELETE_TODO = 'DELETE_TODO'; -export const UPDATE_TODO = 'UPDATE_TODO'; -export const TOGGLE_EDIT_TODO = 'TOGGLE_EDIT_TODO'; -export const CANCEL_UPDATE_TODO = 'CANCEL_UPDATE_TODO'; - -// Actions Creators -export const addTodo = (text: string) => ({ - type: ADD_TODO, - payload: { - text, - id: UUID(), - editing: false, - createdAt: getTimestamp(), - }, -}); - -export const cancelUpdateTodo = (id: string) => ({ - type: CANCEL_UPDATE_TODO, - payload: { id }, -}); - -export const deleteTodo = (id: string) => ({ - type: DELETE_TODO, - payload: { id }, -}); - -export const toggleEdit = (id: string) => ({ - type: TOGGLE_EDIT_TODO, - payload: { id }, -}); - -export const updateTodo = (id: string, text: string) => ({ - type: UPDATE_TODO, - payload: { - text, - id, - }, -}); - -// Initial State -const initialState = []; - -// Reducers -export default (state: Array = initialState, action: Action): Array => { - switch (action.type) { - case ADD_TODO: - return [...state, action.payload]; - case DELETE_TODO: - return state.filter((todo: TodoType) => todo.id !== action.payload.id); - case TOGGLE_EDIT_TODO: { - const { id } = action.payload; - return state.map(todo => (todo.id === id ? { ...todo, editing: true } : todo)); - } - case UPDATE_TODO: { - const { id, text } = action.payload; - return state.map(todo => (todo.id === id ? { ...todo, editing: false, text } : todo)); - } - case CANCEL_UPDATE_TODO: { - const { id } = action.payload; - return state.map(todo => (todo.id === id ? { ...todo, editing: false } : todo)); - } - default: - return state; - } -}; - -// SideEffects diff --git a/app/views/todo.js b/app/views/todo.js deleted file mode 100644 index a6dedd9..0000000 --- a/app/views/todo.js +++ /dev/null @@ -1,42 +0,0 @@ -// @flow - -import React from 'react'; - -import TodoInput from '../components/todo-input'; -import TodoList from '../components/todo-list'; - -import type { TodoType } from '../types/todo'; - -import checklist from '../assets/images/checklist.svg'; - -type Props = { - addTodo: Function, - deleteTodo: Function, - toggleEdit: Function, - todos: Array, - updateTodo: Function, - cancelUpdateTodo: Function, -}; - -export default (props: Props) => { - const { - addTodo, todos, deleteTodo, toggleEdit, updateTodo, cancelUpdateTodo, - } = props; - - return ( -
-
- Testing File Loader -

Todo List App

-
- - -
- ); -};