This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
import { connect } from 'react-redux' | |
import { calculate }from './store/actions/calculate' | |
import Calculator from './components/calculator' | |
import * as fromCalculator from './store' | |
import './App.css' | |
export class App extends Component { | |
render() { | |
return ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as types from '../types' | |
import calculate from '../../utils/calculate' | |
let initialState = { | |
expression: '', | |
total: 0 | |
} | |
export default (state = initialState, action) => { | |
switch (action.type) { | |
case types.SET_EXPRESSION: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const calculate = (expression) => { | |
return { | |
type: 'SET_EXPRESSION', | |
payload: expression | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const SET_EXPRESSION = 'SET_EXPRESSION'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
handleClick = (key) => { | |
switch(key) { | |
case 'c': | |
this.props.clear() | |
break | |
case 'Del': | |
this.props.delete() | |
break | |
case '=': |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import calculatorReducer from '../store/reducers/calculateReducer'; | |
import * as types from '../store/types'; | |
describe('Calculator Reducer', () => { | |
it ('should return the initial state', () => { | |
const initialState = { | |
expression: '', | |
total: 0 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { mount, configure } from 'enzyme'; | |
import Adapter from 'enzyme-adapter-react-16'; | |
import toJson from 'enzyme-to-json'; | |
import { App } from '../App'; | |
import sinon from 'sinon'; | |
configure({ | |
adapter: new Adapter | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
export const operators = ['*', '-', '+', '/', '=']; | |
export const specialOperators = ['c', '%', 'Del']; |