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

228 lines
6.7 KiB
JavaScript
Raw Normal View History

2019-12-26 22:10:19 +05:30
import { mount } from '@vue/test-utils';
2020-07-28 23:09:34 +05:30
import PipelinesTableRowComponent from '~/pipelines/components/pipelines_list/pipelines_table_row.vue';
2018-11-08 19:23:39 +05:30
import eventHub from '~/pipelines/event_hub';
2017-09-10 17:25:29 +05:30
describe('Pipelines Table Row', () => {
const jsonFixtureName = 'pipelines/pipelines.json';
2019-12-26 22:10:19 +05:30
const createWrapper = pipeline =>
mount(PipelinesTableRowComponent, {
2017-09-10 17:25:29 +05:30
propsData: {
pipeline,
2018-03-17 18:26:18 +05:30
autoDevopsHelpPath: 'foo',
viewType: 'root',
2017-09-10 17:25:29 +05:30
},
2019-12-26 22:10:19 +05:30
});
2017-09-10 17:25:29 +05:30
2019-12-26 22:10:19 +05:30
let wrapper;
2017-09-10 17:25:29 +05:30
let pipeline;
let pipelineWithoutAuthor;
let pipelineWithoutCommit;
preloadFixtures(jsonFixtureName);
beforeEach(() => {
2018-11-08 19:23:39 +05:30
const { pipelines } = getJSONFixture(jsonFixtureName);
2018-03-17 18:26:18 +05:30
pipeline = pipelines.find(p => p.user !== null && p.commit !== null);
pipelineWithoutAuthor = pipelines.find(p => p.user === null && p.commit !== null);
pipelineWithoutCommit = pipelines.find(p => p.user === null && p.commit === null);
2017-09-10 17:25:29 +05:30
});
afterEach(() => {
2019-12-26 22:10:19 +05:30
wrapper.destroy();
wrapper = null;
2017-09-10 17:25:29 +05:30
});
it('should render a table row', () => {
2019-12-26 22:10:19 +05:30
wrapper = createWrapper(pipeline);
2018-12-13 13:39:08 +05:30
2019-12-26 22:10:19 +05:30
expect(wrapper.attributes('class')).toContain('gl-responsive-table-row');
2017-09-10 17:25:29 +05:30
});
describe('status column', () => {
beforeEach(() => {
2019-12-26 22:10:19 +05:30
wrapper = createWrapper(pipeline);
2017-09-10 17:25:29 +05:30
});
it('should render a pipeline link', () => {
2019-12-26 22:10:19 +05:30
expect(wrapper.find('.table-section.commit-link a').attributes('href')).toEqual(
pipeline.path,
);
2017-09-10 17:25:29 +05:30
});
it('should render status text', () => {
2019-12-26 22:10:19 +05:30
expect(wrapper.find('.table-section.commit-link a').text()).toContain(
2018-11-08 19:23:39 +05:30
pipeline.details.status.text,
);
2017-09-10 17:25:29 +05:30
});
});
describe('information column', () => {
beforeEach(() => {
2019-12-26 22:10:19 +05:30
wrapper = createWrapper(pipeline);
2017-09-10 17:25:29 +05:30
});
it('should render a pipeline link', () => {
2019-12-26 22:10:19 +05:30
expect(wrapper.find('.table-section:nth-child(2) a').attributes('href')).toEqual(
pipeline.path,
);
2017-09-10 17:25:29 +05:30
});
it('should render pipeline ID', () => {
2019-12-26 22:10:19 +05:30
expect(wrapper.find('.table-section:nth-child(2) a > span').text()).toEqual(
`#${pipeline.id}`,
);
2017-09-10 17:25:29 +05:30
});
describe('when a user is provided', () => {
it('should render user information', () => {
expect(
2019-12-26 22:10:19 +05:30
wrapper.find('.table-section:nth-child(3) .js-pipeline-url-user').attributes('href'),
2017-09-10 17:25:29 +05:30
).toEqual(pipeline.user.path);
expect(
2019-12-26 22:10:19 +05:30
wrapper
.find('.table-section:nth-child(3) .js-user-avatar-image-toolip')
.text()
.trim(),
2017-09-10 17:25:29 +05:30
).toEqual(pipeline.user.name);
});
});
});
describe('commit column', () => {
it('should render link to commit', () => {
2019-12-26 22:10:19 +05:30
wrapper = createWrapper(pipeline);
2017-09-10 17:25:29 +05:30
2019-12-26 22:10:19 +05:30
const commitLink = wrapper.find('.branch-commit .commit-sha');
2018-12-13 13:39:08 +05:30
2019-12-26 22:10:19 +05:30
expect(commitLink.attributes('href')).toEqual(pipeline.commit.commit_path);
2017-09-10 17:25:29 +05:30
});
const findElements = () => {
2019-12-26 22:10:19 +05:30
const commitTitleElement = wrapper.find('.branch-commit .commit-title');
const commitAuthorElement = commitTitleElement.find('a.avatar-image-container');
2017-09-10 17:25:29 +05:30
2019-12-26 22:10:19 +05:30
if (!commitAuthorElement.exists()) {
return {
commitAuthorElement,
};
2017-09-10 17:25:29 +05:30
}
2019-12-26 22:10:19 +05:30
const commitAuthorLink = commitAuthorElement.attributes('href');
2018-11-08 19:23:39 +05:30
const commitAuthorName = commitAuthorElement
2019-12-26 22:10:19 +05:30
.find('.js-user-avatar-image-toolip')
.text()
.trim();
return {
commitAuthorElement,
commitAuthorLink,
commitAuthorName,
};
2017-09-10 17:25:29 +05:30
};
it('renders nothing without commit', () => {
expect(pipelineWithoutCommit.commit).toBe(null);
2019-12-26 22:10:19 +05:30
wrapper = createWrapper(pipelineWithoutCommit);
2017-09-10 17:25:29 +05:30
const { commitAuthorElement } = findElements();
2019-12-26 22:10:19 +05:30
expect(commitAuthorElement.exists()).toBe(false);
2017-09-10 17:25:29 +05:30
});
it('renders commit author', () => {
2019-12-26 22:10:19 +05:30
wrapper = createWrapper(pipeline);
2017-09-10 17:25:29 +05:30
const { commitAuthorLink, commitAuthorName } = findElements();
expect(commitAuthorLink).toEqual(pipeline.commit.author.path);
expect(commitAuthorName).toEqual(pipeline.commit.author.username);
});
it('renders commit with unregistered author', () => {
expect(pipelineWithoutAuthor.commit.author).toBe(null);
2019-12-26 22:10:19 +05:30
wrapper = createWrapper(pipelineWithoutAuthor);
2017-09-10 17:25:29 +05:30
const { commitAuthorLink, commitAuthorName } = findElements();
expect(commitAuthorLink).toEqual(`mailto:${pipelineWithoutAuthor.commit.author_email}`);
expect(commitAuthorName).toEqual(pipelineWithoutAuthor.commit.author_name);
});
});
describe('stages column', () => {
beforeEach(() => {
2019-12-26 22:10:19 +05:30
wrapper = createWrapper(pipeline);
2017-09-10 17:25:29 +05:30
});
it('should render an icon for each stage', () => {
expect(
2019-12-26 22:10:19 +05:30
wrapper.findAll('.table-section:nth-child(4) .js-builds-dropdown-button').length,
2017-09-10 17:25:29 +05:30
).toEqual(pipeline.details.stages.length);
});
});
describe('actions column', () => {
2018-12-05 23:21:45 +05:30
const scheduledJobAction = {
name: 'some scheduled job',
};
2017-09-10 17:25:29 +05:30
beforeEach(() => {
2020-05-24 23:13:21 +05:30
const withActions = { ...pipeline };
2018-12-05 23:21:45 +05:30
withActions.details.scheduled_actions = [scheduledJobAction];
2018-11-08 19:23:39 +05:30
withActions.flags.cancelable = true;
withActions.flags.retryable = true;
withActions.cancel_path = '/cancel';
withActions.retry_path = '/retry';
2019-12-26 22:10:19 +05:30
wrapper = createWrapper(withActions);
2017-09-10 17:25:29 +05:30
});
it('should render the provided actions', () => {
2019-12-26 22:10:19 +05:30
expect(wrapper.find('.js-pipelines-retry-button').exists()).toBe(true);
expect(wrapper.find('.js-pipelines-cancel-button').exists()).toBe(true);
const dropdownMenu = wrapper.find('.dropdown-menu');
2018-12-13 13:39:08 +05:30
2019-12-26 22:10:19 +05:30
expect(dropdownMenu.text()).toContain(scheduledJobAction.name);
2018-11-08 19:23:39 +05:30
});
it('emits `retryPipeline` event when retry button is clicked and toggles loading', () => {
eventHub.$on('retryPipeline', endpoint => {
2019-12-26 22:10:19 +05:30
expect(endpoint).toBe('/retry');
2018-11-08 19:23:39 +05:30
});
2019-12-26 22:10:19 +05:30
wrapper.find('.js-pipelines-retry-button').trigger('click');
expect(wrapper.vm.isRetrying).toBe(true);
2018-11-08 19:23:39 +05:30
});
it('emits `openConfirmationModal` event when cancel button is clicked and toggles loading', () => {
eventHub.$once('openConfirmationModal', data => {
2019-07-07 11:18:12 +05:30
const { id, ref, commit } = pipeline;
2019-12-26 22:10:19 +05:30
expect(data.endpoint).toBe('/cancel');
expect(data.pipeline).toEqual(
expect.objectContaining({
id,
ref,
commit,
}),
);
2018-11-08 19:23:39 +05:30
});
2019-12-26 22:10:19 +05:30
wrapper.find('.js-pipelines-cancel-button').trigger('click');
2018-11-08 19:23:39 +05:30
});
it('renders a loading icon when `cancelingPipeline` matches pipeline id', done => {
2019-12-26 22:10:19 +05:30
wrapper.setProps({ cancelingPipeline: pipeline.id });
wrapper.vm
2018-12-13 13:39:08 +05:30
.$nextTick()
2018-11-08 19:23:39 +05:30
.then(() => {
2019-12-26 22:10:19 +05:30
expect(wrapper.vm.isCancelling).toBe(true);
2018-11-08 19:23:39 +05:30
})
.then(done)
.catch(done.fail);
2017-09-10 17:25:29 +05:30
});
});
});