Skip to content

Instantly share code, notes, and snippets.

View mazeeblanke's full-sized avatar
🎯
Focusing

Ewomazino Ukah mazeeblanke

🎯
Focusing
View GitHub Profile
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 (
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:
export const calculate = (expression) => {
return {
type: 'SET_EXPRESSION',
payload: expression
}
}
export const SET_EXPRESSION = 'SET_EXPRESSION';
...
handleClick = (key) => {
switch(key) {
case 'c':
this.props.clear()
break
case 'Del':
this.props.delete()
break
case '=':
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
}
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
})
import React from 'react';
import { operators, specialOperators } from '../../utils/constants'
export default ({ onButtonClick, buttonKey}) => {
let handleClick = (e) => { onButtonClick(e.target.textContent) }
let classNames = [
'btn',
operators.includes(buttonKey) ? 'btn--orange' : '',
specialOperators.includes(buttonKey) ? 'btn--grey' : '',
buttonKey === '0' ? 'btn--zero': ''
];
...
export const operators = ['*', '-', '+', '/', '='];
export const specialOperators = ['c', '%', 'Del'];
...
return (
<button
className={buttonKey === '0' ? 'btn btn--zero': 'btn'}
onClick={handleClick}>
{ buttonKey }
</button>
);