2021-11-17 15:10:28 +00:00
|
|
|
import { GlDropdown, GlDropdownItem, GlSprintf } from '@gitlab/ui';
|
2021-02-24 21:11:16 +00:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2021-11-17 15:10:28 +00:00
|
|
|
import PipelineArtifacts from '~/pipelines/components/pipelines_list/pipelines_artifacts.vue';
|
2020-05-06 09:10:02 +00:00
|
|
|
|
|
|
|
describe('Pipelines Artifacts dropdown', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
2021-05-07 12:10:27 +00:00
|
|
|
const artifacts = [
|
|
|
|
{
|
|
|
|
name: 'job my-artifact',
|
|
|
|
path: '/download/path',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'job-2 my-artifact-2',
|
|
|
|
path: '/download/path-two',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const pipelineId = 108;
|
|
|
|
|
2021-11-17 15:10:28 +00:00
|
|
|
const createComponent = ({ mockArtifacts = artifacts } = {}) => {
|
2021-02-24 21:11:16 +00:00
|
|
|
wrapper = shallowMount(PipelineArtifacts, {
|
2020-05-06 09:10:02 +00:00
|
|
|
propsData: {
|
2021-05-07 12:10:27 +00:00
|
|
|
pipelineId,
|
2021-11-17 15:10:28 +00:00
|
|
|
artifacts: mockArtifacts,
|
2020-05-06 09:10:02 +00:00
|
|
|
},
|
2021-02-24 21:11:16 +00:00
|
|
|
stubs: {
|
|
|
|
GlSprintf,
|
|
|
|
},
|
2020-05-06 09:10:02 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-05-07 12:10:27 +00:00
|
|
|
const findDropdown = () => wrapper.findComponent(GlDropdown);
|
2021-01-08 18:10:43 +00:00
|
|
|
const findFirstGlDropdownItem = () => wrapper.find(GlDropdownItem);
|
|
|
|
const findAllGlDropdownItems = () => wrapper.find(GlDropdown).findAll(GlDropdownItem);
|
2020-05-06 09:10:02 +00:00
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render a dropdown with all the provided artifacts', () => {
|
2021-11-17 15:10:28 +00:00
|
|
|
createComponent();
|
2021-05-07 12:10:27 +00:00
|
|
|
|
|
|
|
expect(findAllGlDropdownItems()).toHaveLength(artifacts.length);
|
2020-05-06 09:10:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render a link with the provided path', () => {
|
2021-11-17 15:10:28 +00:00
|
|
|
createComponent();
|
2020-05-06 09:10:02 +00:00
|
|
|
|
2021-05-07 12:10:27 +00:00
|
|
|
expect(findFirstGlDropdownItem().attributes('href')).toBe(artifacts[0].path);
|
2021-10-08 21:09:48 +00:00
|
|
|
expect(findFirstGlDropdownItem().text()).toBe(artifacts[0].name);
|
2021-05-07 12:10:27 +00:00
|
|
|
});
|
|
|
|
|
2021-11-17 15:10:28 +00:00
|
|
|
describe('with no artifacts', () => {
|
|
|
|
it('should not render the dropdown', () => {
|
|
|
|
createComponent({ mockArtifacts: [] });
|
2021-05-07 12:10:27 +00:00
|
|
|
|
2021-11-17 15:10:28 +00:00
|
|
|
expect(findDropdown().exists()).toBe(false);
|
2021-05-07 12:10:27 +00:00
|
|
|
});
|
2020-05-06 09:10:02 +00:00
|
|
|
});
|
|
|
|
});
|