Commit 491b45b1 authored by Nathan Friend's avatar Nathan Friend

Merge branch '212867-clean-up-dependency_list_ui-remove-table-row' into 'master'

Remove unused DependenciesTableRow component

See merge request gitlab-org/gitlab!31096
parents 30e975ce 35ae1514
<script>
import { GlDeprecatedButton, GlSkeletonLoading } from '@gitlab/ui';
import Icon from '~/vue_shared/components/icon.vue';
import DependencyLicenseLinks from './dependency_license_links.vue';
import DependencyVulnerability from './dependency_vulnerability.vue';
import { MAX_DISPLAYED_VULNERABILITIES_PER_DEPENDENCY } from './constants';
export default {
name: 'DependenciesTableRow',
components: {
DependencyLicenseLinks,
DependencyVulnerability,
GlDeprecatedButton,
GlSkeletonLoading,
Icon,
},
props: {
dependency: {
type: Object,
required: false,
default: null,
},
isLoading: {
type: Boolean,
required: false,
default: true,
},
},
data() {
return {
isExpanded: false,
};
},
computed: {
toggleArrowName() {
return this.isExpanded ? 'chevron-up' : 'chevron-down';
},
vulnerabilities() {
const { vulnerabilities = [] } = this.dependency || {};
return vulnerabilities;
},
isVulnerable() {
return this.vulnerabilities.length > 0;
},
renderableVulnerabilities() {
return this.vulnerabilities.slice(0, MAX_DISPLAYED_VULNERABILITIES_PER_DEPENDENCY);
},
vulnerabilitiesNotShown() {
return Math.max(
0,
this.vulnerabilities.length - MAX_DISPLAYED_VULNERABILITIES_PER_DEPENDENCY,
);
},
},
watch: {
dependency: 'collapseVulnerabilities',
isLoading: 'collapseVulnerabilities',
},
methods: {
toggleVulnerabilities() {
this.isExpanded = !this.isExpanded;
},
collapseVulnerabilities() {
this.isExpanded = false;
},
},
};
</script>
<template>
<div class="gl-responsive-table-row flex-md-column align-items-md-stretch px-2">
<gl-skeleton-loading
v-if="isLoading"
:lines="1"
class="d-flex flex-column justify-content-center h-auto"
/>
<div v-else class="d-md-flex align-items-baseline">
<!-- status-->
<div class="table-section section-20 section-wrap pr-md-3">
<div class="table-mobile-header" role="rowheader">{{ s__('Dependencies|Status') }}</div>
<div class="table-mobile-content">
<gl-deprecated-button
v-if="isVulnerable"
class="bold text-warning-700 text-1 text-decoration-none js-vulnerabilities-toggle"
variant="link"
@click="toggleVulnerabilities"
>
<icon :name="toggleArrowName" class="align-top text-secondary-700 d-none d-md-inline" />
{{
n__(
'Dependencies|%d vulnerability',
'Dependencies|%d vulnerabilities',
vulnerabilities.length,
)
}}
</gl-deprecated-button>
<span v-else class="text-success-500 text-1">
<icon name="check-circle" class="align-middle mr-1" />{{ s__('Dependencies|Safe') }}
</span>
</div>
</div>
<!-- name-->
<div class="table-section section-20 section-wrap pr-md-3">
<div class="table-mobile-header" role="rowheader">
{{ s__('Dependencies|Component') }}
</div>
<div class="table-mobile-content">{{ dependency.name }}</div>
</div>
<!-- version -->
<div class="table-section section-10 pr-md-3">
<div class="table-mobile-header" role="rowheader">{{ s__('Dependencies|Version') }}</div>
<div class="table-mobile-content">{{ dependency.version }}</div>
</div>
<!-- packager -->
<div class="table-section section-20 section-wrap pr-md-3">
<div class="table-mobile-header" role="rowheader">{{ s__('Dependencies|Packager') }}</div>
<div class="table-mobile-content">{{ dependency.packager }}</div>
</div>
<!-- location -->
<div class="table-section section-15 section-wrap pr-md-3">
<div class="table-mobile-header" role="rowheader">{{ s__('Dependencies|Location') }}</div>
<div class="table-mobile-content">
<a :href="dependency.location.blob_path">{{ dependency.location.path }}</a>
</div>
</div>
<!-- license -->
<div class="table-section section-15 section-wrap">
<div class="table-mobile-header" role="rowheader">{{ s__('Dependencies|License') }}</div>
<div class="table-mobile-content">
<dependency-license-links :licenses="dependency.licenses" :title="dependency.name" />
</div>
</div>
</div>
<ul v-if="isExpanded" class="d-none d-md-block list-unstyled mb-1">
<li v-for="vulnerability in renderableVulnerabilities" :key="vulnerability.id">
<dependency-vulnerability :vulnerability="vulnerability" class="mt-3" />
</li>
<li v-if="vulnerabilitiesNotShown" class="text-muted text-center mt-3 js-excess-message">
{{
n__(
'Dependencies|%d additional vulnerability not shown',
'Dependencies|%d additional vulnerabilities not shown',
vulnerabilitiesNotShown,
)
}}
</li>
</ul>
</div>
</template>
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`DependenciesTableRow component when a dependency with no vulnerabilities is loaded matches the snapshot 1`] = `
<div
class="gl-responsive-table-row flex-md-column align-items-md-stretch px-2"
>
<div
class="d-md-flex align-items-baseline"
>
<div
class="table-section section-20 section-wrap pr-md-3"
>
<div
class="table-mobile-header"
role="rowheader"
>
Status
</div>
<div
class="table-mobile-content"
>
<span
class="text-success-500 text-1"
>
<icon-stub
class="align-middle mr-1"
name="check-circle"
size="16"
/>
Safe
</span>
</div>
</div>
<div
class="table-section section-20 section-wrap pr-md-3"
>
<div
class="table-mobile-header"
role="rowheader"
>
Component
</div>
<div
class="table-mobile-content"
>
left-pad
</div>
</div>
<div
class="table-section section-10 pr-md-3"
>
<div
class="table-mobile-header"
role="rowheader"
>
Version
</div>
<div
class="table-mobile-content"
>
0.0.3
</div>
</div>
<div
class="table-section section-20 section-wrap pr-md-3"
>
<div
class="table-mobile-header"
role="rowheader"
>
Packager
</div>
<div
class="table-mobile-content"
>
JavaScript (yarn)
</div>
</div>
<div
class="table-section section-15 section-wrap pr-md-3"
>
<div
class="table-mobile-header"
role="rowheader"
>
Location
</div>
<div
class="table-mobile-content"
>
<a
href="/a-group/a-project/blob/da39a3ee5e6b4b0d3255bfef95601890afd80709/yarn.lock"
>
yarn.lock
</a>
</div>
</div>
<div
class="table-section section-15 section-wrap"
>
<div
class="table-mobile-header"
role="rowheader"
>
License
</div>
<div
class="table-mobile-content"
>
<dependency-license-links-stub
licenses=""
title="left-pad"
/>
</div>
</div>
</div>
<!---->
</div>
`;
exports[`DependenciesTableRow component when a dependency with vulnerabilities is loaded matches the snapshot 1`] = `
<div
class="gl-responsive-table-row flex-md-column align-items-md-stretch px-2"
>
<div
class="d-md-flex align-items-baseline"
>
<div
class="table-section section-20 section-wrap pr-md-3"
>
<div
class="table-mobile-header"
role="rowheader"
>
Status
</div>
<div
class="table-mobile-content"
>
<gl-deprecated-button-stub
class="bold text-warning-700 text-1 text-decoration-none js-vulnerabilities-toggle"
size="md"
variant="link"
>
<icon-stub
class="align-top text-secondary-700 d-none d-md-inline"
name="chevron-down"
size="16"
/>
8 vulnerabilities
</gl-deprecated-button-stub>
</div>
</div>
<div
class="table-section section-20 section-wrap pr-md-3"
>
<div
class="table-mobile-header"
role="rowheader"
>
Component
</div>
<div
class="table-mobile-content"
>
left-pad
</div>
</div>
<div
class="table-section section-10 pr-md-3"
>
<div
class="table-mobile-header"
role="rowheader"
>
Version
</div>
<div
class="table-mobile-content"
>
0.0.3
</div>
</div>
<div
class="table-section section-20 section-wrap pr-md-3"
>
<div
class="table-mobile-header"
role="rowheader"
>
Packager
</div>
<div
class="table-mobile-content"
>
JavaScript (yarn)
</div>
</div>
<div
class="table-section section-15 section-wrap pr-md-3"
>
<div
class="table-mobile-header"
role="rowheader"
>
Location
</div>
<div
class="table-mobile-content"
>
<a
href="/a-group/a-project/blob/da39a3ee5e6b4b0d3255bfef95601890afd80709/yarn.lock"
>
yarn.lock
</a>
</div>
</div>
<div
class="table-section section-15 section-wrap"
>
<div
class="table-mobile-header"
role="rowheader"
>
License
</div>
<div
class="table-mobile-content"
>
<dependency-license-links-stub
licenses=""
title="left-pad"
/>
</div>
</div>
</div>
<!---->
</div>
`;
exports[`DependenciesTableRow component when loading matches the snapshot 1`] = `
<div
class="gl-responsive-table-row flex-md-column align-items-md-stretch px-2"
>
<gl-skeleton-loading-stub
class="d-flex flex-column justify-content-center h-auto"
lines="1"
/>
<!---->
</div>
`;
exports[`DependenciesTableRow component when passed no props matches the snapshot 1`] = `
<div
class="gl-responsive-table-row flex-md-column align-items-md-stretch px-2"
>
<gl-skeleton-loading-stub
class="d-flex flex-column justify-content-center h-auto"
lines="1"
/>
<!---->
</div>
`;
import { shallowMount } from '@vue/test-utils';
import DependenciesTableRow from 'ee/dependencies/components/dependencies_table_row.vue';
import DependencyVulnerability from 'ee/dependencies/components/dependency_vulnerability.vue';
import { MAX_DISPLAYED_VULNERABILITIES_PER_DEPENDENCY } from 'ee/dependencies/components/constants';
import { makeDependency } from './utils';
import mockDataVulnerabilities from '../../security_dashboard/store/modules/vulnerabilities/data/mock_data_vulnerabilities';
describe('DependenciesTableRow component', () => {
let wrapper;
const factory = ({ propsData, ...options } = {}) => {
wrapper = shallowMount(DependenciesTableRow, {
...options,
propsData: { ...propsData },
});
};
const findVulnerabilities = () => wrapper.findAll(DependencyVulnerability).wrappers;
const findExcessMessage = () => wrapper.find('.js-excess-message');
const expectVulnerabilitiesCollapsed = () => expect(findVulnerabilities()).toHaveLength(0);
const expectVulnerabilitiesExpanded = vulnerabilities => {
const wrappers = findVulnerabilities();
expect(wrappers).toHaveLength(vulnerabilities.length);
wrappers.forEach((vulnerabilityWrapper, i) => {
expect(vulnerabilityWrapper.isVisible()).toBe(true);
expect(vulnerabilityWrapper.props().vulnerability).toEqual(vulnerabilities[i]);
});
expect(findExcessMessage().exists()).toBe(false);
};
const clickToggle = () => {
wrapper.find('.js-vulnerabilities-toggle').vm.$emit('click');
return wrapper.vm.$nextTick();
};
afterEach(() => {
wrapper.destroy();
});
describe('when passed no props', () => {
beforeEach(() => {
factory();
});
it('matches the snapshot', () => {
expect(wrapper.element).toMatchSnapshot();
});
});
describe('when loading', () => {
beforeEach(() => {
factory({
propsData: {
isLoading: true,
},
});
});
it('matches the snapshot', () => {
expect(wrapper.element).toMatchSnapshot();
});
});
describe('when a dependency with no vulnerabilities is loaded', () => {
beforeEach(() => {
factory({
propsData: {
isLoading: false,
dependency: makeDependency({ vulnerabilities: [] }),
},
});
});
it('matches the snapshot', () => {
expect(wrapper.element).toMatchSnapshot();
});
});
describe('when a dependency with vulnerabilities is loaded', () => {
beforeEach(() => {
factory({
propsData: {
isLoading: false,
dependency: makeDependency({ vulnerabilities: mockDataVulnerabilities }),
},
});
});
it('matches the snapshot', () => {
expect(wrapper.element).toMatchSnapshot();
});
describe('when the list of vulnerabilities is expanded', () => {
beforeEach(clickToggle);
it('renders each vulnerability', () => {
expectVulnerabilitiesExpanded(mockDataVulnerabilities);
});
describe('when clicking the toggle ', () => {
beforeEach(clickToggle);
it('closes the list of vulnerabilities', expectVulnerabilitiesCollapsed);
});
describe('when the dependency prop changes', () => {
beforeEach(() => {
wrapper.setProps({
dependency: makeDependency({ vulnerabilities: mockDataVulnerabilities }),
});
return wrapper.vm.$nextTick();
});
it('closes the list of vulnerabilities', expectVulnerabilitiesCollapsed);
});
describe('when the isLoading prop changes', () => {
beforeEach(() => {
wrapper.setProps({
isLoading: true,
});
return wrapper.vm.$nextTick();
});
it('closes the list of vulnerabilities', expectVulnerabilitiesCollapsed);
});
});
});
describe('when a dependency with a huge number vulnerabilities is loaded and expanded', () => {
beforeEach(() => {
const hugeNumberOfVulnerabilities = Array(1 + MAX_DISPLAYED_VULNERABILITIES_PER_DEPENDENCY)
.fill(null)
.map((_, id) => ({ id }));
factory({
propsData: {
isLoading: false,
dependency: makeDependency({ vulnerabilities: hugeNumberOfVulnerabilities }),
},
});
return clickToggle();
});
it('does not render all of them', () => {
expect(findVulnerabilities()).toHaveLength(MAX_DISPLAYED_VULNERABILITIES_PER_DEPENDENCY);
expect(findExcessMessage().isVisible()).toBe(true);
});
});
});
......@@ -6901,11 +6901,6 @@ msgid_plural "Dependencies|%d additional vulnerabilities not shown"
msgstr[0] ""
msgstr[1] ""
msgid "Dependencies|%d vulnerability"
msgid_plural "Dependencies|%d vulnerabilities"
msgstr[0] ""
msgstr[1] ""
msgid "Dependencies|%d vulnerability detected"
msgid_plural "Dependencies|%d vulnerabilities detected"
msgstr[0] ""
......@@ -6941,12 +6936,6 @@ msgstr ""
msgid "Dependencies|Packager"
msgstr ""
msgid "Dependencies|Safe"
msgstr ""
msgid "Dependencies|Status"
msgstr ""
msgid "Dependencies|The %{codeStartTag}dependency_scanning%{codeEndTag} job has failed and cannot generate the list. Please ensure the job is running properly and run the pipeline again."
msgstr ""
......@@ -6956,9 +6945,6 @@ msgstr ""
msgid "Dependencies|Unsupported file(s) detected"
msgstr ""
msgid "Dependencies|Version"
msgstr ""
msgid "Dependencies|Vulnerable components"
msgstr ""
......
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