Skip to content

Commit

Permalink
Group by sprints directly in the store (#384)
Browse files Browse the repository at this point in the history
* Group by sprints directly in the store

* requested modifications
- ordering was not being considered on backlog reducer
- add tests to backlog reducer

* initialize sprints array in Sprints component
  • Loading branch information
julliasaad authored and talyssonoc committed Sep 27, 2018
1 parent 827bd14 commit 74d22e9
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 37 deletions.
7 changes: 4 additions & 3 deletions app/assets/javascripts/actions/column.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ const setStoryChillyBin = payload => ({
data: payload
});

const setStoryBacklog = payload => ({
const setStoryBacklog = (payload, project) => ({
type: actionTypes.COLUMN_BACKLOG,
data: payload
data: payload,
project: project
});

const setStoryDone = payload => ({
Expand All @@ -21,7 +22,7 @@ export const getColumnType = (story, project) => {
return setStoryChillyBin(story);
}
if (isBacklog(story, project)) {
return setStoryBacklog(story);
return setStoryBacklog(story, project);
}
return setStoryDone(story);
};
Expand Down
1 change: 0 additions & 1 deletion app/assets/javascripts/components/Columns/ColumnItem.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from "react";
import Stories from "../stories/Stories";

const Column = ({ title, children }) => (
<div className="Column">
Expand Down
3 changes: 1 addition & 2 deletions app/assets/javascripts/components/projects/ProjectBoard.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class ProjectBoard extends React.Component {
title={`${I18n.t("projects.show.backlog")} /
${I18n.t("projects.show.in_progress")}`}>
<Sprints
stories={this.props.columns.backlog.stories}
project={this.props.project}
sprints={this.props.columns.backlog.sprints}
/>
</Column>

Expand Down
18 changes: 6 additions & 12 deletions app/assets/javascripts/components/stories/Sprints.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import React from "react";
import PropTypes from "prop-types";
import Sprint from "./Sprint";
import * as Iteration from "models/beta/iteration";

const propTypes = {
stories: PropTypes.array,
project: PropTypes.object
project: PropTypes.object,
sprints: PropTypes.array,
};

const defaultProps = {
stories: [],
project: {}
project: {},
sprints: [],
};

const renderSprints = sprints => {
Expand All @@ -29,15 +30,8 @@ const renderSprints = sprints => {
);
};

const Sprints = ({ stories, project }) => {
const currentSprintNumber = Iteration.getCurrentIteration(project) || 0;
const sprints = Iteration.groupBySprints(
stories,
project,
currentSprintNumber
);

if (!stories.length) return null;
const Sprints = ({ sprints }) => {
if (!sprints.length) return null;

return <div className="Sprints">{renderSprints(sprints)}</div>;
};
Expand Down
6 changes: 4 additions & 2 deletions app/assets/javascripts/models/beta/iteration.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ const addStoryToSprint = (project, sprints, index, story) => {
}
}
fillRemainingPoints(
sprints, Story.getPoints(story),
index, project.defaultVelocity,
sprints,
Story.getPoints(story),
index,
project.defaultVelocity,
previousFillerSprintsQuantity
);

Expand Down
21 changes: 17 additions & 4 deletions app/assets/javascripts/reducers/columns/backlog.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import actionTypes from "actions/actionTypes";
import { status } from "libs/beta/constants";
import * as Story from "models/beta/story";
import _ from "underscore";
import * as Iteration from "models/beta/iteration";

const initialState = {
stories: []
stories: [],
sprints: [],
};

const filterByState = state => story => {
Expand Down Expand Up @@ -38,7 +40,7 @@ const orderByState = stories => {
);
const unestimatedUnstartedStories = partitionedFeatures[0];
const estimatedUnstartedStories = partitionedFeatures[1];

return [
...acceptedStories,
...deliveredStories,
Expand All @@ -50,13 +52,24 @@ const orderByState = stories => {
];
};

const groupStoriesInSprints = (stories, project) => {
const currentSprintNumber = Iteration.getCurrentIteration(project) || 0;

return Iteration.groupBySprints(
stories,
project,
currentSprintNumber
);
};

const backlog = (state = initialState, action) => {
switch (action.type) {
case actionTypes.COLUMN_BACKLOG:
const stories = [...state.stories, action.data];

const orderedStories = orderByState(stories);
return {
stories: orderByState(stories)
stories: orderedStories,
sprints: groupStoriesInSprints(orderedStories, action.project)
};
default:
return state;
Expand Down
32 changes: 29 additions & 3 deletions spec/javascripts/components/stories/sprints_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,32 @@ const createProps = () => ({
startDate: "2018-09-03T16:00:00",
iterationLength: 1,
defaultVelocity: 2
}
},
sprints: [
{
completedPoints: 0,
isFiller: false,
number: 1,
points: 1,
remainingPoints: 1,
stories: [
{
id: 1,
position: "3",
state: "unstarted",
estimate: 1,
storyType: "feature"
},
{
id: 2,
position: "2",
state: "unstarted",
estimate: 1,
storyType: "feature"
}
],
}
]
});

describe("<Sprints />", () => {
Expand All @@ -41,12 +66,13 @@ describe("<Sprints />", () => {
expect(wrapper.find("Sprint")).toHaveLength(1);
});

describe("when no stories are passed as props", () => {
describe("when no sprints are passed as props", () => {
beforeEach(() => {
props = createProps();
props.stories = [];
props.sprints = [];
wrapper = shallow(<Sprints {...props} />);
});

it("does not render any <Sprint> component", () => {
expect(wrapper.find("Sprint")).toHaveLength(0);
});
Expand Down
71 changes: 61 additions & 10 deletions spec/javascripts/reducers/column_backlog_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,26 @@ describe('Backlog Column reducer', () => {
deliveredAt: '2018-08-06T16:36:20.811Z',
estimate: 1
}
]
],
}
}

function createEmptyInitialstate() {
return {
stories: []
stories: [],
sprints: [],
}
}

function createAction(data) {
return {
type: actionTypes.COLUMN_BACKLOG,
data
data,
project: {
startDate: "2018-09-03T16:00:00",
iterationLength: 1,
defaultVelocity: 2,
},
}
}

Expand All @@ -80,7 +86,6 @@ describe('Backlog Column reducer', () => {


describe("when there are stories on the initial state", () => {

it("return the new story with the others", () => {
const newStory = {
id : 80,
Expand Down Expand Up @@ -111,6 +116,58 @@ describe('Backlog Column reducer', () => {
expect(state.stories[5].state).toEqual('unstarted');
});

describe("when stories are grouped by sprints", () => {
const stories = [
{
id: 1,
position: '1.0',
state: 'unstarted',
estimate: 2,
storyType: "feature",
},
{
id: 2,
position: '2.0',
state: 'unstarted',
estimate: 2,
storyType: "feature",
},
{
id: 3,
position: '4.0',
state: 'delivered',
estimate: 2,
storyType: "feature",
},
{
id: 4,
position: '4.0',
state: 'finished',
estimate: 2,
storyType: "feature",
},
];
const action = createAction(stories);
let state;

beforeEach(() => {
state = reducer({ stories: stories, sprints: [] }, action);
});

it("creates 3 sprints", () => {
expect(state.sprints.length).toEqual(3);
});

it("adds 2 stories to current sprint", () => {
expect(state.sprints[0].stories.length).toEqual(2);
});

it("stories grouped in current sprint are ordered by state", () => {
expect(state.sprints[0].stories[0].state).toEqual('delivered');
expect(state.sprints[0].stories[1].state).toEqual('finished');
});
});

describe("when the story states are the same", () => {
describe("accepted stories", () => {
describe("when the acceptedAt of the new story is older then the others", () => {
Expand All @@ -130,7 +187,6 @@ describe('Backlog Column reducer', () => {
expect(state.stories[0].state).toEqual('accepted');
expect(state.stories[1].state).toEqual('accepted');
expect(state.stories[0].id).toEqual(newStory.id);

});
});

Expand All @@ -151,7 +207,6 @@ describe('Backlog Column reducer', () => {
expect(state.stories[0].state).toEqual('accepted');
expect(state.stories[1].state).toEqual('accepted');
expect(state.stories[1].id).toEqual(newStory.id);

});
});
});
Expand All @@ -174,7 +229,6 @@ describe('Backlog Column reducer', () => {
expect(state.stories[1].state).toEqual('delivered');
expect(state.stories[2].state).toEqual('delivered');
expect(state.stories[1].id).toEqual(newStory.id);

});
});

Expand All @@ -194,7 +248,6 @@ describe('Backlog Column reducer', () => {
expect(state.stories[1].state).toEqual('delivered');
expect(state.stories[2].state).toEqual('delivered');
expect(state.stories[2].id).toEqual(newStory.id);

});
});
});
Expand All @@ -217,7 +270,6 @@ describe('Backlog Column reducer', () => {
expect(state.stories[4].state).toEqual('started');
expect(state.stories[5].state).toEqual('started');
expect(state.stories[4].id).toEqual(newStory.id);

});
});

Expand All @@ -237,7 +289,6 @@ describe('Backlog Column reducer', () => {
expect(state.stories[4].state).toEqual('started');
expect(state.stories[5].state).toEqual('started');
expect(state.stories[5].id).toEqual(newStory.id);

});
});
});
Expand Down

0 comments on commit 74d22e9

Please sign in to comment.