From 042e730e4671de24eeeda39995c652e90f66d3d1 Mon Sep 17 00:00:00 2001 From: euZebe Date: Fri, 13 Apr 2018 22:41:59 +0200 Subject: [PATCH] fix tests --- src/store/reducers.js | 2 ++ src/store/reducers.spec.js | 35 +++++++++++++++++++++-------------- src/ui/BoardContainer.js | 9 ++++++--- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/store/reducers.js b/src/store/reducers.js index b387bb5..8c1775a 100644 --- a/src/store/reducers.js +++ b/src/store/reducers.js @@ -10,6 +10,8 @@ import { export const getTableOfCellsSelector = state => state.cellsTable.present; export const getHoneyCombSelector = state => state.hexaCells.present; +export const getPastHoneyCombSelector = state => state.hexaCells.past; +export const getFutureHoneyCombSelector = state => state.hexaCells.future; export const honeyCombAsSingleArraySelector = createSelector( getHoneyCombSelector, arrayOfRows => [].concat.apply([], arrayOfRows), diff --git a/src/store/reducers.spec.js b/src/store/reducers.spec.js index 50dc241..5335fb9 100644 --- a/src/store/reducers.spec.js +++ b/src/store/reducers.spec.js @@ -5,11 +5,14 @@ import { RECTANGLE, HEXAGON } from '../model/shapes'; describe('getTableOfCellsSelector', () => { test('should select cells in a table according to their position', () => { const state = { - cellsTable: [ - [ALIVE, DEAD], - [DEAD, DEAD], - [ALIVE, ALIVE], - ], + cellsTable: { + past:[], + present: [ + [ALIVE, DEAD], + [DEAD, DEAD], + [ALIVE, ALIVE], + ], + }, shape: { shape: RECTANGLE.value, height: 3, @@ -23,12 +26,14 @@ describe('getTableOfCellsSelector', () => { test('should return an empty array if hexagon is current', () => { const state = { - cellsTable: [], - hexaCells: [ - [ALIVE, DEAD], - [DEAD, DEAD], - [ALIVE, ALIVE], - ], + cellsTable: {present:[]}, + hexaCells: { + present: [ + [ALIVE, DEAD], + [DEAD, DEAD], + [ALIVE, ALIVE], + ], + }, shape: { shape: HEXAGON.value, height: 3, @@ -42,12 +47,14 @@ describe('getTableOfCellsSelector', () => { describe('getHoneyCombSelector', () => { test('should select cells in a table according to their position', () => { const state = { - hexaCells: [ + hexaCells: {present:[ [ALIVE, DEAD], [DEAD, DEAD], [ALIVE, ALIVE], - ], - cellsTable: [], + ],}, + cellsTable: { + present: [] + }, shape: { shape: HEXAGON.value, rows: 3, diff --git a/src/ui/BoardContainer.js b/src/ui/BoardContainer.js index 9ec8d5d..f063cd6 100644 --- a/src/ui/BoardContainer.js +++ b/src/ui/BoardContainer.js @@ -1,15 +1,18 @@ import { connect } from 'react-redux'; import { ActionCreators as UndoActionCreators } from 'redux-undo' import Board from './Board'; -import {getHoneyCombSelector, getShapeSelector, getTableOfCellsSelector} from '../store/reducers'; +import { + getFutureHoneyCombSelector, getHoneyCombSelector, getPastHoneyCombSelector, getShapeSelector, + getTableOfCellsSelector +} from '../store/reducers'; import { toggleStatus } from '../store/cell-duck'; const mapStateToProps = (state) => ({ tableOfCells: getTableOfCellsSelector(state), honeyComb: getHoneyCombSelector(state), shape: getShapeSelector, - canRedo: true, - canUndo: true, + canRedo: getFutureHoneyCombSelector(state).length, + canUndo: getPastHoneyCombSelector(state).length, });