Commit c39becb5 authored by Tim Zallmann's avatar Tim Zallmann

Merge branch 'nfriend-deduplicate-dora-flag-names' into 'master'

Deduplicate DORA chart visibility flag names

See merge request gitlab-org/gitlab!59291
parents 29f133ee 0b3d3fbf
...@@ -14,11 +14,7 @@ export default { ...@@ -14,11 +14,7 @@ export default {
import('ee_component/projects/pipelines/charts/components/lead_time_charts.vue'), import('ee_component/projects/pipelines/charts/components/lead_time_charts.vue'),
}, },
inject: { inject: {
shouldRenderDeploymentFrequencyCharts: { shouldRenderDoraCharts: {
type: Boolean,
default: false,
},
shouldRenderLeadTimeCharts: {
type: Boolean, type: Boolean,
default: false, default: false,
}, },
...@@ -32,12 +28,8 @@ export default { ...@@ -32,12 +28,8 @@ export default {
charts() { charts() {
const chartsToShow = ['pipelines']; const chartsToShow = ['pipelines'];
if (this.shouldRenderDeploymentFrequencyCharts) { if (this.shouldRenderDoraCharts) {
chartsToShow.push('deployments'); chartsToShow.push('deployments', 'lead-time');
}
if (this.shouldRenderLeadTimeCharts) {
chartsToShow.push('lead-time');
} }
return chartsToShow; return chartsToShow;
...@@ -69,12 +61,14 @@ export default { ...@@ -69,12 +61,14 @@ export default {
<gl-tab :title="__('Pipelines')"> <gl-tab :title="__('Pipelines')">
<pipeline-charts /> <pipeline-charts />
</gl-tab> </gl-tab>
<gl-tab v-if="shouldRenderDeploymentFrequencyCharts" :title="__('Deployments')"> <template v-if="shouldRenderDoraCharts">
<deployment-frequency-charts /> <gl-tab :title="__('Deployments')">
</gl-tab> <deployment-frequency-charts />
<gl-tab v-if="shouldRenderLeadTimeCharts" :title="__('Lead Time')"> </gl-tab>
<lead-time-charts /> <gl-tab :title="__('Lead Time')">
</gl-tab> <lead-time-charts />
</gl-tab>
</template>
</gl-tabs> </gl-tabs>
<pipeline-charts v-else /> <pipeline-charts v-else />
</div> </div>
......
...@@ -13,10 +13,7 @@ const apolloProvider = new VueApollo({ ...@@ -13,10 +13,7 @@ const apolloProvider = new VueApollo({
const mountPipelineChartsApp = (el) => { const mountPipelineChartsApp = (el) => {
const { projectPath } = el.dataset; const { projectPath } = el.dataset;
const shouldRenderDeploymentFrequencyCharts = parseBoolean( const shouldRenderDoraCharts = parseBoolean(el.dataset.shouldRenderDoraCharts);
el.dataset.shouldRenderDeploymentFrequencyCharts,
);
const shouldRenderLeadTimeCharts = parseBoolean(el.dataset.shouldRenderLeadTimeCharts);
return new Vue({ return new Vue({
el, el,
...@@ -27,8 +24,7 @@ const mountPipelineChartsApp = (el) => { ...@@ -27,8 +24,7 @@ const mountPipelineChartsApp = (el) => {
apolloProvider, apolloProvider,
provide: { provide: {
projectPath, projectPath,
shouldRenderDeploymentFrequencyCharts, shouldRenderDoraCharts,
shouldRenderLeadTimeCharts,
}, },
render: (createElement) => createElement(ProjectPipelinesCharts, {}), render: (createElement) => createElement(ProjectPipelinesCharts, {}),
}); });
......
...@@ -23,11 +23,7 @@ module GraphHelper ...@@ -23,11 +23,7 @@ module GraphHelper
ratio.to_i ratio.to_i
end end
def should_render_deployment_frequency_charts def should_render_dora_charts
false
end
def should_render_lead_time_charts
false false
end end
end end
......
- 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_dora_charts: should_render_dora_charts.to_s } }
should_render_lead_time_charts: should_render_lead_time_charts.to_s } }
...@@ -4,15 +4,8 @@ module EE ...@@ -4,15 +4,8 @@ module EE
module GraphHelper module GraphHelper
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
override :should_render_deployment_frequency_charts override :should_render_dora_charts
def should_render_deployment_frequency_charts def should_render_dora_charts
return false unless @project.feature_available?(:dora4_analytics)
can?(current_user, :read_dora4_analytics, @project)
end
override :should_render_lead_time_charts
def should_render_lead_time_charts
return false unless @project.feature_available?(:dora4_analytics) return false unless @project.feature_available?(:dora4_analytics)
can?(current_user, :read_dora4_analytics, @project) can?(current_user, :read_dora4_analytics, @project)
......
...@@ -15,37 +15,13 @@ RSpec.describe EE::GraphHelper do ...@@ -15,37 +15,13 @@ RSpec.describe EE::GraphHelper do
allow(self).to receive(:can?).with(current_user, :read_dora4_analytics, project).and_return(is_user_authorized) allow(self).to receive(:can?).with(current_user, :read_dora4_analytics, project).and_return(is_user_authorized)
end end
describe '#should_render_deployment_frequency_charts' do describe '#should_render_dora_charts' do
shared_examples 'returns true' do shared_examples 'returns true' do
it { expect(should_render_deployment_frequency_charts).to be(true) } it { expect(should_render_dora_charts).to be(true) }
end end
shared_examples 'returns false' do shared_examples 'returns false' do
it { expect(should_render_deployment_frequency_charts).to be(false) } it { expect(should_render_dora_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
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 end
it_behaves_like 'returns true' it_behaves_like 'returns true'
......
...@@ -22,8 +22,7 @@ describe('ProjectsPipelinesChartsApp', () => { ...@@ -22,8 +22,7 @@ describe('ProjectsPipelinesChartsApp', () => {
{}, {},
{ {
provide: { provide: {
shouldRenderDeploymentFrequencyCharts: true, shouldRenderDoraCharts: true,
shouldRenderLeadTimeCharts: true,
}, },
stubs: { stubs: {
DeploymentFrequencyCharts: DeploymentFrequencyChartsStub, DeploymentFrequencyCharts: DeploymentFrequencyChartsStub,
...@@ -41,39 +40,35 @@ describe('ProjectsPipelinesChartsApp', () => { ...@@ -41,39 +40,35 @@ describe('ProjectsPipelinesChartsApp', () => {
const findGlTabs = () => wrapper.find(GlTabs); const findGlTabs = () => wrapper.find(GlTabs);
const findAllGlTabs = () => wrapper.findAll(GlTab); const findAllGlTabs = () => wrapper.findAll(GlTab);
const findGlTabAtIndex = (index) => findAllGlTabs().at(index);
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);
const expectCorrectTabs = ({ pipelines, leadTime, deploymentFreqency }) => { describe('when all charts are available', () => {
it('renders the expected tabs', () => { beforeEach(() => {
expect(findGlTabs().exists()).toBe(true); createComponent();
});
const allTabTitles = findAllGlTabs().wrappers.map((w) => w.attributes('title'));
if (pipelines) { it('renders tabs', () => {
expect(allTabTitles).toContain('Pipelines'); expect(findGlTabs().exists()).toBe(true);
expect(findPipelineCharts().exists()).toBe(true);
}
if (deploymentFreqency) { expect(findGlTabAtIndex(0).attributes('title')).toBe('Pipelines');
expect(allTabTitles).toContain('Deployments'); expect(findGlTabAtIndex(1).attributes('title')).toBe('Deployments');
expect(findDeploymentFrequencyCharts().exists()).toBe(true); expect(findGlTabAtIndex(2).attributes('title')).toBe('Lead Time');
} });
if (leadTime) { it('renders the pipeline charts', () => {
expect(allTabTitles).toContain('Lead Time'); expect(findPipelineCharts().exists()).toBe(true);
expect(findLeadTimeCharts().exists()).toBe(true);
}
}); });
};
describe('when all charts are available', () => { it('renders the deployment frequency charts', () => {
beforeEach(() => { expect(findDeploymentFrequencyCharts().exists()).toBe(true);
createComponent();
}); });
expectCorrectTabs({ pipelines: true, deploymentFreqency: true, leadTime: true }); it('renders the lead time charts', () => {
expect(findLeadTimeCharts().exists()).toBe(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;
...@@ -131,7 +126,7 @@ describe('ProjectsPipelinesChartsApp', () => { ...@@ -131,7 +126,7 @@ describe('ProjectsPipelinesChartsApp', () => {
expect(name).toBe('chart'); expect(name).toBe('chart');
return chart ? [chart] : []; return chart ? [chart] : [];
}); });
createComponent({ provide: { shouldRenderDeploymentFrequencyCharts: true } }); createComponent();
expect(findGlTabs().attributes('value')).toBe(tab); expect(findGlTabs().attributes('value')).toBe(tab);
}); });
...@@ -151,7 +146,7 @@ describe('ProjectsPipelinesChartsApp', () => { ...@@ -151,7 +146,7 @@ describe('ProjectsPipelinesChartsApp', () => {
return []; return [];
}); });
createComponent({ provide: { shouldRenderDeploymentFrequencyCharts: true } }); createComponent();
expect(findGlTabs().attributes('value')).toBe('0'); expect(findGlTabs().attributes('value')).toBe('0');
...@@ -168,30 +163,9 @@ describe('ProjectsPipelinesChartsApp', () => { ...@@ -168,30 +163,9 @@ describe('ProjectsPipelinesChartsApp', () => {
}); });
}); });
describe('when shouldRenderDeploymentFrequencyCharts is false', () => { describe('when the dora charts are not available', () => {
beforeEach(() => {
createComponent({ provide: { shouldRenderDeploymentFrequencyCharts: false } });
});
expectCorrectTabs({ pipelines: true, deploymentFreqency: false, leadTime: true });
});
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(() => { beforeEach(() => {
createComponent({ createComponent({ provide: { shouldRenderDoraCharts: false } });
provide: {
shouldRenderDeploymentFrequencyCharts: false,
shouldRenderLeadTimeCharts: false,
},
});
}); });
it('does not render tabs', () => { it('does not render tabs', () => {
......
...@@ -16,7 +16,7 @@ RSpec.describe GraphHelper do ...@@ -16,7 +16,7 @@ RSpec.describe GraphHelper do
end end
end end
describe '#should_render_deployment_frequency_charts' do describe '#should_render_dora_charts' do
let(:project) { create(:project, :private) } let(:project) { create(:project, :private) }
before do before do
...@@ -24,19 +24,7 @@ RSpec.describe GraphHelper do ...@@ -24,19 +24,7 @@ RSpec.describe GraphHelper do
end end
it 'always returns false' do it 'always returns false' do
expect(should_render_deployment_frequency_charts).to be(false) expect(should_render_dora_charts).to be(false)
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
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