debian-mirror-gitlab/spec/frontend/pipelines/pipeline_url_spec.js

237 lines
7.9 KiB
JavaScript
Raw Normal View History

2022-04-04 11:22:00 +05:30
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
2020-01-01 13:55:28 +05:30
import { trimText } from 'helpers/text_helper';
2020-07-28 23:09:34 +05:30
import PipelineUrlComponent from '~/pipelines/components/pipelines_list/pipeline_url.vue';
2022-04-04 11:22:00 +05:30
import { mockPipeline, mockPipelineBranch, mockPipelineTag } from './mock_data';
2020-01-01 13:55:28 +05:30
2021-04-17 20:07:23 +05:30
const projectPath = 'test/test';
2020-01-01 13:55:28 +05:30
describe('Pipeline Url Component', () => {
let wrapper;
2022-04-04 11:22:00 +05:30
const findTableCell = () => wrapper.findByTestId('pipeline-url-table-cell');
const findPipelineUrlLink = () => wrapper.findByTestId('pipeline-url-link');
const findScheduledTag = () => wrapper.findByTestId('pipeline-url-scheduled');
const findLatestTag = () => wrapper.findByTestId('pipeline-url-latest');
const findYamlTag = () => wrapper.findByTestId('pipeline-url-yaml');
const findFailureTag = () => wrapper.findByTestId('pipeline-url-failure');
const findAutoDevopsTag = () => wrapper.findByTestId('pipeline-url-autodevops');
const findAutoDevopsTagLink = () => wrapper.findByTestId('pipeline-url-autodevops-link');
const findStuckTag = () => wrapper.findByTestId('pipeline-url-stuck');
const findDetachedTag = () => wrapper.findByTestId('pipeline-url-detached');
const findForkTag = () => wrapper.findByTestId('pipeline-url-fork');
const findTrainTag = () => wrapper.findByTestId('pipeline-url-train');
const findRefName = () => wrapper.findByTestId('merge-request-ref');
const findCommitShortSha = () => wrapper.findByTestId('commit-short-sha');
const findCommitIcon = () => wrapper.findByTestId('commit-icon');
const findCommitIconType = () => wrapper.findByTestId('commit-icon-type');
const findCommitTitleContainer = () => wrapper.findByTestId('commit-title-container');
const findCommitTitle = (commitWrapper) => commitWrapper.find('[data-testid="commit-title"]');
const defaultProps = mockPipeline(projectPath);
const createComponent = (props, rearrangePipelinesTable = false) => {
wrapper = shallowMountExtended(PipelineUrlComponent, {
2020-07-28 23:09:34 +05:30
propsData: { ...defaultProps, ...props },
2021-02-22 17:27:13 +05:30
provide: {
2021-04-17 20:07:23 +05:30
targetProjectFullPath: projectPath,
2022-04-04 11:22:00 +05:30
glFeatures: {
rearrangePipelinesTable,
},
2021-02-22 17:27:13 +05:30
},
2020-01-01 13:55:28 +05:30
});
};
afterEach(() => {
wrapper.destroy();
2020-07-28 23:09:34 +05:30
wrapper = null;
2020-01-01 13:55:28 +05:30
});
2022-04-04 11:22:00 +05:30
describe('with the rearrangePipelinesTable feature flag turned off', () => {
it('should render pipeline url table cell', () => {
createComponent();
2020-07-28 23:09:34 +05:30
2022-04-04 11:22:00 +05:30
expect(findTableCell().exists()).toBe(true);
});
2020-07-28 23:09:34 +05:30
2022-04-04 11:22:00 +05:30
it('should render a link the provided path and id', () => {
createComponent();
2020-07-28 23:09:34 +05:30
2022-04-04 11:22:00 +05:30
expect(findPipelineUrlLink().attributes('href')).toBe('foo');
2020-07-28 23:09:34 +05:30
2022-04-04 11:22:00 +05:30
expect(findPipelineUrlLink().text()).toBe('#1');
});
2020-07-28 23:09:34 +05:30
2022-04-04 11:22:00 +05:30
it('should not render tags when flags are not set', () => {
createComponent();
expect(findStuckTag().exists()).toBe(false);
expect(findLatestTag().exists()).toBe(false);
expect(findYamlTag().exists()).toBe(false);
expect(findAutoDevopsTag().exists()).toBe(false);
expect(findFailureTag().exists()).toBe(false);
expect(findScheduledTag().exists()).toBe(false);
expect(findForkTag().exists()).toBe(false);
expect(findTrainTag().exists()).toBe(false);
});
2021-04-17 20:07:23 +05:30
2022-04-04 11:22:00 +05:30
it('should render the stuck tag when flag is provided', () => {
const stuckPipeline = defaultProps.pipeline;
stuckPipeline.flags.stuck = true;
createComponent({
...stuckPipeline.pipeline,
});
expect(findStuckTag().text()).toContain('stuck');
2020-01-01 13:55:28 +05:30
});
2022-04-04 11:22:00 +05:30
it('should render latest tag when flag is provided', () => {
const latestPipeline = defaultProps.pipeline;
latestPipeline.flags.latest = true;
2020-01-01 13:55:28 +05:30
2022-04-04 11:22:00 +05:30
createComponent({
...latestPipeline,
});
expect(findLatestTag().text()).toContain('latest');
2020-01-01 13:55:28 +05:30
});
2022-04-04 11:22:00 +05:30
it('should render a yaml badge when it is invalid', () => {
const yamlPipeline = defaultProps.pipeline;
yamlPipeline.flags.yaml_errors = true;
2020-01-01 13:55:28 +05:30
2022-04-04 11:22:00 +05:30
createComponent({
...yamlPipeline,
});
expect(findYamlTag().text()).toContain('yaml invalid');
2020-01-01 13:55:28 +05:30
});
2022-04-04 11:22:00 +05:30
it('should render an autodevops badge when flag is provided', () => {
const autoDevopsPipeline = defaultProps.pipeline;
autoDevopsPipeline.flags.auto_devops = true;
2020-01-01 13:55:28 +05:30
2022-04-04 11:22:00 +05:30
createComponent({
...autoDevopsPipeline,
});
expect(trimText(findAutoDevopsTag().text())).toBe('Auto DevOps');
expect(findAutoDevopsTagLink().attributes()).toMatchObject({
href: '/help/topics/autodevops/index.md',
target: '_blank',
});
2020-07-28 23:09:34 +05:30
});
2020-01-01 13:55:28 +05:30
2022-04-04 11:22:00 +05:30
it('should render a detached badge when flag is provided', () => {
const detachedMRPipeline = defaultProps.pipeline;
detachedMRPipeline.flags.detached_merge_request_pipeline = true;
createComponent({
...detachedMRPipeline,
});
2021-04-17 20:07:23 +05:30
2022-04-04 11:22:00 +05:30
expect(findDetachedTag().text()).toContain('detached');
2021-04-17 20:07:23 +05:30
});
2020-01-01 13:55:28 +05:30
2022-04-04 11:22:00 +05:30
it('should render error badge when pipeline has a failure reason set', () => {
const failedPipeline = defaultProps.pipeline;
failedPipeline.flags.failure_reason = true;
failedPipeline.failure_reason = 'some reason';
createComponent({
...failedPipeline,
});
expect(findFailureTag().text()).toContain('error');
expect(findFailureTag().attributes('title')).toContain('some reason');
2020-01-01 13:55:28 +05:30
});
2022-04-04 11:22:00 +05:30
it('should render scheduled badge when pipeline was triggered by a schedule', () => {
const scheduledPipeline = defaultProps.pipeline;
scheduledPipeline.source = 'schedule';
2020-01-01 13:55:28 +05:30
2022-04-04 11:22:00 +05:30
createComponent({
...scheduledPipeline,
});
expect(findScheduledTag().exists()).toBe(true);
expect(findScheduledTag().text()).toContain('Scheduled');
2020-01-01 13:55:28 +05:30
});
2022-04-04 11:22:00 +05:30
it('should render the fork badge when the pipeline was run in a fork', () => {
const forkedPipeline = defaultProps.pipeline;
forkedPipeline.project.full_path = '/test/forked';
2020-07-28 23:09:34 +05:30
2022-04-04 11:22:00 +05:30
createComponent({
...forkedPipeline,
});
expect(findForkTag().exists()).toBe(true);
expect(findForkTag().text()).toBe('fork');
2020-07-28 23:09:34 +05:30
});
2022-04-04 11:22:00 +05:30
it('should render the train badge when the pipeline is a merge train pipeline', () => {
const mergeTrainPipeline = defaultProps.pipeline;
mergeTrainPipeline.flags.merge_train_pipeline = true;
2021-03-11 19:13:27 +05:30
2022-04-04 11:22:00 +05:30
createComponent({
...mergeTrainPipeline,
});
expect(findTrainTag().text()).toContain('train');
2021-02-22 17:27:13 +05:30
});
2022-04-04 11:22:00 +05:30
it('should not render the train badge when the pipeline is not a merge train pipeline', () => {
const mergeTrainPipeline = defaultProps.pipeline;
mergeTrainPipeline.flags.merge_train_pipeline = false;
2021-03-11 19:13:27 +05:30
2022-04-04 11:22:00 +05:30
createComponent({
...mergeTrainPipeline,
});
expect(findTrainTag().exists()).toBe(false);
2021-03-11 19:13:27 +05:30
});
2022-04-04 11:22:00 +05:30
it('should not render the commit wrapper and commit-short-sha', () => {
createComponent();
expect(findCommitTitleContainer().exists()).toBe(false);
expect(findCommitShortSha().exists()).toBe(false);
});
2021-03-11 19:13:27 +05:30
});
2022-04-04 11:22:00 +05:30
describe('with the rearrangePipelinesTable feature flag turned on', () => {
it('should render the commit title, commit reference and commit-short-sha', () => {
createComponent({}, true);
const commitWrapper = findCommitTitleContainer();
expect(findCommitTitle(commitWrapper).exists()).toBe(true);
expect(findRefName().exists()).toBe(true);
expect(findCommitShortSha().exists()).toBe(true);
2021-03-11 19:13:27 +05:30
});
2022-04-04 11:22:00 +05:30
it('should render commit icon tooltip', () => {
createComponent({}, true);
expect(findCommitIcon().attributes('title')).toBe('Commit');
});
it.each`
pipeline | expectedTitle
${mockPipelineTag()} | ${'Tag'}
${mockPipelineBranch()} | ${'Branch'}
${mockPipeline()} | ${'Merge Request'}
`(
'should render tooltip $expectedTitle for commit icon type',
({ pipeline, expectedTitle }) => {
createComponent(pipeline, true);
expect(findCommitIconType().attributes('title')).toBe(expectedTitle);
},
);
2021-03-11 19:13:27 +05:30
});
2020-01-01 13:55:28 +05:30
});