Commit c4ab6898 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo Committed by Martin Wortschack

Show the dropdown when there are value streams

Updates the related create value stream specs
to check inside the dropdown
parent 0489d9c0
...@@ -14,7 +14,6 @@ import { mapState, mapActions } from 'vuex'; ...@@ -14,7 +14,6 @@ import { mapState, mapActions } from 'vuex';
import { sprintf, __ } from '~/locale'; import { sprintf, __ } from '~/locale';
import { debounce } from 'lodash'; import { debounce } from 'lodash';
import { DATA_REFETCH_DELAY } from '../../shared/constants'; import { DATA_REFETCH_DELAY } from '../../shared/constants';
import { DEFAULT_VALUE_STREAM_ID } from '../constants';
const ERRORS = { const ERRORS = {
MIN_LENGTH: __('Name is required'), MIN_LENGTH: __('Name is required'),
...@@ -32,10 +31,6 @@ const validate = ({ name }) => { ...@@ -32,10 +31,6 @@ const validate = ({ name }) => {
return errors; return errors;
}; };
const hasCustomValueStream = vs => {
return Boolean(vs.length > 1 || vs[0].name.toLowerCase().trim() !== DEFAULT_VALUE_STREAM_ID);
};
export default { export default {
components: { components: {
GlButton, GlButton,
...@@ -70,7 +65,7 @@ export default { ...@@ -70,7 +65,7 @@ export default {
return this.errors.name?.join('\n'); return this.errors.name?.join('\n');
}, },
hasValueStreams() { hasValueStreams() {
return Boolean(this.data.length && hasCustomValueStream(this.data)); return Boolean(this.data.length);
}, },
selectedValueStreamName() { selectedValueStreamName() {
return this.selectedValueStream?.name || ''; return this.selectedValueStream?.name || '';
...@@ -124,7 +119,12 @@ export default { ...@@ -124,7 +119,12 @@ export default {
</script> </script>
<template> <template>
<gl-form> <gl-form>
<gl-dropdown v-if="hasValueStreams" :text="selectedValueStreamName" right> <gl-dropdown
v-if="hasValueStreams"
data-testid="dropdown-value-streams"
:text="selectedValueStreamName"
right
>
<gl-dropdown-item <gl-dropdown-item
v-for="{ id, name: streamName } in data" v-for="{ id, name: streamName } in data"
:key="id" :key="id"
......
...@@ -147,6 +147,8 @@ export default { ...@@ -147,6 +147,8 @@ export default {
}, },
[types.RECEIVE_VALUE_STREAMS_SUCCESS](state, data) { [types.RECEIVE_VALUE_STREAMS_SUCCESS](state, data) {
state.isLoadingValueStreams = false; state.isLoadingValueStreams = false;
state.valueStreams = data; state.valueStreams = data.sort(({ name: aName = '' }, { name: bName = '' }) => {
return aName.toUpperCase() > bName.toUpperCase() ? 1 : -1;
});
}, },
}; };
...@@ -23,6 +23,7 @@ RSpec.describe 'Group Value Stream Analytics', :js do ...@@ -23,6 +23,7 @@ RSpec.describe 'Group Value Stream Analytics', :js do
path_nav_selector = '.js-path-navigation' path_nav_selector = '.js-path-navigation'
filter_bar_selector = '.js-filter-bar' filter_bar_selector = '.js-filter-bar'
duration_stage_selector = '.js-dropdown-stages' duration_stage_selector = '.js-dropdown-stages'
value_stream_selector = '[data-testid="dropdown-value-streams"]'
3.times do |i| 3.times do |i|
let_it_be("issue_#{i}".to_sym) { create(:issue, title: "New Issue #{i}", project: project, created_at: 2.days.ago) } let_it_be("issue_#{i}".to_sym) { create(:issue, title: "New Issue #{i}", project: project, created_at: 2.days.ago) }
...@@ -1018,6 +1019,11 @@ RSpec.describe 'Group Value Stream Analytics', :js do ...@@ -1018,6 +1019,11 @@ RSpec.describe 'Group Value Stream Analytics', :js do
describe 'Create value stream', :js do describe 'Create value stream', :js do
let(:custom_value_stream_name) { "Test value stream" } let(:custom_value_stream_name) { "Test value stream" }
let(:value_stream_dropdown) { page.find(value_stream_selector) }
def toggle_value_stream_dropdown
value_stream_dropdown.click
end
before do before do
visit analytics_cycle_analytics_path visit analytics_cycle_analytics_path
...@@ -1026,6 +1032,8 @@ RSpec.describe 'Group Value Stream Analytics', :js do ...@@ -1026,6 +1032,8 @@ RSpec.describe 'Group Value Stream Analytics', :js do
end end
it 'can create a value stream' do it 'can create a value stream' do
toggle_value_stream_dropdown
page.find_button(_('Create new Value Stream')).click page.find_button(_('Create new Value Stream')).click
fill_in 'create-value-stream-name', with: custom_value_stream_name fill_in 'create-value-stream-name', with: custom_value_stream_name
......
...@@ -84,6 +84,24 @@ describe('ValueStreamSelect', () => { ...@@ -84,6 +84,24 @@ describe('ValueStreamSelect', () => {
}); });
}); });
describe('Only the default value stream available', () => {
beforeEach(() => {
wrapper = createComponent({
initialState: {
valueStreams: [{ id: 'default', name: 'default' }],
},
});
});
it('does not display the create value stream button', () => {
expect(findCreateValueStreamButton().exists()).toBe(false);
});
it('displays the select value stream dropdown', () => {
expect(findSelectValueStreamDropdown().exists()).toBe(true);
});
});
describe('No value streams available', () => { describe('No value streams available', () => {
beforeEach(() => { beforeEach(() => {
wrapper = createComponent({ wrapper = createComponent({
......
...@@ -76,6 +76,21 @@ describe('Cycle analytics mutations', () => { ...@@ -76,6 +76,21 @@ describe('Cycle analytics mutations', () => {
}, },
); );
describe(`${types.RECEIVE_VALUE_STREAMS_SUCCESS}`, () => {
const dummyValueStream = { id: 3, name: 'A new value stream' };
const sorted = [dummyValueStream, valueStreams[0], valueStreams[1]];
it('will sort the value streams alphabetically', () => {
state = { valueStreams: [] };
mutations[types.RECEIVE_VALUE_STREAMS_SUCCESS](state, [
valueStreams[1],
valueStreams[0],
dummyValueStream,
]);
expect(state.valueStreams).toEqual(sorted);
});
});
describe('with value streams available', () => { describe('with value streams available', () => {
it.each` it.each`
mutation | payload | expectedState mutation | payload | expectedState
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment