Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhavya Narula committed Sep 27, 2018
2 parents 77882c0 + e8212e8 commit e4c216b
Show file tree
Hide file tree
Showing 10 changed files with 321 additions and 189 deletions.
3 changes: 3 additions & 0 deletions src/BowlerScorer/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ const bowlerScorerReducer = function bowlerScorerReducer(state = initialState, a
newState.isNewOverStarting = true;
}
}
if (action.lastbowl.wicket) {
currentBowler.wickets += 1;
}
return newState;
}
case actionNames.AddNewBowlerActionName: {
Expand Down
48 changes: 24 additions & 24 deletions src/PlayerList/playerListReducer.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@

const Teams = {
const initialState = {
Teams: [
{
name: 'Team 1',
players: [
{
name: 'Player 1',
id: '1',
id: 1,
},
{
name: 'Player 2',
id: '2',
id: 2,
},
{
name: 'Player 3',
id: '3',
id: 3,
},
{
name: 'Player 4',
id: '4',
id: 4,
},
{
name: 'Player 5',
id: '5',
id: 5,
},
{
name: 'Player 6',
id: '6',
id: 6,
},
{
name: 'Player 7',
id: '7',
id: 7,
},
{
name: 'Player 8',
id: '8',
id: 8,
},
{
name: 'Player 9',
id: '9',
id: 9,
},
{
name: 'Player 10',
id: '10',
id: 10,
},
{
name: 'Player 11',
id: '11',
id: 11,
},
],
},
Expand All @@ -55,54 +55,54 @@ const Teams = {
players: [
{
name: 'Player 21',
id: '1',
id: 1,
},
{
name: 'Player 22',
id: '2',
id: 2,
},
{
name: 'Player 23',
id: '3',
id: 3,
},
{
name: 'Player 24',
id: '4',
id: 4,
},
{
name: 'Player 25',
id: '5',
id: 5,
},
{
name: 'Player 26',
id: '6',
id: 6,
},
{
name: 'Player 27',
id: '7',
id: 7,
},
{
name: 'Player 28',
id: '8',
id: 8,
},
{
name: 'Player 29',
id: '9',
id: 9,
},
{
name: 'Player 30',
id: '10',
id: 10,
},
{
name: 'Player 31',
id: '11',
id: 11,
},
],
},
],
};

const playerListReducer = function playerListReducer(state = Teams, action) {
const playerListReducer = function playerListReducer(state = initialState, action) {
switch (action.type) {
default:
return state;
Expand Down
202 changes: 102 additions & 100 deletions src/PlayerList/playerListReducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,106 +2,108 @@ import playerListReducer from './playerListReducer';

describe('gameInformation/reducer', () => {
it('should return initial state of 11 players in each team', () => {
const initialState = [
{
name: 'Team 1',
players: [
{
name: 'Player 1',
id: '1',
},
{
name: 'Player 2',
id: '2',
},
{
name: 'Player 3',
id: '3',
},
{
name: 'Player 4',
id: '4',
},
{
name: 'Player 5',
id: '5',
},
{
name: 'Player 6',
id: '6',
},
{
name: 'Player 7',
id: '7',
},
{
name: 'Player 8',
id: '8',
},
{
name: 'Player 9',
id: '9',
},
{
name: 'Player 10',
id: '10',
},
{
name: 'Player 11',
id: '11',
},
],
},
{
name: 'Team 2',
players: [
{
name: 'Player 21',
id: '1',
},
{
name: 'Player 22',
id: '2',
},
{
name: 'Player 23',
id: '3',
},
{
name: 'Player 24',
id: '4',
},
{
name: 'Player 25',
id: '5',
},
{
name: 'Player 26',
id: '6',
},
{
name: 'Player 27',
id: '7',
},
{
name: 'Player 28',
id: '8',
},
{
name: 'Player 29',
id: '9',
},
{
name: 'Player 30',
id: '10',
},
{
name: 'Player 31',
id: '11',
},
],
},
];
const initialState = {
Teams: [
{
name: 'Team 1',
players: [
{
name: 'Player 1',
id: 1,
},
{
name: 'Player 2',
id: 2,
},
{
name: 'Player 3',
id: 3,
},
{
name: 'Player 4',
id: 4,
},
{
name: 'Player 5',
id: 5,
},
{
name: 'Player 6',
id: 6,
},
{
name: 'Player 7',
id: 7,
},
{
name: 'Player 8',
id: 8,
},
{
name: 'Player 9',
id: 9,
},
{
name: 'Player 10',
id: 10,
},
{
name: 'Player 11',
id: 11,
},
],
},
{
name: 'Team 2',
players: [
{
name: 'Player 21',
id: 1,
},
{
name: 'Player 22',
id: 2,
},
{
name: 'Player 23',
id: 3,
},
{
name: 'Player 24',
id: 4,
},
{
name: 'Player 25',
id: 5,
},
{
name: 'Player 26',
id: 6,
},
{
name: 'Player 27',
id: 7,
},
{
name: 'Player 28',
id: 8,
},
{
name: 'Player 29',
id: 9,
},
{
name: 'Player 30',
id: 10,
},
{
name: 'Player 31',
id: 11,
},
],
},
],
};
expect(playerListReducer(undefined, {})).toEqual(initialState);
});
});
9 changes: 6 additions & 3 deletions src/ThisOver/ThisOver.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ class ThisOver extends Component {

return players.filter(item => (bowlerId === item.id))[0].name;
};
const getExtrasStr = function getExtrasStr(extras) {
return extras ? `-${extras}` : '';
const getExtrasStr = function getExtrasStr(extras, wicket) {
const wicketStr = (wicket ? '-W' : '');
const extraStr = (extras ? `-${extras}` : '');
return extraStr + wicketStr;
};
const overData = this.props.currentOver.map((item, indx) => {
const index = indx;
return <span key={index}>{item.runs + getExtrasStr(item.extras)}&nbsp;&nbsp;</span>;
return (
<span key={index}>{item.runs + getExtrasStr(item.extras, item.wicket)}&nbsp;&nbsp;</span>);
});
return (
<div className="home-component this-over-wrapper">
Expand Down
21 changes: 21 additions & 0 deletions src/batsmanScorer/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ const batsManScorerReducer = function batsManScorerReducer(state = initialState,
cloneState.strikerBatsmanId = cloneState.nonstrikerBatsmanId;
cloneState.nonstrikerBatsmanId = nonstrikerBatsmanId;
}
if (action.lastbowl.wicket) {
currentBatsman[0].isOut = action.lastbowl.wicket;
const nextBatsmanId = (
cloneState.strikerBatsmanId > cloneState.nonstrikerBatsmanId ?
cloneState.strikerBatsmanId : cloneState.nonstrikerBatsmanId
) + 1;
const nextBatsman = action.batsmenList.players.filter(item => item.id === nextBatsmanId);
if (nextBatsman.length > 0) {
const newBatsman = {
name: nextBatsman[0].name,
id: nextBatsman[0].id,
runs: 0,
fours: 0,
sixes: 0,
ballsplayed: 0,
isOut: false,
};
cloneState.battingTeamPlayers.push(newBatsman);
cloneState.strikerBatsmanId = newBatsman.id;
}
}

if (action.lastbowl.extras) {
return cloneState;
Expand Down
Loading

0 comments on commit e4c216b

Please sign in to comment.