Commit 31315850 authored by Sean McGivern's avatar Sean McGivern

Merge branch '30138-display-cycle-analytics-issue' into 'master'

Display and logic improvements for cycle analytics

Closes #30138

See merge request gitlab-org/gitlab-ce!28507
parents aa8e7591 13f37264
...@@ -9,7 +9,8 @@ class AnalyticsStageEntity < Grape::Entity ...@@ -9,7 +9,8 @@ class AnalyticsStageEntity < Grape::Entity
expose :description expose :description
expose :median, as: :value do |stage| expose :median, as: :value do |stage|
# median returns a BatchLoader instance which we first have to unwrap by using to_i # median returns a BatchLoader instance which we first have to unwrap by using to_f
!stage.median.to_i.zero? ? distance_of_time_in_words(stage.median) : nil # we use to_f to make sure results below 1 are presented to the end-user
stage.median.to_f.nonzero? ? distance_of_time_in_words(stage.median) : nil
end end
end end
---
title: Show data on Cycle Analytics page when value is less than a second
merge_request: 28507
author:
type: fixed
...@@ -21,4 +21,34 @@ describe AnalyticsStageSerializer do ...@@ -21,4 +21,34 @@ describe AnalyticsStageSerializer do
it 'contains important elements of AnalyticsStage' do it 'contains important elements of AnalyticsStage' do
expect(subject).to include(:title, :description, :value) expect(subject).to include(:title, :description, :value)
end end
context 'when median is equal 0' do
before do
allow_any_instance_of(Gitlab::CycleAnalytics::BaseStage).to receive(:median).and_return(0)
end
it 'sets the value to nil' do
expect(subject.fetch(:value)).to be_nil
end
end
context 'when median is below 1' do
before do
allow_any_instance_of(Gitlab::CycleAnalytics::BaseStage).to receive(:median).and_return(0.12)
end
it 'sets the value to equal to median' do
expect(subject.fetch(:value)).to eq('less than a minute')
end
end
context 'when median is above 1' do
before do
allow_any_instance_of(Gitlab::CycleAnalytics::BaseStage).to receive(:median).and_return(60.12)
end
it 'sets the value to equal to median' do
expect(subject.fetch(:value)).to eq('1 minute')
end
end
end end
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