Commit 1ceac69a authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'nfriend-hide-lead-time-if-not-availabl' into 'master'

Hide lead time graphs if not available

See merge request gitlab-org/gitlab!59268
parents 1a5cb572 a76c6dbc
...@@ -18,6 +18,10 @@ export default { ...@@ -18,6 +18,10 @@ export default {
type: Boolean, type: Boolean,
default: false, default: false,
}, },
shouldRenderLeadTimeCharts: {
type: Boolean,
default: false,
},
}, },
data() { data() {
return { return {
...@@ -26,11 +30,17 @@ export default { ...@@ -26,11 +30,17 @@ export default {
}, },
computed: { computed: {
charts() { charts() {
const chartsToShow = ['pipelines'];
if (this.shouldRenderDeploymentFrequencyCharts) { if (this.shouldRenderDeploymentFrequencyCharts) {
return ['pipelines', 'deployments', 'lead-time']; chartsToShow.push('deployments');
}
if (this.shouldRenderLeadTimeCharts) {
chartsToShow.push('lead-time');
} }
return ['pipelines', 'lead-time']; return chartsToShow;
}, },
}, },
created() { created() {
...@@ -55,16 +65,17 @@ export default { ...@@ -55,16 +65,17 @@ export default {
</script> </script>
<template> <template>
<div> <div>
<gl-tabs :value="selectedTab" @input="onTabChange"> <gl-tabs v-if="charts.length > 1" :value="selectedTab" @input="onTabChange">
<gl-tab :title="__('Pipelines')"> <gl-tab :title="__('Pipelines')">
<pipeline-charts /> <pipeline-charts />
</gl-tab> </gl-tab>
<gl-tab v-if="shouldRenderDeploymentFrequencyCharts" :title="__('Deployments')"> <gl-tab v-if="shouldRenderDeploymentFrequencyCharts" :title="__('Deployments')">
<deployment-frequency-charts /> <deployment-frequency-charts />
</gl-tab> </gl-tab>
<gl-tab :title="__('Lead Time')"> <gl-tab v-if="shouldRenderLeadTimeCharts" :title="__('Lead Time')">
<lead-time-charts /> <lead-time-charts />
</gl-tab> </gl-tab>
</gl-tabs> </gl-tabs>
<pipeline-charts v-else />
</div> </div>
</template> </template>
...@@ -16,6 +16,7 @@ const mountPipelineChartsApp = (el) => { ...@@ -16,6 +16,7 @@ const mountPipelineChartsApp = (el) => {
const shouldRenderDeploymentFrequencyCharts = parseBoolean( const shouldRenderDeploymentFrequencyCharts = parseBoolean(
el.dataset.shouldRenderDeploymentFrequencyCharts, el.dataset.shouldRenderDeploymentFrequencyCharts,
); );
const shouldRenderLeadTimeCharts = parseBoolean(el.dataset.shouldRenderLeadTimeCharts);
return new Vue({ return new Vue({
el, el,
...@@ -27,6 +28,7 @@ const mountPipelineChartsApp = (el) => { ...@@ -27,6 +28,7 @@ const mountPipelineChartsApp = (el) => {
provide: { provide: {
projectPath, projectPath,
shouldRenderDeploymentFrequencyCharts, shouldRenderDeploymentFrequencyCharts,
shouldRenderLeadTimeCharts,
}, },
render: (createElement) => createElement(ProjectPipelinesCharts, {}), render: (createElement) => createElement(ProjectPipelinesCharts, {}),
}); });
......
...@@ -26,6 +26,10 @@ module GraphHelper ...@@ -26,6 +26,10 @@ module GraphHelper
def should_render_deployment_frequency_charts def should_render_deployment_frequency_charts
false false
end end
def should_render_lead_time_charts
false
end
end end
GraphHelper.prepend_if_ee('EE::GraphHelper') GraphHelper.prepend_if_ee('EE::GraphHelper')
- page_title _('CI/CD Analytics') - page_title _('CI/CD Analytics')
#js-project-pipelines-charts-app{ data: { project_path: @project.full_path, #js-project-pipelines-charts-app{ data: { project_path: @project.full_path,
should_render_deployment_frequency_charts: should_render_deployment_frequency_charts.to_s } } should_render_deployment_frequency_charts: should_render_deployment_frequency_charts.to_s,
should_render_lead_time_charts: should_render_lead_time_charts.to_s } }
...@@ -11,5 +11,12 @@ module EE ...@@ -11,5 +11,12 @@ module EE
can?(current_user, :read_dora4_analytics, @project) can?(current_user, :read_dora4_analytics, @project)
end end
override :should_render_lead_time_charts
def should_render_lead_time_charts
return false unless @project.feature_available?(:dora4_analytics)
can?(current_user, :read_dora4_analytics, @project)
end
end end
end end
...@@ -3,20 +3,23 @@ ...@@ -3,20 +3,23 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe EE::GraphHelper do RSpec.describe EE::GraphHelper do
describe '#should_render_deployment_frequency_charts' do let_it_be(:current_user) { create(:user) }
let_it_be(:current_user) { create(:user) } let(:project) { create(:project, :private) }
let(:project) { create(:project, :private) } let(:is_feature_licensed) { true }
let(:is_user_authorized) { true }
before do
stub_licensed_features(dora4_analytics: is_feature_licensed)
self.instance_variable_set(:@current_user, current_user)
self.instance_variable_set(:@project, project)
allow(self).to receive(:can?).with(current_user, :read_dora4_analytics, project).and_return(is_user_authorized)
end
let(:is_feature_licensed) { true } describe '#should_render_deployment_frequency_charts' do
let(:is_flag_enabled) { true } let(:is_flag_enabled) { true }
let(:is_user_authorized) { true }
before do before do
stub_licensed_features(dora4_analytics: is_feature_licensed)
stub_feature_flags(deployment_frequency_charts: is_flag_enabled) stub_feature_flags(deployment_frequency_charts: is_flag_enabled)
self.instance_variable_set(:@current_user, current_user)
self.instance_variable_set(:@project, project)
allow(self).to receive(:can?).with(current_user, :read_dora4_analytics, project).and_return(is_user_authorized)
end end
shared_examples 'returns true' do shared_examples 'returns true' do
...@@ -47,4 +50,28 @@ RSpec.describe EE::GraphHelper do ...@@ -47,4 +50,28 @@ RSpec.describe EE::GraphHelper do
it_behaves_like 'returns false' it_behaves_like 'returns false'
end end
end end
describe '#should_render_lead_time_charts' do
shared_examples 'returns true' do
it { expect(should_render_lead_time_charts).to be(true) }
end
shared_examples 'returns false' do
it { expect(should_render_lead_time_charts).to be(false) }
end
it_behaves_like 'returns true'
context 'when the feature is not available' do
let(:is_feature_licensed) { false }
it_behaves_like 'returns false'
end
context 'when the user does not have permission' do
let(:is_user_authorized) { false }
it_behaves_like 'returns false'
end
end
end end
...@@ -22,7 +22,8 @@ describe('ProjectsPipelinesChartsApp', () => { ...@@ -22,7 +22,8 @@ describe('ProjectsPipelinesChartsApp', () => {
{}, {},
{ {
provide: { provide: {
shouldRenderDeploymentFrequencyCharts: false, shouldRenderDeploymentFrequencyCharts: true,
shouldRenderLeadTimeCharts: true,
}, },
stubs: { stubs: {
DeploymentFrequencyCharts: DeploymentFrequencyChartsStub, DeploymentFrequencyCharts: DeploymentFrequencyChartsStub,
...@@ -34,46 +35,46 @@ describe('ProjectsPipelinesChartsApp', () => { ...@@ -34,46 +35,46 @@ describe('ProjectsPipelinesChartsApp', () => {
); );
} }
beforeEach(() => {
createComponent();
});
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
wrapper = null;
}); });
const findGlTabs = () => wrapper.find(GlTabs); const findGlTabs = () => wrapper.find(GlTabs);
const findAllGlTab = () => wrapper.findAll(GlTab); const findAllGlTabs = () => wrapper.findAll(GlTab);
const findGlTabAt = (i) => findAllGlTab().at(i);
const findLeadTimeCharts = () => wrapper.find(LeadTimeChartsStub); const findLeadTimeCharts = () => wrapper.find(LeadTimeChartsStub);
const findDeploymentFrequencyCharts = () => wrapper.find(DeploymentFrequencyChartsStub); const findDeploymentFrequencyCharts = () => wrapper.find(DeploymentFrequencyChartsStub);
const findPipelineCharts = () => wrapper.find(PipelineCharts); const findPipelineCharts = () => wrapper.find(PipelineCharts);
it('renders the pipeline charts', () => { const expectCorrectTabs = ({ pipelines, leadTime, deploymentFreqency }) => {
expect(findPipelineCharts().exists()).toBe(true); it('renders the expected tabs', () => {
}); expect(findGlTabs().exists()).toBe(true);
it('renders the lead time charts', () => { const allTabTitles = findAllGlTabs().wrappers.map((w) => w.attributes('title'));
expect(findLeadTimeCharts().exists()).toBe(true);
});
describe('when shouldRenderDeploymentFrequencyCharts is true', () => { if (pipelines) {
beforeEach(() => { expect(allTabTitles).toContain('Pipelines');
createComponent({ provide: { shouldRenderDeploymentFrequencyCharts: true } }); expect(findPipelineCharts().exists()).toBe(true);
}); }
it('renders the expected tabs', () => { if (deploymentFreqency) {
expect(findGlTabs().exists()).toBe(true); expect(allTabTitles).toContain('Deployments');
expect(findGlTabAt(0).attributes('title')).toBe('Pipelines'); expect(findDeploymentFrequencyCharts().exists()).toBe(true);
expect(findGlTabAt(1).attributes('title')).toBe('Deployments'); }
expect(findGlTabAt(2).attributes('title')).toBe('Lead Time');
if (leadTime) {
expect(allTabTitles).toContain('Lead Time');
expect(findLeadTimeCharts().exists()).toBe(true);
}
}); });
};
it('renders the deployment frequency charts', () => { describe('when all charts are available', () => {
expect(findDeploymentFrequencyCharts().exists()).toBe(true); beforeEach(() => {
createComponent();
}); });
expectCorrectTabs({ pipelines: true, deploymentFreqency: true, leadTime: true });
it('sets the tab and url when a tab is clicked', async () => { it('sets the tab and url when a tab is clicked', async () => {
let chartsPath; let chartsPath;
setWindowLocation(`${TEST_HOST}/gitlab-org/gitlab-test/-/pipelines/charts`); setWindowLocation(`${TEST_HOST}/gitlab-org/gitlab-test/-/pipelines/charts`);
...@@ -172,14 +173,33 @@ describe('ProjectsPipelinesChartsApp', () => { ...@@ -172,14 +173,33 @@ describe('ProjectsPipelinesChartsApp', () => {
createComponent({ provide: { shouldRenderDeploymentFrequencyCharts: false } }); createComponent({ provide: { shouldRenderDeploymentFrequencyCharts: false } });
}); });
it('renders the expected tabs', () => { expectCorrectTabs({ pipelines: true, deploymentFreqency: false, leadTime: true });
expect(findGlTabs().exists()).toBe(true); });
expect(findGlTabAt(0).attributes('title')).toBe('Pipelines');
expect(findGlTabAt(1).attributes('title')).toBe('Lead Time'); describe('when shouldRenderLeadTimeCharts is false', () => {
beforeEach(() => {
createComponent({ provide: { shouldRenderLeadTimeCharts: false } });
});
expectCorrectTabs({ pipelines: true, deploymentFreqency: true, leadTime: false });
});
describe('when shouldRenderDeploymentFrequencyCharts and shouldRenderLeadTimeCharts are false', () => {
beforeEach(() => {
createComponent({
provide: {
shouldRenderDeploymentFrequencyCharts: false,
shouldRenderLeadTimeCharts: false,
},
});
});
it('does not render tabs', () => {
expect(findGlTabs().exists()).toBe(false);
}); });
it('does not render the deployment frequency charts in a tab', () => { it('renders the pipeline charts', () => {
expect(findDeploymentFrequencyCharts().exists()).toBe(false); expect(findPipelineCharts().exists()).toBe(true);
}); });
}); });
}); });
...@@ -27,4 +27,16 @@ RSpec.describe GraphHelper do ...@@ -27,4 +27,16 @@ RSpec.describe GraphHelper do
expect(should_render_deployment_frequency_charts).to be(false) expect(should_render_deployment_frequency_charts).to be(false)
end end
end end
describe '#should_render_lead_time_charts' do
let(:project) { create(:project, :private) }
before do
self.instance_variable_set(:@project, project)
end
it 'always returns false' do
expect(should_render_lead_time_charts).to be(false)
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