Commit 775f1c63 authored by Alexander Turinske's avatar Alexander Turinske Committed by Natalia Tepluhina

Disable location link for container images

parent bc94314b
...@@ -25,9 +25,15 @@ export default { ...@@ -25,9 +25,15 @@ export default {
ancestors() { ancestors() {
return this.location.ancestors || []; return this.location.ancestors || [];
}, },
locationComponent() {
return this.isContainerImageDependency ? 'span' : GlLink;
},
hasAncestors() { hasAncestors() {
return this.ancestors.length > 0; return this.ancestors.length > 0;
}, },
isContainerImageDependency() {
return this.location.path.includes('container-image:');
},
isTopLevelDependency() { isTopLevelDependency() {
return this.location.top_level; return this.location.top_level;
}, },
...@@ -51,15 +57,20 @@ export default { ...@@ -51,15 +57,20 @@ export default {
<gl-intersperse separator=" / " class="gl-text-gray-500"> <gl-intersperse separator=" / " class="gl-text-gray-500">
<!-- We need to put an extra span to avoid separator between path & top level label --> <!-- We need to put an extra span to avoid separator between path & top level label -->
<span> <span>
<gl-link class="gl-display-inline-block gl-lg-display-block!" :href="location.blob_path"> <component
<gl-icon name="doc-text" /> :is="locationComponent"
data-testid="dependency-path"
class="gl-display-inline-block gl-lg-display-block!"
:href="location.blob_path"
>
<gl-icon v-if="!isContainerImageDependency" name="doc-text" />
<gl-truncate <gl-truncate
class="gl-lg-max-w-80p gl-display-none gl-lg-display-inline-flex" class="gl-lg-max-w-80p gl-display-none gl-lg-display-inline-flex"
:text="location.path" :text="location.path"
with-tooltip with-tooltip
/> />
<span class="gl-lg-display-none">{{ location.path }}</span> <span class="gl-lg-display-none">{{ location.path }}</span>
</gl-link> </component>
<span v-if="isTopLevelDependency">{{ s__('Dependencies|(top level)') }}</span> <span v-if="isTopLevelDependency">{{ s__('Dependencies|(top level)') }}</span>
</span> </span>
......
import { GlLink, GlIntersperse, GlPopover } from '@gitlab/ui'; import { GlLink, GlIcon, GlIntersperse, GlPopover } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import DependencyLocation from 'ee/dependencies/components/dependency_location.vue'; import DependencyLocation from 'ee/dependencies/components/dependency_location.vue';
import DependencyPathViewer from 'ee/dependencies/components/dependency_path_viewer.vue'; import DependencyPathViewer from 'ee/dependencies/components/dependency_path_viewer.vue';
...@@ -16,6 +16,9 @@ describe('Dependency Location component', () => { ...@@ -16,6 +16,9 @@ describe('Dependency Location component', () => {
}); });
}; };
const findIcon = () => wrapper.find(GlIcon);
const findPath = () => wrapper.find('[data-testid="dependency-path"]');
const findPathLink = () => wrapper.find(GlLink);
const findPopover = () => wrapper.find(GlPopover); const findPopover = () => wrapper.find(GlPopover);
afterEach(() => { afterEach(() => {
...@@ -23,11 +26,12 @@ describe('Dependency Location component', () => { ...@@ -23,11 +26,12 @@ describe('Dependency Location component', () => {
}); });
it.each` it.each`
name | location | path name | location | path
${'no path'} | ${Paths.noPath} | ${'package.json'} ${'container image path'} | ${Paths.containerImagePath} | ${Paths.containerImagePath.path}
${'top level path'} | ${Paths.topLevelPath} | ${'package.json (top level)'} ${'no path'} | ${Paths.noPath} | ${Paths.noPath.path}
${'short path'} | ${Paths.shortPath} | ${'package.json / swell 1.2 / emmajsq 10.11'} ${'top level path'} | ${Paths.topLevelPath} | ${'package.json (top level)'}
${'long path'} | ${Paths.longPath} | ${'package.json / swell 1.2 / emmajsq 10.11 / 3 more'} ${'short path'} | ${Paths.shortPath} | ${'package.json / swell 1.2 / emmajsq 10.11'}
${'long path'} | ${Paths.longPath} | ${'package.json / swell 1.2 / emmajsq 10.11 / 3 more'}
`('shows dependency path for $name', ({ location, path }) => { `('shows dependency path for $name', ({ location, path }) => {
createComponent({ createComponent({
propsData: { propsData: {
...@@ -67,8 +71,8 @@ describe('Dependency Location component', () => { ...@@ -67,8 +71,8 @@ describe('Dependency Location component', () => {
}); });
}); });
it('should show the depedency name and link', () => { it('should show the dependency name and link', () => {
const locationLink = wrapper.find(GlLink); const locationLink = findPathLink();
expect(locationLink.attributes().href).toBe('test.link'); expect(locationLink.attributes().href).toBe('test.link');
expect(locationLink.text()).toBe('package.json'); expect(locationLink.text()).toBe('package.json');
}); });
...@@ -81,5 +85,28 @@ describe('Dependency Location component', () => { ...@@ -81,5 +85,28 @@ describe('Dependency Location component', () => {
it('should not render the popover', () => { it('should not render the popover', () => {
expect(findPopover().exists()).toBe(false); expect(findPopover().exists()).toBe(false);
}); });
it('should render the icon', () => {
expect(findIcon().exists()).toBe(true);
});
});
describe('dependency with container image dependency path', () => {
beforeEach(() => {
createComponent({
propsData: {
location: Paths.containerImagePath,
},
});
});
it('should render the dependency name not as a link', () => {
expect(findPathLink().exists()).toBe(false);
expect(findPath().text()).toBe(Paths.containerImagePath.path);
});
it('should not render the icon', () => {
expect(findIcon().exists()).toBe(false);
});
}); });
}); });
export const containerImagePath = {
ancestors: null,
top_level: null,
blob_path: 'test.link',
path: 'container-image:nginx:1.17',
};
export const longPath = { export const longPath = {
ancestors: [ ancestors: [
{ {
......
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