diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
commit | e8d2c2579383897a1dd7f9debd359abe8ae8373d (patch) | |
tree | c42be41678c2586d49a75cabce89322082698334 /spec/frontend/vue_shared/security_reports | |
parent | fc845b37ec3a90aaa719975f607740c22ba6a113 (diff) |
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'spec/frontend/vue_shared/security_reports')
4 files changed, 71 insertions, 11 deletions
diff --git a/spec/frontend/vue_shared/security_reports/components/manage_via_mr_spec.js b/spec/frontend/vue_shared/security_reports/components/manage_via_mr_spec.js index 517eee6a729..facbd51168c 100644 --- a/spec/frontend/vue_shared/security_reports/components/manage_via_mr_spec.js +++ b/spec/frontend/vue_shared/security_reports/components/manage_via_mr_spec.js @@ -9,6 +9,7 @@ import waitForPromises from 'helpers/wait_for_promises'; import { humanize } from '~/lib/utils/text_utility'; import { redirectTo } from '~/lib/utils/url_utility'; import ManageViaMr from '~/vue_shared/security_configuration/components/manage_via_mr.vue'; +import { REPORT_TYPE_SAST } from '~/vue_shared/security_reports/constants'; import { buildConfigureSecurityFeatureMockFactory } from './apollo_mocks'; jest.mock('~/lib/utils/url_utility'); @@ -169,6 +170,29 @@ describe('ManageViaMr component', () => { }, ); + describe('canRender static method', () => { + it.each` + context | type | available | configured | canEnableByMergeRequest | expectedValue + ${'an unconfigured feature'} | ${REPORT_TYPE_SAST} | ${true} | ${false} | ${true} | ${true} + ${'a configured feature'} | ${REPORT_TYPE_SAST} | ${true} | ${true} | ${true} | ${false} + ${'an unavailable feature'} | ${REPORT_TYPE_SAST} | ${false} | ${false} | ${true} | ${false} + ${'a feature which cannot be enabled via MR'} | ${REPORT_TYPE_SAST} | ${true} | ${false} | ${false} | ${false} + ${'an unknown feature'} | ${'foo'} | ${true} | ${false} | ${true} | ${false} + `( + 'given $context returns $expectedValue', + ({ type, available, configured, canEnableByMergeRequest, expectedValue }) => { + expect( + ManageViaMr.canRender({ + type, + available, + configured, + canEnableByMergeRequest, + }), + ).toBe(expectedValue); + }, + ); + }); + describe('button props', () => { it('passes the variant and category props to the GlButton', () => { const variant = 'danger'; diff --git a/spec/frontend/vue_shared/security_reports/components/security_report_download_dropdown_spec.js b/spec/frontend/vue_shared/security_reports/components/security_report_download_dropdown_spec.js index 9138d2d3f4c..4b75da0b126 100644 --- a/spec/frontend/vue_shared/security_reports/components/security_report_download_dropdown_spec.js +++ b/spec/frontend/vue_shared/security_reports/components/security_report_download_dropdown_spec.js @@ -40,14 +40,13 @@ describe('SecurityReportDownloadDropdown component', () => { expect(findDropdown().props('loading')).toBe(false); }); - it('renders a dropdown items for each artifact', () => { + it('renders a dropdown item for each artifact', () => { artifacts.forEach((artifact, i) => { const item = findDropdownItems().at(i); expect(item.text()).toContain(artifact.name); - expect(item.attributes()).toMatchObject({ - href: artifact.path, - download: expect.any(String), - }); + + expect(item.element.getAttribute('href')).toBe(artifact.path); + expect(item.element.getAttribute('download')).toBeDefined(); }); }); }); @@ -61,4 +60,32 @@ describe('SecurityReportDownloadDropdown component', () => { expect(findDropdown().props('loading')).toBe(true); }); }); + + describe('given title props', () => { + beforeEach(() => { + createComponent({ artifacts: [], loading: true, title: 'test title' }); + }); + + it('should render title', () => { + expect(findDropdown().attributes('title')).toBe('test title'); + }); + + it('should not render text', () => { + expect(findDropdown().text().trim()).toBe(''); + }); + }); + + describe('given text props', () => { + beforeEach(() => { + createComponent({ artifacts: [], loading: true, text: 'test text' }); + }); + + it('should not render title', () => { + expect(findDropdown().props().title).not.toBeDefined(); + }); + + it('should render text', () => { + expect(findDropdown().props().text).toContain('test text'); + }); + }); }); diff --git a/spec/frontend/vue_shared/security_reports/mock_data.js b/spec/frontend/vue_shared/security_reports/mock_data.js index bd9ce3b7314..06631710509 100644 --- a/spec/frontend/vue_shared/security_reports/mock_data.js +++ b/spec/frontend/vue_shared/security_reports/mock_data.js @@ -581,9 +581,18 @@ export const secretDetectionArtifacts = [ }, ]; -export const expectedDownloadDropdownProps = { +export const expectedDownloadDropdownPropsWithTitle = { loading: false, artifacts: [...secretDetectionArtifacts, ...sastArtifacts], + text: '', + title: 'Download results', +}; + +export const expectedDownloadDropdownPropsWithText = { + loading: false, + artifacts: [...secretDetectionArtifacts, ...sastArtifacts], + title: '', + text: 'Download results', }; /** diff --git a/spec/frontend/vue_shared/security_reports/security_reports_app_spec.js b/spec/frontend/vue_shared/security_reports/security_reports_app_spec.js index 038d7754776..bef538e1ff1 100644 --- a/spec/frontend/vue_shared/security_reports/security_reports_app_spec.js +++ b/spec/frontend/vue_shared/security_reports/security_reports_app_spec.js @@ -8,7 +8,7 @@ import createMockApollo from 'helpers/mock_apollo_helper'; import { trimText } from 'helpers/text_helper'; import waitForPromises from 'helpers/wait_for_promises'; import { - expectedDownloadDropdownProps, + expectedDownloadDropdownPropsWithText, securityReportMergeRequestDownloadPathsQueryNoArtifactsResponse, securityReportMergeRequestDownloadPathsQueryResponse, sastDiffSuccessMock, @@ -99,7 +99,7 @@ describe('Security reports app', () => { }); it('renders the download dropdown', () => { - expect(findDownloadDropdown().props()).toEqual(expectedDownloadDropdownProps); + expect(findDownloadDropdown().props()).toEqual(expectedDownloadDropdownPropsWithText); }); it('renders the expected message', () => { @@ -203,7 +203,7 @@ describe('Security reports app', () => { }); it('renders the download dropdown', () => { - expect(findDownloadDropdown().props()).toEqual(expectedDownloadDropdownProps); + expect(findDownloadDropdown().props()).toEqual(expectedDownloadDropdownPropsWithText); }); }); @@ -225,7 +225,7 @@ describe('Security reports app', () => { }); it('renders the download dropdown', () => { - expect(findDownloadDropdown().props()).toEqual(expectedDownloadDropdownProps); + expect(findDownloadDropdown().props()).toEqual(expectedDownloadDropdownPropsWithText); }); }); @@ -247,7 +247,7 @@ describe('Security reports app', () => { }); it('renders the download dropdown', () => { - expect(findDownloadDropdown().props()).toEqual(expectedDownloadDropdownProps); + expect(findDownloadDropdown().props()).toEqual(expectedDownloadDropdownPropsWithText); }); }); |