Commit a2aa897b authored by Phil Hughes's avatar Phil Hughes

Merge branch '349608-not-enabled-state-in-dets-page' into 'master'

Hide training section in vulnerability details

See merge request gitlab-org/gitlab!78201
parents 40624225 632b0878
...@@ -3,6 +3,7 @@ import Vue from 'vue'; ...@@ -3,6 +3,7 @@ import Vue from 'vue';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import createDefaultClient from '~/lib/graphql'; import createDefaultClient from '~/lib/graphql';
import { vulnerabilityLocationTypes } from '~/graphql_shared/fragment_types/vulnerability_location_types'; import { vulnerabilityLocationTypes } from '~/graphql_shared/fragment_types/vulnerability_location_types';
import tempResolvers from '~/security_configuration/resolver';
Vue.use(VueApollo); Vue.use(VueApollo);
...@@ -13,7 +14,9 @@ const fragmentMatcher = new IntrospectionFragmentMatcher({ ...@@ -13,7 +14,9 @@ const fragmentMatcher = new IntrospectionFragmentMatcher({
}); });
const defaultClient = createDefaultClient( const defaultClient = createDefaultClient(
{}, {
...tempResolvers,
},
{ {
cacheConfig: { cacheConfig: {
fragmentMatcher, fragmentMatcher,
......
<script> <script>
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import securityTrainingProvidersQuery from '~/security_configuration/graphql/security_training_providers.query.graphql';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { SUPPORTED_REFERENCE_SCHEMA } from '../constants'; import { SUPPORTED_REFERENCE_SCHEMA } from '../constants';
...@@ -20,9 +21,23 @@ export default { ...@@ -20,9 +21,23 @@ export default {
required: true, required: true,
}, },
}, },
apollo: {
securityTrainingProviders: {
query: securityTrainingProvidersQuery,
},
},
data() {
return {
securityTrainingProviders: [],
};
},
computed: { computed: {
hasTraining() { hasTraining() {
return this.glFeatures.secureVulnerabilityTraining && this.identifiers?.length; return (
this.glFeatures.secureVulnerabilityTraining &&
this.securityTrainingProviders?.length &&
this.identifiers?.length
);
}, },
isSupportedReferenceSchema() { isSupportedReferenceSchema() {
return this.referenceSchemas?.some( return this.referenceSchemas?.some(
......
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import VulnerabilityTraining, { import VulnerabilityTraining, {
i18n, i18n,
} from 'ee/vulnerabilities/components/vulnerability_training.vue'; } from 'ee/vulnerabilities/components/vulnerability_training.vue';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import { SUPPORTED_REFERENCE_SCHEMA } from 'ee/vulnerabilities/constants'; import { SUPPORTED_REFERENCE_SCHEMA } from 'ee/vulnerabilities/constants';
import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises';
import { createMockResolvers } from 'jest/security_configuration/mock_data';
const defaultProps = { const defaultProps = {
identifiers: [{ externalType: SUPPORTED_REFERENCE_SCHEMA.cwe }, { externalType: 'cve' }], identifiers: [{ externalType: SUPPORTED_REFERENCE_SCHEMA.cwe }, { externalType: 'cve' }],
}; };
Vue.use(VueApollo);
describe('VulnerabilityTraining component', () => { describe('VulnerabilityTraining component', () => {
let wrapper; let wrapper;
let apolloProvider;
const createApolloProvider = ({ resolvers } = {}) => {
apolloProvider = createMockApollo([], createMockResolvers({ resolvers }));
};
const createComponent = (props = {}, { secureVulnerabilityTraining = true } = {}) => { const createComponent = (props = {}, { secureVulnerabilityTraining = true } = {}) => {
wrapper = shallowMountExtended(VulnerabilityTraining, { wrapper = shallowMountExtended(VulnerabilityTraining, {
...@@ -17,6 +29,7 @@ describe('VulnerabilityTraining component', () => { ...@@ -17,6 +29,7 @@ describe('VulnerabilityTraining component', () => {
...defaultProps, ...defaultProps,
...props, ...props,
}, },
apolloProvider,
provide: { provide: {
glFeatures: { glFeatures: {
secureVulnerabilityTraining, secureVulnerabilityTraining,
...@@ -25,10 +38,16 @@ describe('VulnerabilityTraining component', () => { ...@@ -25,10 +38,16 @@ describe('VulnerabilityTraining component', () => {
}); });
}; };
beforeEach(async () => {
createApolloProvider();
});
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
apolloProvider = null;
}); });
const waitForQueryToBeLoaded = () => waitForPromises();
const findTitle = () => wrapper.findByRole('heading', i18n.trainingTitle); const findTitle = () => wrapper.findByRole('heading', i18n.trainingTitle);
const findDescription = () => wrapper.findByTestId('description'); const findDescription = () => wrapper.findByTestId('description');
const findUnavailableMessage = () => wrapper.findByTestId('unavailable-message'); const findUnavailableMessage = () => wrapper.findByTestId('unavailable-message');
...@@ -38,11 +57,13 @@ describe('VulnerabilityTraining component', () => { ...@@ -38,11 +57,13 @@ describe('VulnerabilityTraining component', () => {
createComponent(); createComponent();
}); });
it('displays the title', () => { it('displays the title', async () => {
await waitForQueryToBeLoaded();
expect(findTitle().text()).toBe(i18n.trainingTitle); expect(findTitle().text()).toBe(i18n.trainingTitle);
}); });
it('displays the description', () => { it('displays the description', async () => {
await waitForQueryToBeLoaded();
expect(findDescription().text()).toBe(i18n.trainingDescription); expect(findDescription().text()).toBe(i18n.trainingDescription);
}); });
...@@ -50,21 +71,29 @@ describe('VulnerabilityTraining component', () => { ...@@ -50,21 +71,29 @@ describe('VulnerabilityTraining component', () => {
createComponent({ identifiers: [] }); createComponent({ identifiers: [] });
expect(wrapper.html()).toBeFalsy(); expect(wrapper.html()).toBeFalsy();
}); });
it('does not render component when there are no securityTrainingProviders', () => {
expect(wrapper.html()).toBeFalsy();
});
}); });
describe('training availability message', () => { describe('training availability message', () => {
it('displays the message', () => { it('displays the message', async () => {
createComponent({ identifiers: [{ externalType: 'not supported identifier' }] }); createComponent({
identifiers: [{ externalType: 'not supported identifier' }],
});
await waitForQueryToBeLoaded();
expect(findUnavailableMessage().text()).toBe(i18n.trainingUnavailable); expect(findUnavailableMessage().text()).toBe(i18n.trainingUnavailable);
}); });
it.each` it.each`
identifiers | exists identifier | exists
${[{ externalType: 'cve' }]} | ${true} ${'not supported identifier'} | ${true}
${[{ externalType: SUPPORTED_REFERENCE_SCHEMA.cwe.toUpperCase() }]} | ${false} ${SUPPORTED_REFERENCE_SCHEMA.cwe.toUpperCase()} | ${false}
${[{ externalType: SUPPORTED_REFERENCE_SCHEMA.cwe.toLowerCase() }]} | ${false} ${SUPPORTED_REFERENCE_SCHEMA.cwe.toLowerCase()} | ${false}
`('sets it to "$exists" for "$identifiers"', ({ identifiers, exists }) => { `('sets it to "$exists" for "$identifier"', async ({ identifier, exists }) => {
createComponent({ identifiers }); createComponent({ identifiers: [{ externalType: identifier }] });
await waitForQueryToBeLoaded();
expect(findUnavailableMessage().exists()).toBe(exists); expect(findUnavailableMessage().exists()).toBe(exists);
}); });
}); });
......
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