Skip to content

Commit

Permalink
Fix states on select dropdown (#586)
Browse files Browse the repository at this point in the history
* Fix model function

* Fixed tests

* Change validation 'story' to 'story._editing'
  • Loading branch information
edumoreira1506 authored and talyssonoc committed Oct 7, 2019
1 parent 8f7cda6 commit bd137cb
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 75 deletions.
6 changes: 2 additions & 4 deletions app/assets/javascripts/models/beta/story.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ export const compareStartedAt = (a, b) => {
return compareValues(a.startedAt, b.startedAt);
};

export const isUnestimatedFeature = story => {
return (story.estimate === null || story.estimate === '') && story.storyType === storyTypes.FEATURE;
};
export const isUnestimatedFeature = story => !hasEstimate(story) && isFeature(story)

export const isFeature = story => {
return story.storyType === storyTypes.FEATURE;
Expand Down Expand Up @@ -82,7 +80,7 @@ export const releaseIsLate = (story) => {
}

export const possibleStatesFor = story =>
isUnestimatedFeature(story) ? states : [states[0]];
isUnestimatedFeature(story._editing) ? [states[0]] : states;

export const types = ['feature', 'bug', 'release', 'chore'];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { shallow, mount } from 'enzyme';
import ExpandedStoryState from 'components/story/ExpandedStory/ExpandedStoryState';
import { states } from '../../../../../app/assets/javascripts/models/beta/story';
import { states, types } from '../../../../../app/assets/javascripts/models/beta/story';
import { storyTypes } from '../../../../../app/assets/javascripts/libs/beta/constants'

describe('<ExpandedStoryState />', () => {
Expand All @@ -28,11 +28,53 @@ describe('<ExpandedStoryState />', () => {
onEditSpy = sinon.spy();
})

describe('when is estimated feature', () => {
const noFeatureTypes = types.filter(type => type !== storyTypes.FEATURE);

noFeatureTypes.forEach(noFeatureType => {
describe(`when is no ${noFeatureType}`, () => {
states.forEach(state => {
describe(`and state is ${state}`, () => {
const story = {
_editing: {
state,
estimate: 1,
storyType: noFeatureType,
}
};

let wrapper;

beforeEach(() => {
wrapper = shallow(
<ExpandedStoryState
story={story}
onEdit={onEditSpy}
disabled={false}
/>
);
});

it('renders all states', () => {
expect(wrapper.find('option').length).toEqual(7);
});

it(`has to be ${state}`, () => {
expect(wrapper.find('select').prop('value')).toBe(state);
});
});
});
})
})

describe('when is unestimated feature', () => {
let onEditSpy;

beforeEach(() => {
onEditSpy = sinon.spy();
})

const story = {
estimate: 1,
storyType: storyTypes.BUG,
_editing: { state: states[0] }
_editing: { state: states[0], estimate: null, storyType: storyTypes.FEATURE }
};
let wrapper;

Expand All @@ -44,45 +86,16 @@ describe('<ExpandedStoryState />', () => {
disabled={false}
/>
);
});

})
it('renders just one state', () => {
expect(wrapper.find('option').length).toEqual(1);
});

it('has to be unscheduled', () => {
expect(wrapper.find('select').prop('value')).toBe(states[0]);
});
})

describe('when is unestimated feature', () => {
let onEditSpy;

beforeEach(() => {
onEditSpy = sinon.spy();
})

const story = {
estimate: null,
storyType: storyTypes.FEATURE,
_editing: { state: states[0] }
};
let wrapper;

beforeEach(() => {
wrapper = shallow(
<ExpandedStoryState
story={story}
onEdit={onEditSpy}
disabled={false}
/>
);
})

it('renders all states', () => {
expect(wrapper.find('option').length).toEqual(states.length);
});
})

states.forEach(state => {
it(`sets select value as ${state}`, () => {
Expand Down Expand Up @@ -183,7 +196,7 @@ describe('<ExpandedStoryState />', () => {

describe("to a number", () => {
it("doesn't disable state select when estimate is a number", () => {
const story = { _editing: { estimate: !isNaN, storyType: 'feature', state: 'unstarted' } };
const story = { _editing: { estimate: 1, storyType: 'feature', state: 'unstarted' } };

const wrapper = shallow(
<ExpandedStoryState
Expand Down
61 changes: 27 additions & 34 deletions spec/javascripts/models/beta/story_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -994,62 +994,59 @@ describe('Story model', function () {

describe("possibleStatesFor", () => {
const invalidEstimates = [null, ''];
const invalidStoryTypes = [storyTypes.FEATURE]
const validEstimates = [1,2,3]
const validStoryTypes = [storyTypes.BUG, storyTypes.CHORE, storyTypes.RELEASE]

invalidStoryTypes.forEach(invalidStoryType => {
describe(`when storyType is ${invalidStoryType}`, () => {
const featureTypes = Story.types.filter(type => type === storyTypes.FEATURE)
const noFeatureTypes = Story.types.filter(type => type !== storyTypes.FEATURE)

featureTypes.forEach(featureType => {
describe(`when storyType is ${featureType}`, () => {
invalidEstimates.forEach(invalidEstimate => {
describe(`and estimate is "${invalidEstimate}"`, () => {
let story;

beforeEach(() => {
story = { estimate: invalidEstimate, storyType: invalidStoryType}
story = { _editing: { estimate: invalidEstimate, storyType: featureType } }
});

it('returns all states', () => {
expect(Story.possibleStatesFor(story).length).toEqual(7);
it(`state has to be ${status.UNSCHEDULED}`, () => {
expect(Story.possibleStatesFor(story)[0]).toEqual(status.UNSCHEDULED);
})
})

validEstimates.forEach(validEstimate => {
describe(`and estimate is ${validEstimate}`, () => {
let story;
it('returns just one state', () => {
expect(Story.possibleStatesFor(story).length).toEqual(1);
})
})
})

beforeEach(() => {
story = { estimate: validEstimate, storyType: invalidStoryType }
});
validEstimates.forEach(validEstimate => {
describe(`and estimate is ${validEstimate}`, () => {
let story;

it(`state has to be ${status.UNSCHEDULED}`, () => {
expect(Story.possibleStatesFor(story)[0]).toEqual(status.UNSCHEDULED);
})
beforeEach(() => {
story = { _editing: { estimate: validEstimate, storyType: featureType } }
});

it('return just one state', () => {
expect(Story.possibleStatesFor(story).length).toEqual(1);
})
it('return all states', () => {
expect(Story.possibleStatesFor(story).length).toEqual(7);
})
})
})
})
})

validStoryTypes.forEach(validStoryType => {
describe(`when storyType is ${validStoryType}`, () => {
noFeatureTypes.forEach(noFeatureType => {
describe(`when storyType is ${noFeatureType}`, () => {
invalidEstimates.forEach(invalidEstimate => {
describe(`and estimate is "${invalidEstimate}"`, () => {
let story;

beforeEach(() => {
story = { estimate: invalidEstimate, storyType: validStoryType}
story = { _editing: { estimate: invalidEstimate, storyType: noFeatureType } }
});

it('returns all states', () => {
expect(Story.possibleStatesFor(story).length).toEqual(1);
})

it(`state has to be ${status.UNSCHEDULED}`, () => {
expect(Story.possibleStatesFor(story)[0]).toEqual(status.UNSCHEDULED);
expect(Story.possibleStatesFor(story).length).toEqual(7);
})
})

Expand All @@ -1058,15 +1055,11 @@ describe('Story model', function () {
let story;

beforeEach(() => {
story = { estimate: validEstimate, storyType: validStoryType }
story = { _editing: { estimate: validEstimate, storyType: noFeatureType } }
});

it('returns all states', () => {
expect(Story.possibleStatesFor(story).length).toEqual(1);
})

it(`state has to be ${status.UNSCHEDULED}`, () => {
expect(Story.possibleStatesFor(story)[0]).toEqual(status.UNSCHEDULED);
expect(Story.possibleStatesFor(story).length).toEqual(7);
})
})
})
Expand Down

0 comments on commit bd137cb

Please sign in to comment.