summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-10 15:09:50 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-10 15:09:50 +0000
commitde2fb5b82c92c90f90ed67ced45143c04e934fb8 (patch)
treeff8e5e642580de7bb596d90dd0e7f739f44ca540 /spec
parentc6a33b298229f9e04933be43d6176c476ef03012 (diff)
downloadgitlab-ce-de2fb5b82c92c90f90ed67ced45143c04e934fb8.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/features/clusters/cluster_detail_page_spec.rb18
-rw-r--r--spec/fixtures/lib/gitlab/metrics/dashboard/schemas/panels.json1
-rw-r--r--spec/frontend/jira_import/components/jira_import_form_spec.js62
-rw-r--r--spec/frontend/prometheus_metrics/custom_metrics_spec.js122
-rw-r--r--spec/frontend/prometheus_metrics/mock_data.js22
-rw-r--r--spec/helpers/clusters_helper_spec.rb35
-rw-r--r--spec/lib/gitlab/metrics/dashboard/stages/panel_ids_inserter_spec.rb67
-rw-r--r--spec/requests/api/releases_spec.rb8
-rw-r--r--spec/services/tags/create_service_spec.rb24
9 files changed, 346 insertions, 13 deletions
diff --git a/spec/features/clusters/cluster_detail_page_spec.rb b/spec/features/clusters/cluster_detail_page_spec.rb
index 28d6c10f04f..4b478163952 100644
--- a/spec/features/clusters/cluster_detail_page_spec.rb
+++ b/spec/features/clusters/cluster_detail_page_spec.rb
@@ -14,6 +14,12 @@ describe 'Clusterable > Show page' do
end
shared_examples 'show page' do
+ it 'displays cluster type label' do
+ visit cluster_path
+
+ expect(page).to have_content(cluster_type_label)
+ end
+
it 'allow the user to set domain' do
visit cluster_path
@@ -125,7 +131,9 @@ describe 'Clusterable > Show page' do
clusterable.add_maintainer(current_user)
end
- it_behaves_like 'show page'
+ it_behaves_like 'show page' do
+ let(:cluster_type_label) { 'Project cluster' }
+ end
it_behaves_like 'editing a GCP cluster'
@@ -143,7 +151,9 @@ describe 'Clusterable > Show page' do
clusterable.add_maintainer(current_user)
end
- it_behaves_like 'show page'
+ it_behaves_like 'show page' do
+ let(:cluster_type_label) { 'Group cluster' }
+ end
it_behaves_like 'editing a GCP cluster'
@@ -157,7 +167,9 @@ describe 'Clusterable > Show page' do
let(:cluster_path) { admin_cluster_path(cluster) }
let(:cluster) { create(:cluster, :provided_by_gcp, :instance) }
- it_behaves_like 'show page'
+ it_behaves_like 'show page' do
+ let(:cluster_type_label) { 'Instance cluster' }
+ end
it_behaves_like 'editing a GCP cluster'
diff --git a/spec/fixtures/lib/gitlab/metrics/dashboard/schemas/panels.json b/spec/fixtures/lib/gitlab/metrics/dashboard/schemas/panels.json
index 9f39e9c77cb..fe2da16c9b7 100644
--- a/spec/fixtures/lib/gitlab/metrics/dashboard/schemas/panels.json
+++ b/spec/fixtures/lib/gitlab/metrics/dashboard/schemas/panels.json
@@ -7,6 +7,7 @@
],
"properties": {
"title": { "type": "string" },
+ "id": { "type": "string" },
"type": { "type": "string" },
"y_label": { "type": "string" },
"y_axis": { "$ref": "axis.json" },
diff --git a/spec/frontend/jira_import/components/jira_import_form_spec.js b/spec/frontend/jira_import/components/jira_import_form_spec.js
new file mode 100644
index 00000000000..315ccccd991
--- /dev/null
+++ b/spec/frontend/jira_import/components/jira_import_form_spec.js
@@ -0,0 +1,62 @@
+import { GlAvatar, GlNewButton, GlFormSelect, GlLabel } from '@gitlab/ui';
+import { shallowMount } from '@vue/test-utils';
+import JiraImportForm from '~/jira_import/components/jira_import_form.vue';
+
+describe('JiraImportForm', () => {
+ let wrapper;
+
+ beforeEach(() => {
+ wrapper = shallowMount(JiraImportForm);
+ });
+
+ afterEach(() => {
+ wrapper.destroy();
+ wrapper = null;
+ });
+
+ it('shows a dropdown to choose the Jira project to import from', () => {
+ expect(wrapper.find(GlFormSelect).exists()).toBe(true);
+ });
+
+ it('shows a label which will be applied to imported Jira projects', () => {
+ expect(wrapper.find(GlLabel).attributes('title')).toBe('jira-import::KEY-1');
+ });
+
+ it('shows information to the user', () => {
+ expect(wrapper.find('p').text()).toBe(
+ "For each Jira issue successfully imported, we'll create a new GitLab issue with the following data:",
+ );
+ });
+
+ it('shows jira.issue.summary for the Title', () => {
+ expect(wrapper.find('[id="jira-project-title"]').text()).toBe('jira.issue.summary');
+ });
+
+ it('shows an avatar for the Reporter', () => {
+ expect(wrapper.find(GlAvatar).exists()).toBe(true);
+ });
+
+ it('shows jira.issue.description.content for the Description', () => {
+ expect(wrapper.find('[id="jira-project-description"]').text()).toBe(
+ 'jira.issue.description.content',
+ );
+ });
+
+ it('shows a Next button', () => {
+ const nextButton = wrapper
+ .findAll(GlNewButton)
+ .at(0)
+ .text();
+
+ expect(nextButton).toBe('Next');
+ });
+
+ it('shows a Cancel button', () => {
+ const cancelButton = wrapper
+ .findAll(GlNewButton)
+ .at(1)
+ .text();
+
+ expect(cancelButton).toBe('Cancel');
+ });
+});
diff --git a/spec/frontend/prometheus_metrics/custom_metrics_spec.js b/spec/frontend/prometheus_metrics/custom_metrics_spec.js
new file mode 100644
index 00000000000..3396b3694c0
--- /dev/null
+++ b/spec/frontend/prometheus_metrics/custom_metrics_spec.js
@@ -0,0 +1,122 @@
+import MockAdapter from 'axios-mock-adapter';
+import PrometheusMetrics from '~/prometheus_metrics/custom_metrics';
+import axios from '~/lib/utils/axios_utils';
+import PANEL_STATE from '~/prometheus_metrics/constants';
+import metrics from './mock_data';
+
+describe('PrometheusMetrics', () => {
+ const FIXTURE = 'services/prometheus/prometheus_service.html';
+ const customMetricsEndpoint =
+ 'http://test.host/frontend-fixtures/services-project/prometheus/metrics';
+ let mock;
+ preloadFixtures(FIXTURE);
+
+ beforeEach(() => {
+ mock = new MockAdapter(axios);
+ mock.onGet(customMetricsEndpoint).reply(200, {
+ metrics,
+ });
+ loadFixtures(FIXTURE);
+ });
+
+ afterEach(() => {
+ mock.restore();
+ });
+
+ describe('Custom Metrics', () => {
+ let prometheusMetrics;
+
+ beforeEach(() => {
+ prometheusMetrics = new PrometheusMetrics('.js-prometheus-metrics-monitoring');
+ });
+
+ it('should initialize wrapper element refs on the class object', () => {
+ expect(prometheusMetrics.$wrapperCustomMetrics).not.toBeNull();
+ expect(prometheusMetrics.$monitoredCustomMetricsPanel).not.toBeNull();
+ expect(prometheusMetrics.$monitoredCustomMetricsCount).not.toBeNull();
+ expect(prometheusMetrics.$monitoredCustomMetricsLoading).not.toBeNull();
+ expect(prometheusMetrics.$monitoredCustomMetricsEmpty).not.toBeNull();
+ expect(prometheusMetrics.$monitoredCustomMetricsList).not.toBeNull();
+ expect(prometheusMetrics.$newCustomMetricButton).not.toBeNull();
+ expect(prometheusMetrics.$flashCustomMetricsContainer).not.toBeNull();
+ });
+
+ it('should contain api endpoints', () => {
+ expect(prometheusMetrics.activeCustomMetricsEndpoint).toEqual(customMetricsEndpoint);
+ });
+
+ it('should show loading state when called with `loading`', () => {
+ prometheusMetrics.showMonitoringCustomMetricsPanelState(PANEL_STATE.LOADING);
+
+ expect(prometheusMetrics.$monitoredCustomMetricsLoading.hasClass('hidden')).toEqual(false);
+ expect(prometheusMetrics.$monitoredCustomMetricsEmpty.hasClass('hidden')).toBeTruthy();
+ expect(prometheusMetrics.$monitoredCustomMetricsList.hasClass('hidden')).toBeTruthy();
+ expect(
+ prometheusMetrics.$monitoredCustomMetricsNoIntegrationText.hasClass('hidden'),
+ ).toBeTruthy();
+
+ expect(prometheusMetrics.$newCustomMetricButton.hasClass('hidden')).toBeTruthy();
+ expect(prometheusMetrics.$newCustomMetricText.hasClass('hidden')).toBeTruthy();
+ });
+
+ it('should show metrics list when called with `list`', () => {
+ prometheusMetrics.showMonitoringCustomMetricsPanelState(PANEL_STATE.LIST);
+
+ expect(prometheusMetrics.$monitoredCustomMetricsLoading.hasClass('hidden')).toBeTruthy();
+ expect(prometheusMetrics.$monitoredCustomMetricsEmpty.hasClass('hidden')).toBeTruthy();
+ expect(prometheusMetrics.$monitoredCustomMetricsList.hasClass('hidden')).toEqual(false);
+ expect(
+ prometheusMetrics.$monitoredCustomMetricsNoIntegrationText.hasClass('hidden'),
+ ).toBeTruthy();
+
+ expect(prometheusMetrics.$newCustomMetricButton.hasClass('hidden')).toEqual(false);
+ expect(prometheusMetrics.$newCustomMetricText.hasClass('hidden')).toBeTruthy();
+ });
+
+ it('should show empty state when called with `empty`', () => {
+ prometheusMetrics.showMonitoringCustomMetricsPanelState(PANEL_STATE.EMPTY);
+
+ expect(prometheusMetrics.$monitoredCustomMetricsLoading.hasClass('hidden')).toBeTruthy();
+ expect(prometheusMetrics.$monitoredCustomMetricsEmpty.hasClass('hidden')).toEqual(false);
+ expect(prometheusMetrics.$monitoredCustomMetricsList.hasClass('hidden')).toBeTruthy();
+ expect(
+ prometheusMetrics.$monitoredCustomMetricsNoIntegrationText.hasClass('hidden'),
+ ).toBeTruthy();
+
+ expect(prometheusMetrics.$newCustomMetricButton.hasClass('hidden')).toEqual(false);
+ expect(prometheusMetrics.$newCustomMetricText.hasClass('hidden')).toEqual(false);
+ });
+
+ it('should show monitored metrics list', () => {
+ prometheusMetrics.customMetrics = metrics;
+ prometheusMetrics.populateCustomMetrics();
+
+ const $metricsListLi = prometheusMetrics.$monitoredCustomMetricsList.find('li');
+
+ expect(prometheusMetrics.$monitoredCustomMetricsLoading.hasClass('hidden')).toBeTruthy();
+ expect(prometheusMetrics.$monitoredCustomMetricsList.hasClass('hidden')).toEqual(false);
+ expect(
+ prometheusMetrics.$monitoredCustomMetricsNoIntegrationText.hasClass('hidden'),
+ ).toBeTruthy();
+
+ expect(prometheusMetrics.$newCustomMetricButton.hasClass('hidden')).toEqual(false);
+ expect(prometheusMetrics.$newCustomMetricText.hasClass('hidden')).toBeTruthy();
+
+ expect($metricsListLi.length).toEqual(metrics.length);
+ });
+
+ it('should show the NO-INTEGRATION empty state', () => {
+ prometheusMetrics.setNoIntegrationActiveState();
+
+ expect(prometheusMetrics.$monitoredCustomMetricsEmpty.hasClass('hidden')).toEqual(false);
+ expect(prometheusMetrics.$monitoredCustomMetricsNoIntegrationText.hasClass('hidden')).toEqual(
+ false,
+ );
+
+ expect(prometheusMetrics.$monitoredCustomMetricsLoading.hasClass('hidden')).toBeTruthy();
+ expect(prometheusMetrics.$monitoredCustomMetricsList.hasClass('hidden')).toBeTruthy();
+ expect(prometheusMetrics.$newCustomMetricButton.hasClass('hidden')).toBeTruthy();
+ expect(prometheusMetrics.$newCustomMetricText.hasClass('hidden')).toBeTruthy();
+ });
+ });
+});
diff --git a/spec/frontend/prometheus_metrics/mock_data.js b/spec/frontend/prometheus_metrics/mock_data.js
new file mode 100644
index 00000000000..d5532537302
--- /dev/null
+++ b/spec/frontend/prometheus_metrics/mock_data.js
@@ -0,0 +1,22 @@
+const metrics = [
+ {
+ edit_path: '/root/prometheus-test/prometheus/metrics/3/edit',
+ id: 3,
+ title: 'Requests',
+ group: 'Business',
+ },
+ {
+ edit_path: '/root/prometheus-test/prometheus/metrics/2/edit',
+ id: 2,
+ title: 'Sales by the hour',
+ group: 'Business',
+ },
+ {
+ edit_path: '/root/prometheus-test/prometheus/metrics/1/edit',
+ id: 1,
+ title: 'Requests',
+ group: 'Business',
+ },
+];
+
+export default metrics;
diff --git a/spec/helpers/clusters_helper_spec.rb b/spec/helpers/clusters_helper_spec.rb
index 5651b899ed0..eec62bbb990 100644
--- a/spec/helpers/clusters_helper_spec.rb
+++ b/spec/helpers/clusters_helper_spec.rb
@@ -58,4 +58,39 @@ describe ClustersHelper do
it { is_expected.to eq('Create new cluster') }
end
end
+
+ describe '#cluster_type_label' do
+ subject { helper.cluster_type_label(cluster_type) }
+
+ context 'project cluster' do
+ let(:cluster_type) { 'project_type' }
+
+ it { is_expected.to eq('Project cluster') }
+ end
+
+ context 'group cluster' do
+ let(:cluster_type) { 'group_type' }
+
+ it { is_expected.to eq('Group cluster') }
+ end
+
+ context 'instance cluster' do
+ let(:cluster_type) { 'instance_type' }
+
+ it { is_expected.to eq('Instance cluster') }
+ end
+
+ context 'other values' do
+ let(:cluster_type) { 'not_supported' }
+
+ it 'Diplays generic cluster and reports error' do
+ expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception).with(
+ an_instance_of(ArgumentError),
+ cluster_error: { error: 'Cluster Type Missing', cluster_type: 'not_supported' }
+ )
+
+ is_expected.to eq('Cluster')
+ end
+ end
+ end
end
diff --git a/spec/lib/gitlab/metrics/dashboard/stages/panel_ids_inserter_spec.rb b/spec/lib/gitlab/metrics/dashboard/stages/panel_ids_inserter_spec.rb
new file mode 100644
index 00000000000..426a54bea78
--- /dev/null
+++ b/spec/lib/gitlab/metrics/dashboard/stages/panel_ids_inserter_spec.rb
@@ -0,0 +1,67 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::Metrics::Dashboard::Stages::PanelIdsInserter do
+ let(:project) { build_stubbed(:project) }
+
+ def fetch_panel_ids(dashboard_hash)
+ dashboard_hash[:panel_groups].flat_map { |group| group[:panels].flat_map { |panel| panel[:id] } }
+ end
+
+ describe '#transform!' do
+ subject(:transform!) { described_class.new(project, dashboard, nil).transform! }
+
+ let(:dashboard) { YAML.safe_load(fixture_file('lib/gitlab/metrics/dashboard/sample_dashboard.yml')).deep_symbolize_keys }
+
+ context 'when dashboard panels are present' do
+ it 'assigns unique ids to each panel using PerformanceMonitoring::PrometheusPanel', :aggregate_failures do
+ dashboard.fetch(:panel_groups).each do |group|
+ group.fetch(:panels).each do |panel|
+ panel_double = instance_double(::PerformanceMonitoring::PrometheusPanel)
+
+ expect(::PerformanceMonitoring::PrometheusPanel).to receive(:new).with(panel).and_return(panel_double)
+ expect(panel_double).to receive(:id).with(group[:group]).and_return(FFaker::Lorem.unique.characters(125))
+ end
+ end
+
+ transform!
+
+ expect(fetch_panel_ids(dashboard)).not_to include nil
+ end
+ end
+
+ context 'when dashboard panels has duplicated ids' do
+ it 'no panel has assigned id' do
+ panel_double = instance_double(::PerformanceMonitoring::PrometheusPanel)
+ allow(::PerformanceMonitoring::PrometheusPanel).to receive(:new).and_return(panel_double)
+ allow(panel_double).to receive(:id).and_return('duplicated id')
+
+ transform!
+
+ expect(fetch_panel_ids(dashboard)).to all be_nil
+ expect(fetch_panel_ids(dashboard)).not_to include 'duplicated id'
+ end
+ end
+
+ context 'when there are no panels in the dashboard' do
+ it 'raises a processing error' do
+ dashboard[:panel_groups][0].delete(:panels)
+
+ expect { transform! }.to(
+ raise_error(::Gitlab::Metrics::Dashboard::Errors::DashboardProcessingError)
+ )
+ end
+ end
+
+ context 'when there are no panel_groups in the dashboard' do
+ it 'raises a processing error' do
+ dashboard.delete(:panel_groups)
+
+ expect { transform! }.to(
+ raise_error(::Gitlab::Metrics::Dashboard::Errors::DashboardProcessingError)
+ )
+ end
+ end
+ end
+end
diff --git a/spec/requests/api/releases_spec.rb b/spec/requests/api/releases_spec.rb
index 0589554bf44..237782a681c 100644
--- a/spec/requests/api/releases_spec.rb
+++ b/spec/requests/api/releases_spec.rb
@@ -702,10 +702,10 @@ describe API::Releases do
context 'when tag name is HEAD' do
let(:tag_name) { 'HEAD' }
- it 'returns an error as failure on tag creation' do
+ it 'returns a 400 error as failure on tag creation' do
post api("/projects/#{project.id}/releases", maintainer), params: params
- expect(response).to have_gitlab_http_status(:internal_server_error)
+ expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']).to eq('Tag name invalid')
end
end
@@ -713,10 +713,10 @@ describe API::Releases do
context 'when tag name is empty' do
let(:tag_name) { '' }
- it 'returns an error as failure on tag creation' do
+ it 'returns a 400 error as failure on tag creation' do
post api("/projects/#{project.id}/releases", maintainer), params: params
- expect(response).to have_gitlab_http_status(:internal_server_error)
+ expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']).to eq('Tag name invalid')
end
end
diff --git a/spec/services/tags/create_service_spec.rb b/spec/services/tags/create_service_spec.rb
index ee558f90d6f..e505960d3c7 100644
--- a/spec/services/tags/create_service_spec.rb
+++ b/spec/services/tags/create_service_spec.rb
@@ -21,8 +21,9 @@ describe Tags::CreateService do
it 'returns an error' do
response = service.execute('v1.1.0', 'foo', 'Foo')
- expect(response).to eq(status: :error,
- message: 'Target foo is invalid')
+ expect(response[:status]).to eq(:error)
+ expect(response[:http_status]).to eq(400)
+ expect(response[:message]).to eq('Target foo is invalid')
end
end
@@ -34,8 +35,19 @@ describe Tags::CreateService do
response = service.execute('v1.1.0', 'master', 'Foo')
- expect(response).to eq(status: :error,
- message: 'Tag v1.1.0 already exists')
+ expect(response[:status]).to eq(:error)
+ expect(response[:http_status]).to eq(409)
+ expect(response[:message]).to eq('Tag v1.1.0 already exists')
+ end
+ end
+
+ context 'when tag name is invalid' do
+ it 'returns an error' do
+ response = service.execute('HEAD', 'master', 'Foo')
+
+ expect(response[:status]).to eq(:error)
+ expect(response[:http_status]).to eq(400)
+ expect(response[:message]).to eq('Tag name invalid')
end
end
@@ -47,8 +59,8 @@ describe Tags::CreateService do
response = service.execute('v1.1.0', 'master', 'Foo')
- expect(response).to eq(status: :error,
- message: 'something went wrong')
+ expect(response[:status]).to eq(:error)
+ expect(response[:message]).to eq('something went wrong')
end
end
end