Commit 18b78fcd authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '351853-vsa-render-empty-state-when-no-value-streams' into 'master'

VSA Remove the default value stream

See merge request gitlab-org/gitlab!84180
parents b33053cd ef895556
...@@ -97,7 +97,13 @@ class Groups::Analytics::CycleAnalytics::ValueStreamsController < Groups::Analyt ...@@ -97,7 +97,13 @@ class Groups::Analytics::CycleAnalytics::ValueStreamsController < Groups::Analyt
end end
def value_streams def value_streams
@group.value_streams.preload_associated_models.presence || [in_memory_default_value_stream] value_streams = @group.value_streams.preload_associated_models
if Feature.enabled?(:use_vsa_aggregated_tables, @group, default_enabled: :yaml)
value_streams
else
value_streams.presence || [in_memory_default_value_stream]
end
end end
def in_memory_default_value_stream def in_memory_default_value_stream
......
...@@ -11,7 +11,11 @@ module EE ...@@ -11,7 +11,11 @@ module EE
def execute def execute
return forbidden unless allowed? return forbidden unless allowed?
success(persisted_stages.presence || build_default_stages) if parent.is_a?(Group) && ::Feature.enabled?(:use_vsa_aggregated_tables, parent, default_enabled: :yaml)
success(persisted_stages)
else
success(persisted_stages.presence || build_default_stages)
end
end end
private private
......
...@@ -5,6 +5,15 @@ require 'spec_helper' ...@@ -5,6 +5,15 @@ require 'spec_helper'
RSpec.describe Groups::Analytics::CycleAnalytics::StagesController do RSpec.describe Groups::Analytics::CycleAnalytics::StagesController do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be(:group, refind: true) { create(:group) } let_it_be(:group, refind: true) { create(:group) }
let_it_be(:stages) { [] }
let_it_be(:value_stream) do
create(:cycle_analytics_group_value_stream,
group: group,
name: 'No stage value stream',
stages: stages
)
end
context 'when params have only group_id' do context 'when params have only group_id' do
let(:params) { { group_id: group } } let(:params) { { group_id: group } }
...@@ -19,6 +28,8 @@ RSpec.describe Groups::Analytics::CycleAnalytics::StagesController do ...@@ -19,6 +28,8 @@ RSpec.describe Groups::Analytics::CycleAnalytics::StagesController do
end end
context 'when use_vsa_aggregated_tables FF is disabled' do context 'when use_vsa_aggregated_tables FF is disabled' do
let_it_be(:stages) { Gitlab::Analytics::CycleAnalytics::DefaultStages.all }
it_behaves_like 'Value Stream Analytics Stages controller' do it_behaves_like 'Value Stream Analytics Stages controller' do
before do before do
stub_feature_flags(use_vsa_aggregated_tables: false) stub_feature_flags(use_vsa_aggregated_tables: false)
...@@ -28,7 +39,19 @@ RSpec.describe Groups::Analytics::CycleAnalytics::StagesController do ...@@ -28,7 +39,19 @@ RSpec.describe Groups::Analytics::CycleAnalytics::StagesController do
end end
context 'when params have group_id and value_stream_id' do context 'when params have group_id and value_stream_id' do
let_it_be(:value_stream) { create(:cycle_analytics_group_value_stream, group: group) } let_it_be(:stages) do
[
create(:cycle_analytics_group_stage, group: group, name: "Issue", relative_position: 1),
create(:cycle_analytics_group_stage, group: group, name: "Code", relative_position: 2)
]
end
let_it_be(:value_stream) do
create(:cycle_analytics_group_value_stream,
group: group,
name: 'First value stream',
stages: stages)
end
let(:params) { { group_id: group, value_stream_id: value_stream.id } } let(:params) { { group_id: group, value_stream_id: value_stream.id } }
let(:parent) { group } let(:parent) { group }
......
...@@ -16,14 +16,34 @@ RSpec.describe Groups::Analytics::CycleAnalytics::ValueStreamsController do ...@@ -16,14 +16,34 @@ RSpec.describe Groups::Analytics::CycleAnalytics::ValueStreamsController do
end end
describe 'GET #index' do describe 'GET #index' do
it 'returns an in-memory default value stream' do context 'when the use_vsa_aggregated_tables feature flag is off' do
get :index, params: params before do
stub_feature_flags(use_vsa_aggregated_tables: false)
end
it 'returns an in-memory default value stream' do
get :index, params: params
expect(response).to have_gitlab_http_status(:ok)
expect(json_response.size).to eq(1)
expect(json_response.first['id']).to eq(Analytics::CycleAnalytics::Stages::BaseService::DEFAULT_VALUE_STREAM_NAME)
expect(json_response.first['name']).to eq(Analytics::CycleAnalytics::Stages::BaseService::DEFAULT_VALUE_STREAM_NAME)
end
end
context 'when the use_vsa_aggregated_tables feature flag is on' do
before do
stub_feature_flags(use_vsa_aggregated_tables: true)
end
expect(response).to have_gitlab_http_status(:ok) it 'returns an empty array' do
get :index, params: params
expect(json_response.size).to eq(1) expect(response).to have_gitlab_http_status(:ok)
expect(json_response.first['id']).to eq(Analytics::CycleAnalytics::Stages::BaseService::DEFAULT_VALUE_STREAM_NAME)
expect(json_response.first['name']).to eq(Analytics::CycleAnalytics::Stages::BaseService::DEFAULT_VALUE_STREAM_NAME) expect(json_response.size).to eq(0)
end
end end
context 'when persisted value streams present' do context 'when persisted value streams present' do
......
...@@ -12,6 +12,16 @@ RSpec.describe 'Value stream analytics charts', :js do ...@@ -12,6 +12,16 @@ RSpec.describe 'Value stream analytics charts', :js do
let_it_be(:group_label2) { create(:group_label, group: group) } let_it_be(:group_label2) { create(:group_label, group: group) }
let_it_be(:label) { create(:group_label, group: group2) } let_it_be(:label) { create(:group_label, group: group2) }
let_it_be(:custom_value_stream_name) { "New created value stream" }
let_it_be(:value_stream) do
create(:cycle_analytics_group_value_stream, group: group, name: custom_value_stream_name, stages: [
create(:cycle_analytics_group_stage, group: group, name: "Issue", relative_position: 1, start_event_identifier: :issue_created, end_event_identifier: :issue_closed),
create(:cycle_analytics_group_stage, group: group, name: "Code", relative_position: 2, start_event_identifier: :merge_request_created, end_event_identifier: :merge_request_merged),
create(:cycle_analytics_group_stage, group: group, name: "Milestone Plan", relative_position: 3, start_event_identifier: :issue_first_associated_with_milestone, end_event_identifier: :issue_first_added_to_board)
])
end
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) }
end end
...@@ -33,12 +43,9 @@ RSpec.describe 'Value stream analytics charts', :js do ...@@ -33,12 +43,9 @@ RSpec.describe 'Value stream analytics charts', :js do
end end
context 'Duration chart' do context 'Duration chart' do
let(:custom_value_stream_name) { "New created value stream" }
before do before do
select_group(group) select_group(group)
select_value_stream(custom_value_stream_name)
create_custom_value_stream(custom_value_stream_name)
end end
it 'displays data for all stages on the overview' do it 'displays data for all stages on the overview' do
...@@ -81,6 +88,7 @@ RSpec.describe 'Value stream analytics charts', :js do ...@@ -81,6 +88,7 @@ RSpec.describe 'Value stream analytics charts', :js do
end end
select_group(group) select_group(group)
select_value_stream(custom_value_stream_name)
end end
it 'displays the chart' do it 'displays the chart' do
......
...@@ -18,7 +18,7 @@ RSpec.describe 'Multiple value streams', :js do ...@@ -18,7 +18,7 @@ RSpec.describe 'Multiple value streams', :js do
let(:extended_form_fields_selector) { '[data-testid="extended-form-fields"]' } let(:extended_form_fields_selector) { '[data-testid="extended-form-fields"]' }
let(:preset_selector) { '[data-testid="vsa-preset-selector"]' } let(:preset_selector) { '[data-testid="vsa-preset-selector"]' }
let!(:default_value_stream) { create(:cycle_analytics_group_value_stream, group: group, name: 'default') } let(:empty_state_selector) { '[data-testid="vsa-empty-state"]' }
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) }
...@@ -198,7 +198,7 @@ RSpec.describe 'Multiple value streams', :js do ...@@ -198,7 +198,7 @@ RSpec.describe 'Multiple value streams', :js do
end end
end end
describe 'With a group' do shared_examples 'create group value streams' do
name = 'group value stream' name = 'group value stream'
before do before do
...@@ -210,7 +210,7 @@ RSpec.describe 'Multiple value streams', :js do ...@@ -210,7 +210,7 @@ RSpec.describe 'Multiple value streams', :js do
it_behaves_like 'delete a value stream', name it_behaves_like 'delete a value stream', name
end end
describe 'With a sub group' do shared_examples 'create sub group value streams' do
name = 'sub group value stream' name = 'sub group value stream'
before do before do
...@@ -221,4 +221,42 @@ RSpec.describe 'Multiple value streams', :js do ...@@ -221,4 +221,42 @@ RSpec.describe 'Multiple value streams', :js do
it_behaves_like 'update a value stream', name it_behaves_like 'update a value stream', name
it_behaves_like 'delete a value stream', name it_behaves_like 'delete a value stream', name
end end
context 'use_vsa_aggregated_tables feature flag off' do
before do
stub_feature_flags(use_vsa_aggregated_tables: false)
end
it_behaves_like 'create group value streams'
it_behaves_like 'create sub group value streams'
end
context 'use_vsa_aggregated_tables feature flag on' do
context 'without a value stream' do
before do
select_group(group, empty_state_selector)
end
it 'renders the empty state' do
expect(page).to have_text(s_('CycleAnalytics|Custom value streams to measure your DevSecOps lifecycle'))
end
it 'can navigate to the create value stream form' do
page.find('[data-testid="create-value-stream-button"]').click
expect(page).to have_selector('[data-testid="value-stream-form-modal"]')
end
end
context 'with a value stream' do
before do
# ensure we have a value stream already available
create(:cycle_analytics_group_value_stream, group: group, name: 'default')
create(:cycle_analytics_group_value_stream, group: sub_group, name: 'default')
end
it_behaves_like 'create group value streams'
it_behaves_like 'create sub group value streams'
end
end
end end
...@@ -19,27 +19,43 @@ RSpec.describe Analytics::CycleAnalytics::Stages::ListService do ...@@ -19,27 +19,43 @@ RSpec.describe Analytics::CycleAnalytics::Stages::ListService do
stub_licensed_features(cycle_analytics_for_groups: true) stub_licensed_features(cycle_analytics_for_groups: true)
end end
it_behaves_like 'permission check for Value Stream Analytics Stage services', :cycle_analytics_for_groups context 'when the use_vsa_aggregated_tables feature is enabled' do
before do
stub_feature_flags(use_vsa_aggregated_tables: true)
end
it 'returns only the default stages' do it_behaves_like 'permission check for Value Stream Analytics Stage services', :cycle_analytics_for_groups
expect(stages.size).to eq(Gitlab::Analytics::CycleAnalytics::DefaultStages.all.size)
end
it 'provides the default stages as non-persisted objects' do it 'returns empty array' do
expect(stages.map(&:id)).to all(be_nil) expect(stages.size).to eq(0)
end end
it 'provides the default stages as non-persisted objects' do
expect(stages.map(&:id)).to all(be_nil)
end
it 'does not persist the value stream record' do it 'does not persist the value stream record' do
expect { subject }.not_to change { Analytics::CycleAnalytics::GroupValueStream.count } expect { subject }.not_to change { Analytics::CycleAnalytics::GroupValueStream.count }
end
context 'when there are persisted stages' do
let_it_be(:stage1) { create(:cycle_analytics_group_stage, parent: group, relative_position: 2, value_stream: value_stream) }
let_it_be(:stage2) { create(:cycle_analytics_group_stage, parent: group, relative_position: 3, value_stream: value_stream) }
let_it_be(:stage3) { create(:cycle_analytics_group_stage, parent: group, relative_position: 1, value_stream: value_stream) }
it 'returns the persisted stages in order' do
expect(stages).to eq([stage3, stage1, stage2])
end
end
end end
context 'when there are persisted stages' do context 'when the use_vsa_aggregated_tables feature is disabled' do
let_it_be(:stage1) { create(:cycle_analytics_group_stage, parent: group, relative_position: 2, value_stream: value_stream) } before do
let_it_be(:stage2) { create(:cycle_analytics_group_stage, parent: group, relative_position: 3, value_stream: value_stream) } stub_feature_flags(use_vsa_aggregated_tables: false)
let_it_be(:stage3) { create(:cycle_analytics_group_stage, parent: group, relative_position: 1, value_stream: value_stream) } end
it 'returns the persisted stages in order' do it 'returns the default stages' do
expect(stages).to eq([stage3, stage1, stage2]) expect(stages.size).to eq(Gitlab::Analytics::CycleAnalytics::DefaultStages.all.size)
end end
end end
end end
...@@ -22,7 +22,7 @@ RSpec.shared_examples 'Value Stream Analytics Stages controller' do ...@@ -22,7 +22,7 @@ RSpec.shared_examples 'Value Stream Analytics Stages controller' do
subject subject
response_start_events = json_response['stages'].map { |s| s['start_event_identifier'] } response_start_events = json_response['stages'].map { |s| s['start_event_identifier'] }
start_events = Gitlab::Analytics::CycleAnalytics::DefaultStages.all.map { |s| s['start_event_identifier'] } start_events = stages.map { |s| s['start_event_identifier'] }
expect(response_start_events).to eq(start_events) expect(response_start_events).to eq(start_events)
end end
......
...@@ -86,6 +86,13 @@ module CycleAnalyticsHelpers ...@@ -86,6 +86,13 @@ module CycleAnalyticsHelpers
wait_for_stages_to_load(ready_selector) wait_for_stages_to_load(ready_selector)
end end
def select_value_stream(value_stream_name)
toggle_value_stream_dropdown
page.find('[data-testid="dropdown-value-streams"]').all('li button').find { |item| item.text == value_stream_name.to_s }.click
wait_for_requests
end
def toggle_dropdown(field) def toggle_dropdown(field)
page.within("[data-testid*='#{field}']") do page.within("[data-testid*='#{field}']") do
find('.dropdown-toggle').click find('.dropdown-toggle').click
......
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