Commit ea48c52f authored by Vitaly Slobodin's avatar Vitaly Slobodin

Merge branch '241474-remove-unused-files' into 'master'

Remove components that are not used anymore

See merge request gitlab-org/gitlab!46892
parents 7b3f3de2 a378627e
...@@ -6,8 +6,6 @@ import Filters from './filters.vue'; ...@@ -6,8 +6,6 @@ import Filters from './filters.vue';
import SecurityDashboardLayout from './security_dashboard_layout.vue'; import SecurityDashboardLayout from './security_dashboard_layout.vue';
import SecurityDashboardTable from './security_dashboard_table.vue'; import SecurityDashboardTable from './security_dashboard_table.vue';
import VulnerabilityChart from './vulnerability_chart.vue'; import VulnerabilityChart from './vulnerability_chart.vue';
import VulnerabilityCountList from './vulnerability_count_list_vuex.vue';
import VulnerabilitySeverity from './vulnerability_severity.vue';
import FuzzingArtifactsDownload from './fuzzing_artifacts_download.vue'; import FuzzingArtifactsDownload from './fuzzing_artifacts_download.vue';
import LoadingError from './loading_error.vue'; import LoadingError from './loading_error.vue';
...@@ -18,8 +16,6 @@ export default { ...@@ -18,8 +16,6 @@ export default {
SecurityDashboardLayout, SecurityDashboardLayout,
SecurityDashboardTable, SecurityDashboardTable,
VulnerabilityChart, VulnerabilityChart,
VulnerabilityCountList,
VulnerabilitySeverity,
FuzzingArtifactsDownload, FuzzingArtifactsDownload,
LoadingError, LoadingError,
}, },
...@@ -28,21 +24,11 @@ export default { ...@@ -28,21 +24,11 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
vulnerabilitiesCountEndpoint: {
type: String,
required: false,
default: '',
},
vulnerabilitiesHistoryEndpoint: { vulnerabilitiesHistoryEndpoint: {
type: String, type: String,
required: false, required: false,
default: '', default: '',
}, },
vulnerableProjectsEndpoint: {
type: String,
required: false,
default: '',
},
lockToProject: { lockToProject: {
type: Object, type: Object,
required: false, required: false,
...@@ -92,20 +78,11 @@ export default { ...@@ -92,20 +78,11 @@ export default {
return this.lockToProject !== null; return this.lockToProject !== null;
}, },
shouldShowAside() { shouldShowAside() {
return this.shouldShowChart || this.shouldShowVulnerabilitySeverities; return this.shouldShowChart;
}, },
shouldShowChart() { shouldShowChart() {
return Boolean(this.vulnerabilitiesHistoryEndpoint); return Boolean(this.vulnerabilitiesHistoryEndpoint);
}, },
shouldShowVulnerabilitySeverities() {
return Boolean(this.vulnerableProjectsEndpoint);
},
shouldShowCountList() {
return this.isLockedToProject && Boolean(this.vulnerabilitiesCountEndpoint);
},
},
watch: {
'pageInfo.total': 'emitVulnerabilitiesCountChanged',
}, },
created() { created() {
if (this.isLockedToProject) { if (this.isLockedToProject) {
...@@ -117,10 +94,8 @@ export default { ...@@ -117,10 +94,8 @@ export default {
this.setPipelineId(this.pipelineId); this.setPipelineId(this.pipelineId);
this.setHideDismissedToggleInitialState(); this.setHideDismissedToggleInitialState();
this.setVulnerabilitiesEndpoint(this.vulnerabilitiesEndpoint); this.setVulnerabilitiesEndpoint(this.vulnerabilitiesEndpoint);
this.setVulnerabilitiesCountEndpoint(this.vulnerabilitiesCountEndpoint);
this.setVulnerabilitiesHistoryEndpoint(this.vulnerabilitiesHistoryEndpoint); this.setVulnerabilitiesHistoryEndpoint(this.vulnerabilitiesHistoryEndpoint);
this.fetchVulnerabilities({ ...this.activeFilters, page: this.pageInfo.page }); this.fetchVulnerabilities({ ...this.activeFilters, page: this.pageInfo.page });
this.fetchVulnerabilitiesCount(this.activeFilters);
this.fetchVulnerabilitiesHistory(this.activeFilters); this.fetchVulnerabilitiesHistory(this.activeFilters);
this.fetchPipelineJobs(); this.fetchPipelineJobs();
}, },
...@@ -133,11 +108,9 @@ export default { ...@@ -133,11 +108,9 @@ export default {
'createMergeRequest', 'createMergeRequest',
'dismissVulnerability', 'dismissVulnerability',
'fetchVulnerabilities', 'fetchVulnerabilities',
'fetchVulnerabilitiesCount',
'fetchVulnerabilitiesHistory', 'fetchVulnerabilitiesHistory',
'openDismissalCommentBox', 'openDismissalCommentBox',
'setPipelineId', 'setPipelineId',
'setVulnerabilitiesCountEndpoint',
'setVulnerabilitiesEndpoint', 'setVulnerabilitiesEndpoint',
'setVulnerabilitiesHistoryEndpoint', 'setVulnerabilitiesHistoryEndpoint',
'showDismissalDeleteButtons', 'showDismissalDeleteButtons',
...@@ -147,9 +120,6 @@ export default { ...@@ -147,9 +120,6 @@ export default {
]), ]),
...mapActions('pipelineJobs', ['fetchPipelineJobs']), ...mapActions('pipelineJobs', ['fetchPipelineJobs']),
...mapActions('filters', ['lockFilter', 'setHideDismissedToggleInitialState']), ...mapActions('filters', ['lockFilter', 'setHideDismissedToggleInitialState']),
emitVulnerabilitiesCountChanged(count) {
this.$emit('vulnerabilitiesCountChanged', count);
},
}, },
}; };
</script> </script>
...@@ -164,7 +134,6 @@ export default { ...@@ -164,7 +134,6 @@ export default {
<template v-else> <template v-else>
<security-dashboard-layout> <security-dashboard-layout>
<template #header> <template #header>
<vulnerability-count-list v-if="shouldShowCountList" />
<filters> <filters>
<template v-if="hasFuzzingArtifacts" #buttons> <template v-if="hasFuzzingArtifacts" #buttons>
<fuzzing-artifacts-download :jobs="fuzzingJobsWithArtifact" :project-id="projectId"> <fuzzing-artifacts-download :jobs="fuzzingJobsWithArtifact" :project-id="projectId">
...@@ -184,10 +153,6 @@ export default { ...@@ -184,10 +153,6 @@ export default {
<template v-if="shouldShowAside" #aside> <template v-if="shouldShowAside" #aside>
<vulnerability-chart v-if="shouldShowChart" class="mb-3" /> <vulnerability-chart v-if="shouldShowChart" class="mb-3" />
<vulnerability-severity
v-if="shouldShowVulnerabilitySeverities"
:endpoint="vulnerableProjectsEndpoint"
/>
</template> </template>
</security-dashboard-layout> </security-dashboard-layout>
......
<script>
import { mapGetters, mapState } from 'vuex';
import VulnerabilityCountListLayout from './vulnerability_count_list_layout.vue';
export default {
components: {
VulnerabilityCountListLayout,
},
computed: {
...mapGetters('vulnerabilities', ['dashboardCountError']),
...mapState('vulnerabilities', ['isLoadingVulnerabilitiesCount', 'vulnerabilitiesCount']),
},
};
</script>
<template>
<vulnerability-count-list-layout
:show-error="dashboardCountError"
:is-loading="isLoadingVulnerabilitiesCount"
:vulnerabilities-count="vulnerabilitiesCount"
/>
</template>
<script>
import {
severityGroupTypes,
severityLevels,
severityLevelsTranslations,
} from 'ee/security_dashboard/store/modules/vulnerable_projects/constants';
import { mapActions, mapGetters, mapState } from 'vuex';
import { GlLink, GlTooltipDirective, GlIcon } from '@gitlab/ui';
import { Accordion, AccordionItem } from 'ee/vue_shared/components/accordion';
export default {
css: {
severityGroups: {
[severityGroupTypes.F]: 'gl-text-red-900',
[severityGroupTypes.D]: 'gl-text-red-700',
[severityGroupTypes.C]: 'gl-text-orange-600',
[severityGroupTypes.B]: 'gl-text-orange-400',
[severityGroupTypes.A]: 'gl-text-green-500',
},
severityLevels: {
[severityLevels.CRITICAL]: 'gl-text-red-900',
[severityLevels.HIGH]: 'gl-text-red-700',
[severityLevels.UNKNOWN]: 'gl-text-gray-300',
[severityLevels.MEDIUM]: 'gl-text-orange-600',
[severityLevels.LOW]: 'gl-text-orange-500',
[severityLevels.NONE]: 'gl-text-green-500',
},
},
accordionItemsContentMaxHeight: '445px',
components: { Accordion, AccordionItem, GlLink, GlIcon },
directives: {
'gl-tooltip': GlTooltipDirective,
},
props: {
endpoint: {
type: String,
required: true,
},
helpPagePath: {
type: String,
required: false,
default: '',
},
},
computed: {
...mapState('vulnerableProjects', ['isLoading']),
...mapGetters('vulnerableProjects', ['severityGroups']),
},
created() {
this.fetchProjects(this.endpoint);
},
methods: {
...mapActions('vulnerableProjects', ['fetchProjects']),
shouldAccordionItemBeDisabled({ projects }) {
return projects && projects.length < 1;
},
cssForSeverityGroup({ type }) {
return this.$options.css.severityGroups[type];
},
cssForMostSevereVulnerability({ level }) {
return this.$options.css.severityLevels[level] || [];
},
severityText(severityLevel) {
return severityLevelsTranslations[severityLevel];
},
},
};
</script>
<template>
<section
class="gl-border-1 gl-border-solid gl-border-gray-100 gl-rounded-base gl-display-flex gl-flex-direction-column"
>
<header class="gl-border-b-gray-100 gl-border-b-solid gl-border-b-1 gl-p-5">
<h4 class="gl-my-0">
{{ __('Project security status') }}
<gl-link
v-if="helpPagePath"
:href="helpPagePath"
:aria-label="__('Project security status help page')"
target="_blank"
><gl-icon name="question"
/></gl-link>
</h4>
<p class="text-secondary gl-m-0">
{{ __('Projects are graded based on the highest severity vulnerability present') }}
</p>
</header>
<accordion class="security-dashboard-accordion gl-px-5 gl-display-flex gl-flex-fill-1">
<template #default="{ accordionId }">
<accordion-item
v-for="severityGroup in severityGroups"
:ref="`accordionItem${severityGroup.type}`"
:key="severityGroup.type"
:data-qa-selector="`severity_accordion_item_${severityGroup.type}`"
:accordion-id="accordionId"
:is-loading="isLoading"
:disabled="shouldAccordionItemBeDisabled(severityGroup)"
:max-height="$options.accordionItemsContentMaxHeight"
class="gl-display-flex gl-flex-fill-1 gl-flex-direction-column gl-justify-content-center"
>
<template #title="{ isExpanded, isDisabled }">
<h5 class="gl-display-flex gl-align-items-center gl-font-weight-normal gl-p-0 gl-m-0">
<span
v-gl-tooltip
:title="severityGroup.description"
class="gl-font-weight-bold gl-mr-5 gl-font-lg"
:class="cssForSeverityGroup(severityGroup)"
>
{{ severityGroup.type }}
</span>
<span :class="{ 'gl-font-weight-bold': isExpanded, 'text-secondary': isDisabled }">
{{ n__('%d project', '%d projects', severityGroup.projects.length) }}
</span>
</h5>
</template>
<template #subTitle>
<p class="gl-m-0 gl-ml-7 gl-pb-2 text-secondary">{{ severityGroup.warning }}</p>
</template>
<div class="gl-ml-7 gl-pb-2">
<ul class="list-unstyled gl-py-1">
<li v-for="project in severityGroup.projects" :key="project.id" class="gl-py-2">
<gl-link
target="_blank"
:href="`${project.fullPath}/security/dashboard`"
data-qa-selector="project_name_text"
>{{ project.fullName }}</gl-link
>
<span
v-if="project.mostSevereVulnerability"
ref="mostSevereCount"
class="gl-display-block text-lowercase"
:class="cssForMostSevereVulnerability(project.mostSevereVulnerability)"
>{{ project.mostSevereVulnerability.count }}
{{ severityText(project.mostSevereVulnerability.level) }}
</span>
</li>
</ul>
</div>
</accordion-item>
</template>
</accordion>
</section>
</template>
...@@ -27,42 +27,6 @@ export const setVulnerabilitiesEndpoint = ({ commit }, endpoint) => { ...@@ -27,42 +27,6 @@ export const setVulnerabilitiesEndpoint = ({ commit }, endpoint) => {
commit(types.SET_VULNERABILITIES_ENDPOINT, endpoint); commit(types.SET_VULNERABILITIES_ENDPOINT, endpoint);
}; };
export const setVulnerabilitiesCountEndpoint = ({ commit }, endpoint) => {
commit(types.SET_VULNERABILITIES_COUNT_ENDPOINT, endpoint);
};
export const fetchVulnerabilitiesCount = ({ state, dispatch }, params = {}) => {
if (!state.vulnerabilitiesCountEndpoint) {
return;
}
dispatch('requestVulnerabilitiesCount');
axios({
method: 'GET',
url: state.vulnerabilitiesCountEndpoint,
params,
})
.then(response => {
const { data } = response;
dispatch('receiveVulnerabilitiesCountSuccess', { data });
})
.catch(() => {
dispatch('receiveVulnerabilitiesCountError');
});
};
export const requestVulnerabilitiesCount = ({ commit }) => {
commit(types.REQUEST_VULNERABILITIES_COUNT);
};
export const receiveVulnerabilitiesCountSuccess = ({ commit }, { data }) => {
commit(types.RECEIVE_VULNERABILITIES_COUNT_SUCCESS, data);
};
export const receiveVulnerabilitiesCountError = ({ commit }) => {
commit(types.RECEIVE_VULNERABILITIES_COUNT_ERROR);
};
export const setVulnerabilitiesPage = ({ commit }, page) => { export const setVulnerabilitiesPage = ({ commit }, page) => {
commit(types.SET_VULNERABILITIES_PAGE, page); commit(types.SET_VULNERABILITIES_PAGE, page);
}; };
......
...@@ -6,11 +6,6 @@ export const REQUEST_VULNERABILITIES = 'REQUEST_VULNERABILITIES'; ...@@ -6,11 +6,6 @@ export const REQUEST_VULNERABILITIES = 'REQUEST_VULNERABILITIES';
export const RECEIVE_VULNERABILITIES_SUCCESS = 'RECEIVE_VULNERABILITIES_SUCCESS'; export const RECEIVE_VULNERABILITIES_SUCCESS = 'RECEIVE_VULNERABILITIES_SUCCESS';
export const RECEIVE_VULNERABILITIES_ERROR = 'RECEIVE_VULNERABILITIES_ERROR'; export const RECEIVE_VULNERABILITIES_ERROR = 'RECEIVE_VULNERABILITIES_ERROR';
export const SET_VULNERABILITIES_COUNT_ENDPOINT = 'SET_VULNERABILITIES_COUNT_ENDPOINT';
export const REQUEST_VULNERABILITIES_COUNT = 'REQUEST_VULNERABILITIES_COUNT';
export const RECEIVE_VULNERABILITIES_COUNT_SUCCESS = 'RECEIVE_VULNERABILITIES_COUNT_SUCCESS';
export const RECEIVE_VULNERABILITIES_COUNT_ERROR = 'RECEIVE_VULNERABILITIES_COUNT_ERROR';
export const SET_VULNERABILITIES_HISTORY_ENDPOINT = 'SET_VULNERABILITIES_HISTORY_ENDPOINT'; export const SET_VULNERABILITIES_HISTORY_ENDPOINT = 'SET_VULNERABILITIES_HISTORY_ENDPOINT';
export const SET_VULNERABILITIES_HISTORY_DAY_RANGE = 'SET_VULNERABILITIES_HISTORY_DAY_RANGE'; export const SET_VULNERABILITIES_HISTORY_DAY_RANGE = 'SET_VULNERABILITIES_HISTORY_DAY_RANGE';
export const REQUEST_VULNERABILITIES_HISTORY = 'REQUEST_VULNERABILITIES_HISTORY'; export const REQUEST_VULNERABILITIES_HISTORY = 'REQUEST_VULNERABILITIES_HISTORY';
......
...@@ -31,24 +31,9 @@ export default { ...@@ -31,24 +31,9 @@ export default {
state.errorLoadingVulnerabilities = true; state.errorLoadingVulnerabilities = true;
state.loadingVulnerabilitiesErrorCode = errorCode; state.loadingVulnerabilitiesErrorCode = errorCode;
}, },
[types.SET_VULNERABILITIES_COUNT_ENDPOINT](state, payload) {
state.vulnerabilitiesCountEndpoint = payload;
},
[types.SET_VULNERABILITIES_PAGE](state, payload) { [types.SET_VULNERABILITIES_PAGE](state, payload) {
state.pageInfo = { ...state.pageInfo, page: payload }; state.pageInfo = { ...state.pageInfo, page: payload };
}, },
[types.REQUEST_VULNERABILITIES_COUNT](state) {
state.isLoadingVulnerabilitiesCount = true;
state.errorLoadingVulnerabilitiesCount = false;
},
[types.RECEIVE_VULNERABILITIES_COUNT_SUCCESS](state, payload) {
state.isLoadingVulnerabilitiesCount = false;
state.vulnerabilitiesCount = payload;
},
[types.RECEIVE_VULNERABILITIES_COUNT_ERROR](state) {
state.isLoadingVulnerabilitiesCount = false;
state.errorLoadingVulnerabilitiesCount = true;
},
[types.SET_VULNERABILITIES_HISTORY_ENDPOINT](state, payload) { [types.SET_VULNERABILITIES_HISTORY_ENDPOINT](state, payload) {
state.vulnerabilitiesHistoryEndpoint = payload; state.vulnerabilitiesHistoryEndpoint = payload;
}, },
......
...@@ -3,7 +3,6 @@ export default () => ({ ...@@ -3,7 +3,6 @@ export default () => ({
errorLoadingVulnerabilities: false, errorLoadingVulnerabilities: false,
loadingVulnerabilitiesErrorCode: null, loadingVulnerabilitiesErrorCode: null,
vulnerabilities: [], vulnerabilities: [],
isLoadingVulnerabilitiesCount: true,
errorLoadingVulnerabilitiesCount: false, errorLoadingVulnerabilitiesCount: false,
vulnerabilitiesCount: {}, vulnerabilitiesCount: {},
isLoadingVulnerabilitiesHistory: true, isLoadingVulnerabilitiesHistory: true,
...@@ -13,7 +12,6 @@ export default () => ({ ...@@ -13,7 +12,6 @@ export default () => ({
vulnerabilitiesHistoryMaxDayInterval: 7, vulnerabilitiesHistoryMaxDayInterval: 7,
pageInfo: {}, pageInfo: {},
pipelineId: null, pipelineId: null,
vulnerabilitiesCountEndpoint: null,
vulnerabilitiesHistoryEndpoint: null, vulnerabilitiesHistoryEndpoint: null,
vulnerabilitiesEndpoint: null, vulnerabilitiesEndpoint: null,
activeVulnerability: null, activeVulnerability: null,
......
...@@ -4,7 +4,6 @@ import * as vulnerabilitiesMutationTypes from '../modules/vulnerabilities/mutati ...@@ -4,7 +4,6 @@ import * as vulnerabilitiesMutationTypes from '../modules/vulnerabilities/mutati
export default store => { export default store => {
const refreshVulnerabilities = payload => { const refreshVulnerabilities = payload => {
store.dispatch('vulnerabilities/fetchVulnerabilities', payload); store.dispatch('vulnerabilities/fetchVulnerabilities', payload);
store.dispatch('vulnerabilities/fetchVulnerabilitiesCount', payload);
store.dispatch('vulnerabilities/fetchVulnerabilitiesHistory', payload); store.dispatch('vulnerabilities/fetchVulnerabilitiesHistory', payload);
}; };
......
...@@ -8,8 +8,6 @@ import IssueModal from 'ee/vue_shared/security_reports/components/modal.vue'; ...@@ -8,8 +8,6 @@ import IssueModal from 'ee/vue_shared/security_reports/components/modal.vue';
import SecurityDashboardTable from 'ee/security_dashboard/components/security_dashboard_table.vue'; import SecurityDashboardTable from 'ee/security_dashboard/components/security_dashboard_table.vue';
import SecurityDashboardLayout from 'ee/security_dashboard/components/security_dashboard_layout.vue'; import SecurityDashboardLayout from 'ee/security_dashboard/components/security_dashboard_layout.vue';
import VulnerabilityChart from 'ee/security_dashboard/components/vulnerability_chart.vue'; import VulnerabilityChart from 'ee/security_dashboard/components/vulnerability_chart.vue';
import VulnerabilityCountList from 'ee/security_dashboard/components/vulnerability_count_list_vuex.vue';
import VulnerabilitySeverity from 'ee/security_dashboard/components/vulnerability_severity.vue';
import LoadingError from 'ee/security_dashboard/components/loading_error.vue'; import LoadingError from 'ee/security_dashboard/components/loading_error.vue';
import createStore from 'ee/security_dashboard/store'; import createStore from 'ee/security_dashboard/store';
...@@ -18,9 +16,7 @@ import axios from '~/lib/utils/axios_utils'; ...@@ -18,9 +16,7 @@ import axios from '~/lib/utils/axios_utils';
const pipelineId = 123; const pipelineId = 123;
const vulnerabilitiesEndpoint = `${TEST_HOST}/vulnerabilities`; const vulnerabilitiesEndpoint = `${TEST_HOST}/vulnerabilities`;
const vulnerabilitiesCountEndpoint = `${TEST_HOST}/vulnerabilities_summary`;
const vulnerabilitiesHistoryEndpoint = `${TEST_HOST}/vulnerabilities_history`; const vulnerabilitiesHistoryEndpoint = `${TEST_HOST}/vulnerabilities_history`;
const vulnerableProjectsEndpoint = `${TEST_HOST}/vulnerable_projects`;
jest.mock('~/lib/utils/url_utility', () => ({ jest.mock('~/lib/utils/url_utility', () => ({
getParameterValues: jest.fn().mockReturnValue([]), getParameterValues: jest.fn().mockReturnValue([]),
...@@ -48,9 +44,7 @@ describe('Security Dashboard component', () => { ...@@ -48,9 +44,7 @@ describe('Security Dashboard component', () => {
propsData: { propsData: {
dashboardDocumentation: '', dashboardDocumentation: '',
vulnerabilitiesEndpoint, vulnerabilitiesEndpoint,
vulnerabilitiesCountEndpoint,
vulnerabilitiesHistoryEndpoint, vulnerabilitiesHistoryEndpoint,
vulnerableProjectsEndpoint,
pipelineId, pipelineId,
...props, ...props,
}, },
...@@ -89,10 +83,6 @@ describe('Security Dashboard component', () => { ...@@ -89,10 +83,6 @@ describe('Security Dashboard component', () => {
expect(wrapper.find(VulnerabilityChart).exists()).toBe(true); expect(wrapper.find(VulnerabilityChart).exists()).toBe(true);
}); });
it('does not render the vulnerability count list', () => {
expect(wrapper.find(VulnerabilityCountList).exists()).toBe(false);
});
it('does not lock to a project', () => { it('does not lock to a project', () => {
expect(wrapper.vm.isLockedToProject).toBe(false); expect(wrapper.vm.isLockedToProject).toBe(false);
}); });
...@@ -109,18 +99,6 @@ describe('Security Dashboard component', () => { ...@@ -109,18 +99,6 @@ describe('Security Dashboard component', () => {
expect(fetchPipelineJobsSpy).toHaveBeenCalledWith(); expect(fetchPipelineJobsSpy).toHaveBeenCalledWith();
}); });
describe('when the total number of vulnerabilities change', () => {
const newCount = 3;
beforeEach(() => {
store.state.vulnerabilities.pageInfo = { total: newCount };
});
it('emits a vulnerabilitiesCountChanged event', () => {
expect(wrapper.emitted('vulnerabilitiesCountChanged')).toEqual([[newCount]]);
});
});
it('renders the issue modal', () => { it('renders the issue modal', () => {
expect(wrapper.find(IssueModal).exists()).toBe(true); expect(wrapper.find(IssueModal).exists()).toBe(true);
}); });
...@@ -187,10 +165,6 @@ describe('Security Dashboard component', () => { ...@@ -187,10 +165,6 @@ describe('Security Dashboard component', () => {
}); });
}); });
it('renders the vulnerability count list', () => {
expect(wrapper.find(VulnerabilityCountList).exists()).toBe(true);
});
it('locks to a given project', () => { it('locks to a given project', () => {
expect(wrapper.vm.isLockedToProject).toBe(true); expect(wrapper.vm.isLockedToProject).toBe(true);
}); });
...@@ -205,9 +179,7 @@ describe('Security Dashboard component', () => { ...@@ -205,9 +179,7 @@ describe('Security Dashboard component', () => {
describe.each` describe.each`
endpointProp | Component endpointProp | Component
${'vulnerabilitiesCountEndpoint'} | ${VulnerabilityCountList}
${'vulnerabilitiesHistoryEndpoint'} | ${VulnerabilityChart} ${'vulnerabilitiesHistoryEndpoint'} | ${VulnerabilityChart}
${'vulnerableProjectsEndpoint'} | ${VulnerabilitySeverity}
`('with an empty $endpointProp', ({ endpointProp, Component }) => { `('with an empty $endpointProp', ({ endpointProp, Component }) => {
beforeEach(() => { beforeEach(() => {
createComponent({ createComponent({
......
import { shallowMount } from '@vue/test-utils';
import VulnerabilityCountListVuex from 'ee/security_dashboard/components/vulnerability_count_list_vuex.vue';
import createStore from 'ee/security_dashboard/store';
import VulnerabilityCountListLayout from 'ee/security_dashboard/components/vulnerability_count_list_layout.vue';
import { resetStore } from '../helpers';
import mockData from '../store/modules/vulnerabilities/data/mock_data_vulnerabilities_count.json';
describe('Vulnerability Count List', () => {
const projectFullPath = 'root/security-imports';
const store = createStore();
let wrapper;
const findVulnerabilityCountListLayout = () => wrapper.find(VulnerabilityCountListLayout);
beforeEach(() => {
wrapper = shallowMount(VulnerabilityCountListVuex, {
store,
propsData: {
projectFullPath,
},
});
});
afterEach(() => {
wrapper.destroy();
resetStore(store);
});
it('should pass down the data to the layout', () => {
store.dispatch('vulnerabilities/receiveVulnerabilitiesCountSuccess', { data: mockData });
return wrapper.vm.$nextTick(() => {
const layout = findVulnerabilityCountListLayout();
expect(layout.props('isLoading')).toBe(false);
expect(layout.props('showError')).toBe(false);
expect(layout.props('vulnerabilitiesCount')).toEqual(mockData);
});
});
it('should pass down the loading flag when vulnerabilities are loading', () => {
store.dispatch('vulnerabilities/requestVulnerabilitiesCount');
return wrapper.vm.$nextTick(() => {
const layout = findVulnerabilityCountListLayout();
expect(layout.props('isLoading')).toBe(true);
expect(layout.props('showError')).toBe(false);
expect(layout.props('vulnerabilitiesCount')).toEqual({});
});
});
it('should pass down the error flag when vulnerabilities are loading', () => {
store.dispatch('vulnerabilities/receiveVulnerabilitiesCountError');
return wrapper.vm.$nextTick(() => {
const layout = findVulnerabilityCountListLayout();
expect(layout.props('isLoading')).toBe(false);
expect(layout.props('showError')).toBe(true);
expect(layout.props('vulnerabilitiesCount')).toEqual({});
});
});
});
import Vuex from 'vuex';
import { mount, createLocalVue } from '@vue/test-utils';
import { GlLink } from '@gitlab/ui';
import { trimText } from 'helpers/text_helper';
import { Accordion, AccordionItem } from 'ee/vue_shared/components/accordion';
import VulnerabilitySeverity from 'ee/security_dashboard/components/vulnerability_severity.vue';
import { severityGroupTypes } from 'ee/security_dashboard/store/modules/vulnerable_projects/constants';
const localVue = createLocalVue();
localVue.use(Vuex);
describe('Vulnerability Severity component', () => {
let actions;
let getters;
let store;
let propsData;
let wrapper;
const getMockProject = () => ({
fullPath: '/foo/bar',
fullName: 'baz',
mostSevereVulnerability: { level: 'qux', count: 10 },
});
const getMockSeverityGroups = ({ projects = [] } = {}) =>
Object.keys(severityGroupTypes).reduce((acc, curr) => {
acc[curr] = { type: curr, projects };
return acc;
}, {});
const factory = () => {
const state = {
isLoading: false,
projects: [],
};
propsData = {
endpoint: 'http://foo.com',
};
actions = {
fetchProjects: jest.fn(),
};
getters = {
severityGroups: getMockSeverityGroups,
};
store = new Vuex.Store({
modules: {
vulnerableProjects: {
namespaced: true,
actions,
getters,
state,
},
},
});
wrapper = mount(VulnerabilitySeverity, {
localVue,
store,
propsData,
});
};
const accordion = () => wrapper.find(Accordion);
const accordionItems = () => wrapper.findAll(AccordionItem);
const firstAccordionItem = () => accordionItems().at(0);
const hasAccordionItemForEachSeverityLevel = () =>
expect(accordionItems()).toHaveLength(Object.keys(getMockSeverityGroups()).length);
const hasEachAccordionItemDisabled = () =>
accordionItems().wrappers.every(item => item.props('disabled'));
beforeEach(factory);
afterEach(() => {
wrapper.destroy();
wrapper = null;
jest.restoreAllMocks();
});
describe('when being created', () => {
it('dispatches the "fetchProjects" action with the given endpoint as an argument', () => {
expect(actions.fetchProjects).toHaveBeenCalledTimes(1);
expect(actions.fetchProjects.mock.calls[0][1]).toBe(propsData.endpoint);
});
});
describe('while the data is being loaded', () => {
beforeEach(() => {
store.state.vulnerableProjects.isLoading = true;
return wrapper.vm.$nextTick();
});
it('contains an accordion item with a loading state for each of the severity levels', () => {
hasAccordionItemForEachSeverityLevel();
accordionItems().wrappers.forEach(itemWrapper => {
expect(itemWrapper.props('isLoading')).toBe(true);
});
});
});
describe('when the data has loaded', () => {
it('matches snapshot', () => {
expect(wrapper.element).toMatchSnapshot();
});
it('contains an accordion', () => {
expect(accordion().exists()).toBe(true);
});
it('contains an accordion item for each of the severity levels', () => {
hasAccordionItemForEachSeverityLevel();
});
it('sets accordion items to be disabled if its given severity level has no projects', () => {
store.state.vulnerableProjects.projects = [];
return wrapper.vm.$nextTick().then(() => {
expect(hasEachAccordionItemDisabled()).toBe(true);
});
});
it('does not set accordion items to be disabled if its given severity level has projects', () => {
store.state.vulnerableProjects.projects = [getMockProject()];
return wrapper.vm.$nextTick().then(() => {
expect(hasEachAccordionItemDisabled()).toBe(false);
});
});
it('links to a given project', () => {
const mockProject = getMockProject();
store.state.vulnerableProjects.projects = [mockProject];
return wrapper.vm.$nextTick().then(() => {
expect(
firstAccordionItem()
.find(GlLink)
.attributes('href'),
).toContain(mockProject.fullPath);
expect(firstAccordionItem().text()).toContain(mockProject.fullName);
});
});
it('shows a count for the most severe vulnerability level', () => {
const project = { mostSevereVulnerability: { level: 'critical', count: 10 } };
store.state.vulnerableProjects.projects = [project];
return wrapper.vm.$nextTick().then(() => {
expect(trimText(wrapper.find({ ref: 'mostSevereCount' }).text())).toBe('10 Critical');
});
});
});
});
...@@ -10,7 +10,6 @@ import axios from '~/lib/utils/axios_utils'; ...@@ -10,7 +10,6 @@ import axios from '~/lib/utils/axios_utils';
import toast from '~/vue_shared/plugins/global_toast'; import toast from '~/vue_shared/plugins/global_toast';
import mockDataVulnerabilities from './data/mock_data_vulnerabilities'; import mockDataVulnerabilities from './data/mock_data_vulnerabilities';
import mockDataVulnerabilitiesCount from './data/mock_data_vulnerabilities_count.json';
import mockDataVulnerabilitiesHistory from './data/mock_data_vulnerabilities_history.json'; import mockDataVulnerabilitiesHistory from './data/mock_data_vulnerabilities_history.json';
const sourceBranch = 'feature-branch-1'; const sourceBranch = 'feature-branch-1';
...@@ -22,9 +21,6 @@ jest.mock('jquery', () => () => ({ ...@@ -22,9 +21,6 @@ jest.mock('jquery', () => () => ({
})); }));
describe('vulnerabilities count actions', () => { describe('vulnerabilities count actions', () => {
const data = mockDataVulnerabilitiesCount;
const params = { filters: { type: ['sast'] } };
const filteredData = mockDataVulnerabilitiesCount.sast;
let state; let state;
beforeEach(() => { beforeEach(() => {
...@@ -72,149 +68,6 @@ describe('vulnerabilities count actions', () => { ...@@ -72,149 +68,6 @@ describe('vulnerabilities count actions', () => {
); );
}); });
}); });
describe('setVulnerabilitiesCountEndpoint', () => {
it('should commit the correct mutuation', done => {
const endpoint = 'fakepath.json';
testAction(
actions.setVulnerabilitiesCountEndpoint,
endpoint,
state,
[
{
type: types.SET_VULNERABILITIES_COUNT_ENDPOINT,
payload: endpoint,
},
],
[],
done,
);
});
});
describe('fetchVulnerabilitiesCount', () => {
let mock;
beforeEach(() => {
state.vulnerabilitiesCountEndpoint = `${TEST_HOST}/vulnerabilities_count.json`;
mock = new MockAdapter(axios);
});
afterEach(() => {
mock.restore();
});
describe('on success', () => {
beforeEach(() => {
mock
.onGet(state.vulnerabilitiesCountEndpoint, { params })
.replyOnce(200, filteredData)
.onGet(state.vulnerabilitiesCountEndpoint)
.replyOnce(200, data);
});
it('should dispatch the request and success actions', done => {
testAction(
actions.fetchVulnerabilitiesCount,
{},
state,
[],
[
{ type: 'requestVulnerabilitiesCount' },
{
type: 'receiveVulnerabilitiesCountSuccess',
payload: { data },
},
],
done,
);
});
it('should send the passed filters to the endpoint', done => {
testAction(
actions.fetchVulnerabilitiesCount,
params,
state,
[],
[
{ type: 'requestVulnerabilitiesCount' },
{
type: 'receiveVulnerabilitiesCountSuccess',
payload: { data: filteredData },
},
],
done,
);
});
});
describe('on error', () => {
beforeEach(() => {
mock.onGet(state.vulnerabilitiesCountEndpoint).replyOnce(404, {});
});
it('should dispatch the request and error actions', done => {
testAction(
actions.fetchVulnerabilitiesCount,
{},
state,
[],
[{ type: 'requestVulnerabilitiesCount' }, { type: 'receiveVulnerabilitiesCountError' }],
done,
);
});
});
describe('with an empty endpoint', () => {
beforeEach(() => {
state.vulnerabilitiesCountEndpoint = '';
});
it('should not do anything', done => {
testAction(actions.fetchVulnerabilitiesCount, {}, state, [], [], done);
});
});
});
describe('requestVulnerabilitiesCount', () => {
it('should commit the request mutation', done => {
testAction(
actions.requestVulnerabilitiesCount,
{},
state,
[{ type: types.REQUEST_VULNERABILITIES_COUNT }],
[],
done,
);
});
});
describe('receiveVulnerabilitiesCountSuccess', () => {
it('should commit the success mutation', done => {
testAction(
actions.receiveVulnerabilitiesCountSuccess,
{ data },
state,
[{ type: types.RECEIVE_VULNERABILITIES_COUNT_SUCCESS, payload: data }],
[],
done,
);
});
});
describe('receiveVulnerabilitiesCountError', () => {
it('should commit the error mutation', done => {
testAction(
actions.receiveVulnerabilitiesCountError,
{},
state,
[{ type: types.RECEIVE_VULNERABILITIES_COUNT_ERROR }],
[],
done,
);
});
});
}); });
describe('vulnerabilities actions', () => { describe('vulnerabilities actions', () => {
......
...@@ -113,56 +113,6 @@ describe('vulnerabilities module mutations', () => { ...@@ -113,56 +113,6 @@ describe('vulnerabilities module mutations', () => {
}); });
}); });
describe('SET_VULNERABILITIES_COUNT_ENDPOINT', () => {
it('should set `vulnerabilitiesCountEndpoint` to `fakepath.json`', () => {
const endpoint = 'fakepath.json';
mutations[types.SET_VULNERABILITIES_COUNT_ENDPOINT](state, endpoint);
expect(state.vulnerabilitiesCountEndpoint).toBe(endpoint);
});
});
describe('REQUEST_VULNERABILITIES_COUNT', () => {
beforeEach(() => {
state.errorLoadingVulnerabilitiesCount = true;
mutations[types.REQUEST_VULNERABILITIES_COUNT](state);
});
it('should set `isLoadingVulnerabilitiesCount` to `true`', () => {
expect(state.isLoadingVulnerabilitiesCount).toBeTruthy();
});
it('should set `errorLoadingVulnerabilitiesCount` to `false`', () => {
expect(state.errorLoadingVulnerabilitiesCount).toBeFalsy();
});
});
describe('RECEIVE_VULNERABILITIES_COUNT_SUCCESS', () => {
let payload;
beforeEach(() => {
payload = mockData;
mutations[types.RECEIVE_VULNERABILITIES_COUNT_SUCCESS](state, payload);
});
it('should set `isLoadingVulnerabilitiesCount` to `false`', () => {
expect(state.isLoadingVulnerabilitiesCount).toBeFalsy();
});
it('should set `vulnerabilitiesCount`', () => {
expect(state.vulnerabilitiesCount).toBe(payload);
});
});
describe('RECEIVE_VULNERABILITIES_COUNT_ERROR', () => {
it('should set `isLoadingVulnerabilitiesCount` to `false`', () => {
mutations[types.RECEIVE_VULNERABILITIES_COUNT_ERROR](state);
expect(state.isLoadingVulnerabilitiesCount).toBeFalsy();
});
});
describe('SET_VULNERABILITIES_HISTORY_ENDPOINT', () => { describe('SET_VULNERABILITIES_HISTORY_ENDPOINT', () => {
it('should set `vulnerabilitiesHistoryEndpoint` to `fakepath.json`', () => { it('should set `vulnerabilitiesHistoryEndpoint` to `fakepath.json`', () => {
const endpoint = 'fakepath.json'; const endpoint = 'fakepath.json';
......
...@@ -3,11 +3,8 @@ import * as filtersMutationTypes from 'ee/security_dashboard/store/modules/filte ...@@ -3,11 +3,8 @@ import * as filtersMutationTypes from 'ee/security_dashboard/store/modules/filte
import * as vulnerabilityMutationTypes from 'ee/security_dashboard/store/modules/vulnerabilities/mutation_types'; import * as vulnerabilityMutationTypes from 'ee/security_dashboard/store/modules/vulnerabilities/mutation_types';
function expectRefreshDispatches(store, payload) { function expectRefreshDispatches(store, payload) {
expect(store.dispatch).toHaveBeenCalledTimes(3); expect(store.dispatch).toHaveBeenCalledTimes(2);
expect(store.dispatch).toHaveBeenCalledWith('vulnerabilities/fetchVulnerabilities', payload); expect(store.dispatch).toHaveBeenCalledWith('vulnerabilities/fetchVulnerabilities', payload);
expect(store.dispatch).toHaveBeenCalledWith('vulnerabilities/fetchVulnerabilitiesCount', payload);
expect(store.dispatch).toHaveBeenCalledWith( expect(store.dispatch).toHaveBeenCalledWith(
'vulnerabilities/fetchVulnerabilitiesHistory', 'vulnerabilities/fetchVulnerabilitiesHistory',
payload, payload,
......
...@@ -12,10 +12,6 @@ module QA ...@@ -12,10 +12,6 @@ module QA
element :security_report_content, required: true element :security_report_content, required: true
end end
view 'ee/app/assets/javascripts/security_dashboard/components/vulnerability_severity.vue' do
element :project_name_text, required: true
end
view 'ee/app/assets/javascripts/security_dashboard/components/first_class_vulnerability_severities.vue' do view 'ee/app/assets/javascripts/security_dashboard/components/first_class_vulnerability_severities.vue' do
element :project_name_text, required: true element :project_name_text, required: true
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