Commit fe251765 authored by Phil Hughes's avatar Phil Hughes

Merge branch '5831-security-apps' into 'master'

Resolve "Security reports app tests are not 100% correct"

Closes #5831

See merge request gitlab-org/gitlab-ee!5821
parents 0ba793c6 43997a7b
...@@ -9,7 +9,7 @@ import eventHub from './event_hub'; ...@@ -9,7 +9,7 @@ import eventHub from './event_hub';
import SecurityReportApp from 'ee/vue_shared/security_reports/split_security_reports_app.vue'; // eslint-disable-line import/first import SecurityReportApp from 'ee/vue_shared/security_reports/split_security_reports_app.vue'; // eslint-disable-line import/first
import SastSummaryWidget from 'ee/pipelines/components/security_reports/report_summary_widget.vue'; // eslint-disable-line import/first import SastSummaryWidget from 'ee/pipelines/components/security_reports/report_summary_widget.vue'; // eslint-disable-line import/first
import store from 'ee/vue_shared/security_reports/store'; // eslint-disable-line import/first import createStore from 'ee/vue_shared/security_reports/store'; // eslint-disable-line import/first
Vue.use(Translate); Vue.use(Translate);
...@@ -116,6 +116,8 @@ export default () => { ...@@ -116,6 +116,8 @@ export default () => {
const vulnerabilityFeedbackPath = datasetOptions.vulnerabilityFeedbackPath; const vulnerabilityFeedbackPath = datasetOptions.vulnerabilityFeedbackPath;
const vulnerabilityFeedbackHelpPath = datasetOptions.vulnerabilityFeedbackHelpPath; const vulnerabilityFeedbackHelpPath = datasetOptions.vulnerabilityFeedbackHelpPath;
const pipelineId = parseInt(datasetOptions.pipelineId, 10); const pipelineId = parseInt(datasetOptions.pipelineId, 10);
const store = createStore();
// Widget summary // Widget summary
// eslint-disable-next-line no-new // eslint-disable-next-line no-new
new Vue({ new Vue({
......
<script> <script>
import { mapActions, mapState, mapGetters } from 'vuex'; import { mapActions, mapState, mapGetters } from 'vuex';
import { SAST, DAST, SAST_CONTAINER } from './store/constants'; import { SAST, DAST, SAST_CONTAINER } from './store/constants';
import store from './store'; import createStore from './store';
import ReportSection from './components/report_section.vue'; import ReportSection from './components/report_section.vue';
import SummaryRow from './components/summary_row.vue'; import SummaryRow from './components/summary_row.vue';
import IssuesList from './components/issues_list.vue'; import IssuesList from './components/issues_list.vue';
...@@ -9,7 +9,7 @@ import IssueModal from './components/modal.vue'; ...@@ -9,7 +9,7 @@ import IssueModal from './components/modal.vue';
import securityReportsMixin from './mixins/security_report_mixin'; import securityReportsMixin from './mixins/security_report_mixin';
export default { export default {
store, store: createStore(),
components: { components: {
ReportSection, ReportSection,
SummaryRow, SummaryRow,
......
...@@ -3,14 +3,12 @@ import { mapActions, mapState } from 'vuex'; ...@@ -3,14 +3,12 @@ import { mapActions, mapState } from 'vuex';
import { s__, sprintf, n__ } from '~/locale'; import { s__, sprintf, n__ } from '~/locale';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { SAST } from './store/constants'; import { SAST } from './store/constants';
import store from './store';
import ReportSection from './components/report_section.vue'; import ReportSection from './components/report_section.vue';
import IssueModal from './components/modal.vue'; import IssueModal from './components/modal.vue';
import mixin from './mixins/security_report_mixin'; import mixin from './mixins/security_report_mixin';
import reportsMixin from './mixins/reports_mixin'; import reportsMixin from './mixins/reports_mixin';
export default { export default {
store,
components: { components: {
ReportSection, ReportSection,
IssueModal, IssueModal,
......
...@@ -7,11 +7,9 @@ import state from './state'; ...@@ -7,11 +7,9 @@ import state from './state';
Vue.use(Vuex); Vue.use(Vuex);
const store = new Vuex.Store({ export default () => new Vuex.Store({
actions, actions,
getters, getters,
mutations, mutations,
state: state(), state: state(),
}); });
export default store;
import Vue from 'vue'; import Vue from 'vue';
import component from 'ee/vue_shared/security_reports/components/modal.vue'; import component from 'ee/vue_shared/security_reports/components/modal.vue';
import store from 'ee/vue_shared/security_reports/store'; import createStore from 'ee/vue_shared/security_reports/store';
import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
describe('Security Reports modal', () => { describe('Security Reports modal', () => {
const Component = Vue.extend(component); const Component = Vue.extend(component);
let vm; let vm;
const store = createStore();
beforeEach(() => { beforeEach(() => {
store.dispatch('setVulnerabilityFeedbackPath', 'path'); store.dispatch('setVulnerabilityFeedbackPath', 'path');
......
...@@ -32,9 +32,9 @@ describe('Grouped security reports app', () => { ...@@ -32,9 +32,9 @@ describe('Grouped security reports app', () => {
}); });
afterEach(() => { afterEach(() => {
vm.$store.replaceState(state());
vm.$destroy(); vm.$destroy();
mock.restore(); mock.restore();
vm.$store.replaceState(state());
}); });
describe('with error', () => { describe('with error', () => {
...@@ -126,7 +126,7 @@ describe('Grouped security reports app', () => { ...@@ -126,7 +126,7 @@ describe('Grouped security reports app', () => {
}); });
}); });
it('renders loading summary text + spinner', () => { it('renders loading summary text + spinner', (done) => {
expect(vm.$el.querySelector('.fa-spinner')).not.toBeNull(); expect(vm.$el.querySelector('.fa-spinner')).not.toBeNull();
expect(vm.$el.querySelector('.js-code-text').textContent.trim()).toEqual( expect(vm.$el.querySelector('.js-code-text').textContent.trim()).toEqual(
'Security scanning is loading', 'Security scanning is loading',
...@@ -137,6 +137,10 @@ describe('Grouped security reports app', () => { ...@@ -137,6 +137,10 @@ describe('Grouped security reports app', () => {
expect(vm.$el.textContent).toContain('Dependency scanning is loading'); expect(vm.$el.textContent).toContain('Dependency scanning is loading');
expect(vm.$el.textContent).toContain('Container scanning is loading'); expect(vm.$el.textContent).toContain('Container scanning is loading');
expect(vm.$el.textContent).toContain('DAST is loading'); expect(vm.$el.textContent).toContain('DAST is loading');
setTimeout(() => {
done();
}, 0);
}); });
}); });
...@@ -175,19 +179,30 @@ describe('Grouped security reports app', () => { ...@@ -175,19 +179,30 @@ describe('Grouped security reports app', () => {
it('renders reports', done => { it('renders reports', done => {
setTimeout(() => { setTimeout(() => {
// It's not loading
expect(vm.$el.querySelector('.fa-spinner')).toBeNull(); expect(vm.$el.querySelector('.fa-spinner')).toBeNull();
// Renders the summary text
expect(vm.$el.querySelector('.js-code-text').textContent.trim()).toEqual( expect(vm.$el.querySelector('.js-code-text').textContent.trim()).toEqual(
'Security scanning detected 12 new vulnerabilities and 4 fixed vulnerabilities', 'Security scanning detected 6 new vulnerabilities and 2 fixed vulnerabilities',
); );
// Renders the expand button
expect(vm.$el.querySelector('.js-collapse-btn').textContent.trim()).toEqual('Expand'); expect(vm.$el.querySelector('.js-collapse-btn').textContent.trim()).toEqual('Expand');
// Renders Sast result
expect(removeBreakLine(vm.$el.textContent)).toContain( expect(removeBreakLine(vm.$el.textContent)).toContain(
'SAST detected 2 new vulnerabilities and 1 fixed vulnerability', 'SAST detected 2 new vulnerabilities and 1 fixed vulnerability',
); );
// Renders DSS result
expect(removeBreakLine(vm.$el.textContent)).toContain( expect(removeBreakLine(vm.$el.textContent)).toContain(
'Dependency scanning detected 2 new vulnerabilities and 1 fixed vulnerability', 'Dependency scanning detected 2 new vulnerabilities and 1 fixed vulnerability',
); );
// Renders container scanning result
expect(vm.$el.textContent).toContain('Container scanning detected 1 new vulnerability'); expect(vm.$el.textContent).toContain('Container scanning detected 1 new vulnerability');
// Renders DAST result
expect(vm.$el.textContent).toContain('DAST detected 1 new vulnerability'); expect(vm.$el.textContent).toContain('DAST detected 1 new vulnerability');
done(); done();
}, 0); }, 0);
......
...@@ -2,9 +2,9 @@ import Vue from 'vue'; ...@@ -2,9 +2,9 @@ import Vue from 'vue';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import component from 'ee/vue_shared/security_reports/split_security_reports_app.vue'; import component from 'ee/vue_shared/security_reports/split_security_reports_app.vue';
import createStore from 'ee/vue_shared/security_reports/store';
import state from 'ee/vue_shared/security_reports/store/state'; import state from 'ee/vue_shared/security_reports/store/state';
import { mountComponentWithStore } from '../../helpers/vue_mount_component_helper';
import mountComponent from '../../helpers/vue_mount_component_helper';
import { sastIssues } from './mock_data'; import { sastIssues } from './mock_data';
describe('Slipt security reports app', () => { describe('Slipt security reports app', () => {
...@@ -25,9 +25,9 @@ describe('Slipt security reports app', () => { ...@@ -25,9 +25,9 @@ describe('Slipt security reports app', () => {
}); });
afterEach(() => { afterEach(() => {
vm.$store.replaceState(state());
vm.$destroy(); vm.$destroy();
mock.restore(); mock.restore();
vm.$store.replaceState(state());
}); });
describe('while loading', () => { describe('while loading', () => {
...@@ -36,7 +36,9 @@ describe('Slipt security reports app', () => { ...@@ -36,7 +36,9 @@ describe('Slipt security reports app', () => {
mock.onGet('dss_head.json').reply(200, sastIssues); mock.onGet('dss_head.json').reply(200, sastIssues);
mock.onGet('vulnerability_feedback_path.json').reply(200, []); mock.onGet('vulnerability_feedback_path.json').reply(200, []);
vm = mountComponent(Component, { vm = mountComponentWithStore(Component, {
store: createStore(),
props: {
headBlobPath: 'path', headBlobPath: 'path',
baseBlobPath: 'path', baseBlobPath: 'path',
sastHeadPath: 'sast_head.json', sastHeadPath: 'sast_head.json',
...@@ -46,14 +48,19 @@ describe('Slipt security reports app', () => { ...@@ -46,14 +48,19 @@ describe('Slipt security reports app', () => {
vulnerabilityFeedbackPath: 'vulnerability_feedback_path.json', vulnerabilityFeedbackPath: 'vulnerability_feedback_path.json',
vulnerabilityFeedbackHelpPath: 'path', vulnerabilityFeedbackHelpPath: 'path',
pipelineId: 123, pipelineId: 123,
},
}); });
}); });
it('renders loading summary text + spinner', () => { it('renders loading summary text + spinner', done => {
expect(vm.$el.querySelector('.fa-spinner')).not.toBeNull(); expect(vm.$el.querySelector('.fa-spinner')).not.toBeNull();
expect(vm.$el.textContent).toContain('SAST is loading'); expect(vm.$el.textContent).toContain('SAST is loading');
expect(vm.$el.textContent).toContain('Dependency scanning is loading'); expect(vm.$el.textContent).toContain('Dependency scanning is loading');
setTimeout(() => {
done();
}, 0);
}); });
}); });
...@@ -63,7 +70,9 @@ describe('Slipt security reports app', () => { ...@@ -63,7 +70,9 @@ describe('Slipt security reports app', () => {
mock.onGet('dss_head.json').reply(200, sastIssues); mock.onGet('dss_head.json').reply(200, sastIssues);
mock.onGet('vulnerability_feedback_path.json').reply(200, []); mock.onGet('vulnerability_feedback_path.json').reply(200, []);
vm = mountComponent(Component, { vm = mountComponentWithStore(Component, {
store: createStore(),
props: {
headBlobPath: 'path', headBlobPath: 'path',
baseBlobPath: 'path', baseBlobPath: 'path',
sastHeadPath: 'sast_head.json', sastHeadPath: 'sast_head.json',
...@@ -73,6 +82,7 @@ describe('Slipt security reports app', () => { ...@@ -73,6 +82,7 @@ describe('Slipt security reports app', () => {
vulnerabilityFeedbackPath: 'vulnerability_feedback_path.json', vulnerabilityFeedbackPath: 'vulnerability_feedback_path.json',
vulnerabilityFeedbackHelpPath: 'path', vulnerabilityFeedbackHelpPath: 'path',
pipelineId: 123, pipelineId: 123,
},
}); });
}); });
...@@ -96,7 +106,9 @@ describe('Slipt security reports app', () => { ...@@ -96,7 +106,9 @@ describe('Slipt security reports app', () => {
mock.onGet('dss_head.json').reply(500); mock.onGet('dss_head.json').reply(500);
mock.onGet('vulnerability_feedback_path.json').reply(500, []); mock.onGet('vulnerability_feedback_path.json').reply(500, []);
vm = mountComponent(Component, { vm = mountComponentWithStore(Component, {
store: createStore(),
props: {
headBlobPath: 'path', headBlobPath: 'path',
baseBlobPath: 'path', baseBlobPath: 'path',
sastHeadPath: 'sast_head.json', sastHeadPath: 'sast_head.json',
...@@ -106,6 +118,7 @@ describe('Slipt security reports app', () => { ...@@ -106,6 +118,7 @@ describe('Slipt security reports app', () => {
vulnerabilityFeedbackPath: 'vulnerability_feedback_path.json', vulnerabilityFeedbackPath: 'vulnerability_feedback_path.json',
vulnerabilityFeedbackHelpPath: 'path', vulnerabilityFeedbackHelpPath: 'path',
pipelineId: 123, pipelineId: 123,
},
}); });
}); });
......
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