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