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

219 lines
6.9 KiB
JavaScript
Raw Normal View History

2017-09-10 17:25:29 +05:30
import Vue from 'vue';
import tableRowComp from '~/pipelines/components/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';
2018-11-08 19:23:39 +05:30
const buildComponent = pipeline => {
2017-09-10 17:25:29 +05:30
const PipelinesTableRowComponent = Vue.extend(tableRowComp);
return new PipelinesTableRowComponent({
el: document.querySelector('.test-dom-element'),
propsData: {
pipeline,
2018-03-17 18:26:18 +05:30
autoDevopsHelpPath: 'foo',
viewType: 'root',
2017-09-10 17:25:29 +05:30
},
}).$mount();
};
let component;
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(() => {
component.$destroy();
});
it('should render a table row', () => {
component = buildComponent(pipeline);
2018-12-13 13:39:08 +05:30
2017-09-10 17:25:29 +05:30
expect(component.$el.getAttribute('class')).toContain('gl-responsive-table-row');
});
describe('status column', () => {
beforeEach(() => {
component = buildComponent(pipeline);
});
it('should render a pipeline link', () => {
expect(
component.$el.querySelector('.table-section.commit-link a').getAttribute('href'),
).toEqual(pipeline.path);
});
it('should render status text', () => {
2018-11-08 19:23:39 +05:30
expect(component.$el.querySelector('.table-section.commit-link a').textContent).toContain(
pipeline.details.status.text,
);
2017-09-10 17:25:29 +05:30
});
});
describe('information column', () => {
beforeEach(() => {
component = buildComponent(pipeline);
});
it('should render a pipeline link', () => {
expect(
component.$el.querySelector('.table-section:nth-child(2) a').getAttribute('href'),
).toEqual(pipeline.path);
});
it('should render pipeline ID', () => {
expect(
component.$el.querySelector('.table-section:nth-child(2) a > span').textContent,
).toEqual(`#${pipeline.id}`);
});
describe('when a user is provided', () => {
it('should render user information', () => {
expect(
2018-11-08 19:23:39 +05:30
component.$el
2019-07-31 22:56:46 +05:30
.querySelector('.table-section:nth-child(3) .js-pipeline-url-user')
2018-11-08 19:23:39 +05:30
.getAttribute('href'),
2017-09-10 17:25:29 +05:30
).toEqual(pipeline.user.path);
expect(
2018-11-08 19:23:39 +05:30
component.$el
2019-07-31 22:56:46 +05:30
.querySelector('.table-section:nth-child(3) .js-user-avatar-image-toolip')
2018-12-13 13:39:08 +05:30
.textContent.trim(),
2017-09-10 17:25:29 +05:30
).toEqual(pipeline.user.name);
});
});
});
describe('commit column', () => {
it('should render link to commit', () => {
component = buildComponent(pipeline);
const commitLink = component.$el.querySelector('.branch-commit .commit-sha');
2018-12-13 13:39:08 +05:30
2017-09-10 17:25:29 +05:30
expect(commitLink.getAttribute('href')).toEqual(pipeline.commit.commit_path);
});
const findElements = () => {
const commitTitleElement = component.$el.querySelector('.branch-commit .commit-title');
const commitAuthorElement = commitTitleElement.querySelector('a.avatar-image-container');
if (!commitAuthorElement) {
return { commitAuthorElement };
}
const commitAuthorLink = commitAuthorElement.getAttribute('href');
2018-11-08 19:23:39 +05:30
const commitAuthorName = commitAuthorElement
2018-12-13 13:39:08 +05:30
.querySelector('.js-user-avatar-image-toolip')
.textContent.trim();
2017-09-10 17:25:29 +05:30
return { commitAuthorElement, commitAuthorLink, commitAuthorName };
};
it('renders nothing without commit', () => {
expect(pipelineWithoutCommit.commit).toBe(null);
component = buildComponent(pipelineWithoutCommit);
const { commitAuthorElement } = findElements();
expect(commitAuthorElement).toBe(null);
});
it('renders commit author', () => {
component = buildComponent(pipeline);
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);
component = buildComponent(pipelineWithoutAuthor);
const { commitAuthorLink, commitAuthorName } = findElements();
expect(commitAuthorLink).toEqual(`mailto:${pipelineWithoutAuthor.commit.author_email}`);
expect(commitAuthorName).toEqual(pipelineWithoutAuthor.commit.author_name);
});
});
describe('stages column', () => {
beforeEach(() => {
component = buildComponent(pipeline);
});
it('should render an icon for each stage', () => {
expect(
2018-11-08 19:23:39 +05:30
component.$el.querySelectorAll('.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(() => {
2018-11-08 19:23:39 +05:30
const withActions = Object.assign({}, 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';
component = buildComponent(withActions);
2017-09-10 17:25:29 +05:30
});
it('should render the provided actions', () => {
2018-11-08 19:23:39 +05:30
expect(component.$el.querySelector('.js-pipelines-retry-button')).not.toBeNull();
expect(component.$el.querySelector('.js-pipelines-cancel-button')).not.toBeNull();
2018-12-05 23:21:45 +05:30
const dropdownMenu = component.$el.querySelectorAll('.dropdown-menu');
2018-12-13 13:39:08 +05:30
2018-12-05 23:21:45 +05:30
expect(dropdownMenu).toContainText(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 => {
expect(endpoint).toEqual('/retry');
});
component.$el.querySelector('.js-pipelines-retry-button').click();
2018-12-13 13:39:08 +05:30
2018-11-08 19:23:39 +05:30
expect(component.isRetrying).toEqual(true);
});
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;
2018-11-08 19:23:39 +05:30
expect(data.endpoint).toEqual('/cancel');
2019-07-07 11:18:12 +05:30
expect(data.pipeline).toEqual(jasmine.objectContaining({ id, ref, commit }));
2018-11-08 19:23:39 +05:30
});
component.$el.querySelector('.js-pipelines-cancel-button').click();
});
it('renders a loading icon when `cancelingPipeline` matches pipeline id', done => {
component.cancelingPipeline = pipeline.id;
2018-12-13 13:39:08 +05:30
component
.$nextTick()
2018-11-08 19:23:39 +05:30
.then(() => {
expect(component.isCancelling).toEqual(true);
})
.then(done)
.catch(done.fail);
2017-09-10 17:25:29 +05:30
});
});
});