debian-mirror-gitlab/spec/frontend/ci/artifacts/components/artifact_row_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

106 lines
3.5 KiB
JavaScript
Raw Normal View History

2023-06-20 00:43:36 +05:30
import { GlBadge, GlFriendlyWrap, GlFormCheckbox } from '@gitlab/ui';
import mockGetJobArtifactsResponse from 'test_fixtures/graphql/ci/artifacts/graphql/queries/get_job_artifacts.query.graphql.json';
2023-01-13 00:05:48 +05:30
import { numberToHumanSize } from '~/lib/utils/number_utils';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import waitForPromises from 'helpers/wait_for_promises';
2023-06-20 00:43:36 +05:30
import ArtifactRow from '~/ci/artifacts/components/artifact_row.vue';
import { BULK_DELETE_FEATURE_FLAG } from '~/ci/artifacts/constants';
2023-01-13 00:05:48 +05:30
describe('ArtifactRow component', () => {
let wrapper;
const artifact = mockGetJobArtifactsResponse.data.project.jobs.nodes[0].artifacts.nodes[0];
const findName = () => wrapper.findByTestId('job-artifact-row-name');
const findBadge = () => wrapper.findComponent(GlBadge);
const findSize = () => wrapper.findByTestId('job-artifact-row-size');
const findDownloadButton = () => wrapper.findByTestId('job-artifact-row-download-button');
const findDeleteButton = () => wrapper.findByTestId('job-artifact-row-delete-button');
2023-05-27 22:25:52 +05:30
const findCheckbox = () => wrapper.findComponent(GlFormCheckbox);
2023-01-13 00:05:48 +05:30
2023-05-27 22:25:52 +05:30
const createComponent = ({ canDestroyArtifacts = true, glFeatures = {} } = {}) => {
2023-03-17 16:20:25 +05:30
wrapper = shallowMountExtended(ArtifactRow, {
2023-01-13 00:05:48 +05:30
propsData: {
artifact,
2023-05-27 22:25:52 +05:30
isSelected: false,
2023-01-13 00:05:48 +05:30
isLoading: false,
isLastRow: false,
},
2023-05-27 22:25:52 +05:30
provide: { canDestroyArtifacts, glFeatures },
2023-06-20 00:43:36 +05:30
stubs: { GlBadge, GlFriendlyWrap },
2023-01-13 00:05:48 +05:30
});
};
describe('artifact details', () => {
beforeEach(async () => {
createComponent();
await waitForPromises();
});
it('displays the artifact name and type', () => {
expect(findName().text()).toContain(artifact.name);
expect(findBadge().text()).toBe(artifact.fileType.toLowerCase());
});
it('displays the artifact size', () => {
expect(findSize().text()).toBe(numberToHumanSize(artifact.size));
});
it('displays the download button as a link to the download path', () => {
expect(findDownloadButton().attributes('href')).toBe(artifact.downloadPath);
});
2023-03-17 16:20:25 +05:30
});
describe('delete button', () => {
it('does not show when user does not have permission', () => {
createComponent({ canDestroyArtifacts: false });
expect(findDeleteButton().exists()).toBe(false);
});
it('shows when user has permission', () => {
createComponent();
2023-01-13 00:05:48 +05:30
expect(findDeleteButton().exists()).toBe(true);
});
2023-03-17 16:20:25 +05:30
it('emits the delete event when clicked', async () => {
createComponent();
2023-01-13 00:05:48 +05:30
expect(wrapper.emitted('delete')).toBeUndefined();
2023-06-20 00:43:36 +05:30
findDeleteButton().vm.$emit('click');
2023-01-13 00:05:48 +05:30
await waitForPromises();
expect(wrapper.emitted('delete')).toBeDefined();
});
});
2023-05-27 22:25:52 +05:30
describe('bulk delete checkbox', () => {
describe('with permission and feature flag enabled', () => {
beforeEach(() => {
createComponent({ glFeatures: { [BULK_DELETE_FEATURE_FLAG]: true } });
});
it('emits selectArtifact when toggled', () => {
findCheckbox().vm.$emit('input', true);
expect(wrapper.emitted('selectArtifact')).toStrictEqual([[artifact, true]]);
});
});
it('is not shown without permission', () => {
createComponent({ canDestroyArtifacts: false });
expect(findCheckbox().exists()).toBe(false);
});
it('is not shown with feature flag disabled', () => {
createComponent();
expect(findCheckbox().exists()).toBe(false);
});
});
2023-01-13 00:05:48 +05:30
});