Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-14 15:07:41 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-14 15:07:41 +0300
commit4ce0bee95df15c05cdb0d777eba31fe753bc443b (patch)
tree3dc6a1aae7e0a01280f6d9f7d774dd369f7863e1 /spec/frontend
parent02ab65d49fc94be7c91e511899762236c122977d (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend')
-rw-r--r--spec/frontend/error_tracking/components/error_details_spec.js54
-rw-r--r--spec/frontend/helpers/diffs_helper_spec.js113
-rw-r--r--spec/frontend/monitoring/components/dashboard_spec.js2
-rw-r--r--spec/frontend/monitoring/mock_data.js141
-rw-r--r--spec/frontend/monitoring/store/actions_spec.js4
-rw-r--r--spec/frontend/monitoring/store/mutations_spec.js8
6 files changed, 232 insertions, 90 deletions
diff --git a/spec/frontend/error_tracking/components/error_details_spec.js b/spec/frontend/error_tracking/components/error_details_spec.js
index eefaff4aba7..b5ce9383eb9 100644
--- a/spec/frontend/error_tracking/components/error_details_spec.js
+++ b/spec/frontend/error_tracking/components/error_details_spec.js
@@ -13,6 +13,7 @@ describe('ErrorDetails', () => {
let wrapper;
let actions;
let getters;
+ let mocks;
const findInput = name => {
const inputs = wrapper.findAll(GlFormInput).filter(c => c.attributes('name') === name);
@@ -24,13 +25,27 @@ describe('ErrorDetails', () => {
stubs: { LoadingButton },
localVue,
store,
+ mocks,
propsData: {
+ issueId: '123',
+ projectPath: '/root/gitlab-test',
issueDetailsPath: '/123/details',
issueStackTracePath: '/stacktrace',
projectIssuesPath: '/test-project/issues/',
csrfToken: 'fakeToken',
},
});
+ wrapper.setData({
+ GQLerror: {
+ id: 129381,
+ title: 'Issue title',
+ externalUrl: 'http://sentry.gitlab.net/gitlab',
+ firstSeen: '2017-05-26T13:32:48Z',
+ lastSeen: '2018-05-26T13:32:48Z',
+ count: 12,
+ userCount: 2,
+ },
+ });
}
beforeEach(() => {
@@ -61,6 +76,19 @@ describe('ErrorDetails', () => {
},
},
});
+
+ const query = jest.fn();
+ mocks = {
+ $apollo: {
+ query,
+ queries: {
+ GQLerror: {
+ loading: true,
+ stopPolling: jest.fn(),
+ },
+ },
+ },
+ };
});
afterEach(() => {
@@ -85,10 +113,11 @@ describe('ErrorDetails', () => {
beforeEach(() => {
store.state.details.loading = false;
store.state.details.error.id = 1;
+ mocks.$apollo.queries.GQLerror.loading = false;
+ mountComponent();
});
it('should show Sentry error details without stacktrace', () => {
- mountComponent();
expect(wrapper.find(GlLink).exists()).toBe(true);
expect(wrapper.find(GlLoadingIcon).exists()).toBe(true);
expect(wrapper.find(Stacktrace).exists()).toBe(false);
@@ -99,13 +128,17 @@ describe('ErrorDetails', () => {
it('should show language and error level badges', () => {
store.state.details.error.tags = { level: 'error', logger: 'ruby' };
mountComponent();
- expect(wrapper.findAll(GlBadge).length).toBe(2);
+ return wrapper.vm.$nextTick().then(() => {
+ expect(wrapper.findAll(GlBadge).length).toBe(2);
+ });
});
it('should NOT show the badge if the tag is not present', () => {
store.state.details.error.tags = { level: 'error' };
mountComponent();
- expect(wrapper.findAll(GlBadge).length).toBe(1);
+ return wrapper.vm.$nextTick().then(() => {
+ expect(wrapper.findAll(GlBadge).length).toBe(1);
+ });
});
});
@@ -113,8 +146,10 @@ describe('ErrorDetails', () => {
it('should show stacktrace', () => {
store.state.details.loadingStacktrace = false;
mountComponent();
- expect(wrapper.find(GlLoadingIcon).exists()).toBe(false);
- expect(wrapper.find(Stacktrace).exists()).toBe(true);
+ return wrapper.vm.$nextTick().then(() => {
+ expect(wrapper.find(GlLoadingIcon).exists()).toBe(false);
+ expect(wrapper.find(Stacktrace).exists()).toBe(true);
+ });
});
it('should NOT show stacktrace if no entries', () => {
@@ -128,15 +163,6 @@ describe('ErrorDetails', () => {
describe('When a user clicks the create issue button', () => {
beforeEach(() => {
- store.state.details.error = {
- id: 129381,
- title: 'Issue title',
- external_url: 'http://sentry.gitlab.net/gitlab',
- first_seen: '2017-05-26T13:32:48Z',
- last_seen: '2018-05-26T13:32:48Z',
- count: 12,
- user_count: 2,
- };
mountComponent();
});
diff --git a/spec/frontend/helpers/diffs_helper_spec.js b/spec/frontend/helpers/diffs_helper_spec.js
new file mode 100644
index 00000000000..b223d48bf5c
--- /dev/null
+++ b/spec/frontend/helpers/diffs_helper_spec.js
@@ -0,0 +1,113 @@
+import * as diffsHelper from '~/helpers/diffs_helper';
+
+describe('diffs helper', () => {
+ function getDiffFile(withOverrides = {}) {
+ return {
+ parallel_diff_lines: ['line'],
+ highlighted_diff_lines: ['line'],
+ blob: {
+ readable_text: 'text',
+ },
+ ...withOverrides,
+ };
+ }
+
+ describe('hasInlineLines', () => {
+ it('is false when the file does not exist', () => {
+ expect(diffsHelper.hasInlineLines()).toBeFalsy();
+ });
+
+ it('is false when the file does not have the highlighted_diff_lines property', () => {
+ const missingInline = getDiffFile({ highlighted_diff_lines: undefined });
+
+ expect(diffsHelper.hasInlineLines(missingInline)).toBeFalsy();
+ });
+
+ it('is false when the file has zero highlighted_diff_lines', () => {
+ const emptyInline = getDiffFile({ highlighted_diff_lines: [] });
+
+ expect(diffsHelper.hasInlineLines(emptyInline)).toBeFalsy();
+ });
+
+ it('is true when the file has at least 1 highlighted_diff_lines', () => {
+ expect(diffsHelper.hasInlineLines(getDiffFile())).toBeTruthy();
+ });
+ });
+
+ describe('hasParallelLines', () => {
+ it('is false when the file does not exist', () => {
+ expect(diffsHelper.hasParallelLines()).toBeFalsy();
+ });
+
+ it('is false when the file does not have the parallel_diff_lines property', () => {
+ const missingInline = getDiffFile({ parallel_diff_lines: undefined });
+
+ expect(diffsHelper.hasParallelLines(missingInline)).toBeFalsy();
+ });
+
+ it('is false when the file has zero parallel_diff_lines', () => {
+ const emptyInline = getDiffFile({ parallel_diff_lines: [] });
+
+ expect(diffsHelper.hasParallelLines(emptyInline)).toBeFalsy();
+ });
+
+ it('is true when the file has at least 1 parallel_diff_lines', () => {
+ expect(diffsHelper.hasParallelLines(getDiffFile())).toBeTruthy();
+ });
+ });
+
+ describe('isSingleViewStyle', () => {
+ it('is true when the file has at least 1 inline line but no parallel lines for any reason', () => {
+ const noParallelLines = getDiffFile({ parallel_diff_lines: undefined });
+ const emptyParallelLines = getDiffFile({ parallel_diff_lines: [] });
+
+ expect(diffsHelper.isSingleViewStyle(noParallelLines)).toBeTruthy();
+ expect(diffsHelper.isSingleViewStyle(emptyParallelLines)).toBeTruthy();
+ });
+
+ it('is true when the file has at least 1 parallel line but no inline lines for any reason', () => {
+ const noInlineLines = getDiffFile({ highlighted_diff_lines: undefined });
+ const emptyInlineLines = getDiffFile({ highlighted_diff_lines: [] });
+
+ expect(diffsHelper.isSingleViewStyle(noInlineLines)).toBeTruthy();
+ expect(diffsHelper.isSingleViewStyle(emptyInlineLines)).toBeTruthy();
+ });
+
+ it('is true when the file does not have any inline lines or parallel lines for any reason', () => {
+ const noLines = getDiffFile({
+ highlighted_diff_lines: undefined,
+ parallel_diff_lines: undefined,
+ });
+ const emptyLines = getDiffFile({
+ highlighted_diff_lines: [],
+ parallel_diff_lines: [],
+ });
+
+ expect(diffsHelper.isSingleViewStyle(noLines)).toBeTruthy();
+ expect(diffsHelper.isSingleViewStyle(emptyLines)).toBeTruthy();
+ expect(diffsHelper.isSingleViewStyle()).toBeTruthy();
+ });
+
+ it('is false when the file has both inline and parallel lines', () => {
+ expect(diffsHelper.isSingleViewStyle(getDiffFile())).toBeFalsy();
+ });
+ });
+
+ describe.each`
+ context | inline | parallel | blob | expected
+ ${'only has inline lines'} | ${['line']} | ${undefined} | ${undefined} | ${true}
+ ${'only has parallel lines'} | ${undefined} | ${['line']} | ${undefined} | ${true}
+ ${"doesn't have inline, parallel, or blob"} | ${undefined} | ${undefined} | ${undefined} | ${true}
+ ${'has blob readable text'} | ${undefined} | ${undefined} | ${{ readable_text: 'text' }} | ${false}
+ `('when hasDiff', ({ context, inline, parallel, blob, expected }) => {
+ it(`${context}`, () => {
+ const diffFile = getDiffFile({
+ highlighted_diff_lines: inline,
+ parallel_diff_lines: parallel,
+ blob,
+ });
+
+ expect(diffsHelper.hasDiff(diffFile)).toEqual(expected);
+ });
+ });
+});
diff --git a/spec/frontend/monitoring/components/dashboard_spec.js b/spec/frontend/monitoring/components/dashboard_spec.js
index 4caa66cf600..efae8b941ee 100644
--- a/spec/frontend/monitoring/components/dashboard_spec.js
+++ b/spec/frontend/monitoring/components/dashboard_spec.js
@@ -345,7 +345,7 @@ describe('Dashboard', () => {
it('metrics can be swapped', done => {
const firstDraggable = findDraggables().at(0);
- const mockMetrics = [...metricsGroupsAPIResponse[1].panels];
+ const mockMetrics = [...metricsGroupsAPIResponse.panel_groups[1].panels];
const firstTitle = mockMetrics[0].title;
const secondTitle = mockMetrics[1].title;
diff --git a/spec/frontend/monitoring/mock_data.js b/spec/frontend/monitoring/mock_data.js
index 6ded22b4a3f..77c92d0eca6 100644
--- a/spec/frontend/monitoring/mock_data.js
+++ b/spec/frontend/monitoring/mock_data.js
@@ -331,77 +331,80 @@ export const mockedQueryResultPayloadCoresTotal = {
],
};
-export const metricsGroupsAPIResponse = [
- {
- group: 'Response metrics (NGINX Ingress VTS)',
- priority: 10,
- panels: [
- {
- metrics: [
- {
- id: 'response_metrics_nginx_ingress_throughput_status_code',
- label: 'Status Code',
- metric_id: 1,
- prometheus_endpoint_path:
- '/root/autodevops-deploy/environments/32/prometheus/api/v1/query_range?query=sum%28rate%28nginx_upstream_responses_total%7Bupstream%3D~%22%25%7Bkube_namespace%7D-%25%7Bci_environment_slug%7D-.%2A%22%7D%5B2m%5D%29%29+by+%28status_code%29',
- query_range:
- 'sum(rate(nginx_upstream_responses_total{upstream=~"%{kube_namespace}-%{ci_environment_slug}-.*"}[2m])) by (status_code)',
- unit: 'req / sec',
- },
- ],
- title: 'Throughput',
- type: 'area-chart',
- weight: 1,
- y_label: 'Requests / Sec',
- },
- ],
- },
- {
- group: 'System metrics (Kubernetes)',
- priority: 5,
- panels: [
- {
- title: 'Memory Usage (Pod average)',
- type: 'area-chart',
- y_label: 'Memory Used per Pod',
- weight: 2,
- metrics: [
- {
- id: 'system_metrics_kubernetes_container_memory_average',
- query_range:
- 'avg(sum(container_memory_usage_bytes{container_name!="POD",pod_name=~"^%{ci_environment_slug}-([^c].*|c([^a]|a([^n]|n([^a]|a([^r]|r[^y])))).*|)-(.*)",namespace="%{kube_namespace}"}) by (job)) without (job) / count(avg(container_memory_usage_bytes{container_name!="POD",pod_name=~"^%{ci_environment_slug}-([^c].*|c([^a]|a([^n]|n([^a]|a([^r]|r[^y])))).*|)-(.*)",namespace="%{kube_namespace}"}) without (job)) /1024/1024',
- label: 'Pod average',
- unit: 'MB',
- metric_id: 17,
- prometheus_endpoint_path:
- '/root/autodevops-deploy/environments/32/prometheus/api/v1/query_range?query=avg%28sum%28container_memory_usage_bytes%7Bcontainer_name%21%3D%22POD%22%2Cpod_name%3D~%22%5E%25%7Bci_environment_slug%7D-%28%5B%5Ec%5D.%2A%7Cc%28%5B%5Ea%5D%7Ca%28%5B%5En%5D%7Cn%28%5B%5Ea%5D%7Ca%28%5B%5Er%5D%7Cr%5B%5Ey%5D%29%29%29%29.%2A%7C%29-%28.%2A%29%22%2Cnamespace%3D%22%25%7Bkube_namespace%7D%22%7D%29+by+%28job%29%29+without+%28job%29+%2F+count%28avg%28container_memory_usage_bytes%7Bcontainer_name%21%3D%22POD%22%2Cpod_name%3D~%22%5E%25%7Bci_environment_slug%7D-%28%5B%5Ec%5D.%2A%7Cc%28%5B%5Ea%5D%7Ca%28%5B%5En%5D%7Cn%28%5B%5Ea%5D%7Ca%28%5B%5Er%5D%7Cr%5B%5Ey%5D%29%29%29%29.%2A%7C%29-%28.%2A%29%22%2Cnamespace%3D%22%25%7Bkube_namespace%7D%22%7D%29+without+%28job%29%29+%2F1024%2F1024',
- appearance: {
- line: {
- width: 2,
+export const metricsGroupsAPIResponse = {
+ dashboard: 'Environment metrics',
+ panel_groups: [
+ {
+ group: 'Response metrics (NGINX Ingress VTS)',
+ priority: 10,
+ panels: [
+ {
+ metrics: [
+ {
+ id: 'response_metrics_nginx_ingress_throughput_status_code',
+ label: 'Status Code',
+ metric_id: 1,
+ prometheus_endpoint_path:
+ '/root/autodevops-deploy/environments/32/prometheus/api/v1/query_range?query=sum%28rate%28nginx_upstream_responses_total%7Bupstream%3D~%22%25%7Bkube_namespace%7D-%25%7Bci_environment_slug%7D-.%2A%22%7D%5B2m%5D%29%29+by+%28status_code%29',
+ query_range:
+ 'sum(rate(nginx_upstream_responses_total{upstream=~"%{kube_namespace}-%{ci_environment_slug}-.*"}[2m])) by (status_code)',
+ unit: 'req / sec',
+ },
+ ],
+ title: 'Throughput',
+ type: 'area-chart',
+ weight: 1,
+ y_label: 'Requests / Sec',
+ },
+ ],
+ },
+ {
+ group: 'System metrics (Kubernetes)',
+ priority: 5,
+ panels: [
+ {
+ title: 'Memory Usage (Pod average)',
+ type: 'area-chart',
+ y_label: 'Memory Used per Pod',
+ weight: 2,
+ metrics: [
+ {
+ id: 'system_metrics_kubernetes_container_memory_average',
+ query_range:
+ 'avg(sum(container_memory_usage_bytes{container_name!="POD",pod_name=~"^%{ci_environment_slug}-([^c].*|c([^a]|a([^n]|n([^a]|a([^r]|r[^y])))).*|)-(.*)",namespace="%{kube_namespace}"}) by (job)) without (job) / count(avg(container_memory_usage_bytes{container_name!="POD",pod_name=~"^%{ci_environment_slug}-([^c].*|c([^a]|a([^n]|n([^a]|a([^r]|r[^y])))).*|)-(.*)",namespace="%{kube_namespace}"}) without (job)) /1024/1024',
+ label: 'Pod average',
+ unit: 'MB',
+ metric_id: 17,
+ prometheus_endpoint_path:
+ '/root/autodevops-deploy/environments/32/prometheus/api/v1/query_range?query=avg%28sum%28container_memory_usage_bytes%7Bcontainer_name%21%3D%22POD%22%2Cpod_name%3D~%22%5E%25%7Bci_environment_slug%7D-%28%5B%5Ec%5D.%2A%7Cc%28%5B%5Ea%5D%7Ca%28%5B%5En%5D%7Cn%28%5B%5Ea%5D%7Ca%28%5B%5Er%5D%7Cr%5B%5Ey%5D%29%29%29%29.%2A%7C%29-%28.%2A%29%22%2Cnamespace%3D%22%25%7Bkube_namespace%7D%22%7D%29+by+%28job%29%29+without+%28job%29+%2F+count%28avg%28container_memory_usage_bytes%7Bcontainer_name%21%3D%22POD%22%2Cpod_name%3D~%22%5E%25%7Bci_environment_slug%7D-%28%5B%5Ec%5D.%2A%7Cc%28%5B%5Ea%5D%7Ca%28%5B%5En%5D%7Cn%28%5B%5Ea%5D%7Ca%28%5B%5Er%5D%7Cr%5B%5Ey%5D%29%29%29%29.%2A%7C%29-%28.%2A%29%22%2Cnamespace%3D%22%25%7Bkube_namespace%7D%22%7D%29+without+%28job%29%29+%2F1024%2F1024',
+ appearance: {
+ line: {
+ width: 2,
+ },
},
},
- },
- ],
- },
- {
- title: 'Core Usage (Total)',
- type: 'area-chart',
- y_label: 'Total Cores',
- weight: 3,
- metrics: [
- {
- id: 'system_metrics_kubernetes_container_cores_total',
- query_range:
- 'avg(sum(rate(container_cpu_usage_seconds_total{container_name!="POD",pod_name=~"^%{ci_environment_slug}-(.*)",namespace="%{kube_namespace}"}[15m])) by (job)) without (job)',
- label: 'Total',
- unit: 'cores',
- metric_id: 13,
- },
- ],
- },
- ],
- },
-];
+ ],
+ },
+ {
+ title: 'Core Usage (Total)',
+ type: 'area-chart',
+ y_label: 'Total Cores',
+ weight: 3,
+ metrics: [
+ {
+ id: 'system_metrics_kubernetes_container_cores_total',
+ query_range:
+ 'avg(sum(rate(container_cpu_usage_seconds_total{container_name!="POD",pod_name=~"^%{ci_environment_slug}-(.*)",namespace="%{kube_namespace}"}[15m])) by (job)) without (job)',
+ label: 'Total',
+ unit: 'cores',
+ metric_id: 13,
+ },
+ ],
+ },
+ ],
+ },
+ ],
+};
export const environmentData = [
{
diff --git a/spec/frontend/monitoring/store/actions_spec.js b/spec/frontend/monitoring/store/actions_spec.js
index f38bd4384e2..c1ad59ac95b 100644
--- a/spec/frontend/monitoring/store/actions_spec.js
+++ b/spec/frontend/monitoring/store/actions_spec.js
@@ -298,7 +298,7 @@ describe('Monitoring store actions', () => {
);
expect(commit).toHaveBeenCalledWith(
types.RECEIVE_METRICS_DATA_SUCCESS,
- metricsDashboardResponse.dashboard.panel_groups,
+ metricsDashboardResponse.dashboard,
);
expect(dispatch).toHaveBeenCalledWith('fetchPrometheusMetrics', params);
});
@@ -441,7 +441,7 @@ describe('Monitoring store actions', () => {
beforeEach(() => {
state = storeState();
[metric] = metricsDashboardResponse.dashboard.panel_groups[0].panels[0].metrics;
- [data] = metricsGroupsAPIResponse[0].panels[0].metrics;
+ [data] = metricsGroupsAPIResponse.panel_groups[0].panels[0].metrics;
});
it('commits result', done => {
diff --git a/spec/frontend/monitoring/store/mutations_spec.js b/spec/frontend/monitoring/store/mutations_spec.js
index 60107a03674..e89c22268d4 100644
--- a/spec/frontend/monitoring/store/mutations_spec.js
+++ b/spec/frontend/monitoring/store/mutations_spec.js
@@ -100,12 +100,12 @@ describe('Monitoring mutations', () => {
values: [[0, 1], [1, 1], [1, 3]],
},
];
- const dashboardGroups = metricsDashboardResponse.dashboard.panel_groups;
+ const { dashboard } = metricsDashboardResponse;
const getMetric = () => stateCopy.dashboard.panel_groups[0].panels[0].metrics[0];
describe('REQUEST_METRIC_RESULT', () => {
beforeEach(() => {
- mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, dashboardGroups);
+ mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, dashboard);
});
it('stores a loading state on a metric', () => {
expect(stateCopy.showEmptyState).toBe(true);
@@ -128,7 +128,7 @@ describe('Monitoring mutations', () => {
describe('RECEIVE_METRIC_RESULT_SUCCESS', () => {
beforeEach(() => {
- mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, dashboardGroups);
+ mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, dashboard);
});
it('clears empty state', () => {
expect(stateCopy.showEmptyState).toBe(true);
@@ -161,7 +161,7 @@ describe('Monitoring mutations', () => {
describe('RECEIVE_METRIC_RESULT_FAILURE', () => {
beforeEach(() => {
- mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, dashboardGroups);
+ mutations[types.RECEIVE_METRICS_DATA_SUCCESS](stateCopy, dashboard);
});
it('maintains the loading state when a metric fails', () => {
expect(stateCopy.showEmptyState).toBe(true);