gitlab-org--gitlab-foss/spec/javascripts/pipelines/pipelines_table_row_spec.js

217 lines
6.8 KiB
JavaScript
Raw Normal View History

import Vue from 'vue';
import tableRowComp from '~/pipelines/components/pipelines_table_row.vue';
import eventHub from '~/pipelines/event_hub';
describe('Pipelines Table Row', () => {
const jsonFixtureName = 'pipelines/pipelines.json';
2018-06-21 08:22:40 -04:00
const buildComponent = pipeline => {
2017-05-04 15:25:04 -04:00
const PipelinesTableRowComponent = Vue.extend(tableRowComp);
return new PipelinesTableRowComponent({
el: document.querySelector('.test-dom-element'),
propsData: {
pipeline,
autoDevopsHelpPath: 'foo',
2017-10-23 09:36:02 -04:00
viewType: 'root',
2017-05-04 15:25:04 -04:00
},
}).$mount();
};
let component;
let pipeline;
2017-05-04 15:25:04 -04:00
let pipelineWithoutAuthor;
let pipelineWithoutCommit;
preloadFixtures(jsonFixtureName);
beforeEach(() => {
const { pipelines } = getJSONFixture(jsonFixtureName);
pipeline = pipelines.find(p => p.user !== null && p.commit !== null);
2018-01-26 09:26:04 -05:00
pipelineWithoutAuthor = pipelines.find(p => p.user === null && p.commit !== null);
pipelineWithoutCommit = pipelines.find(p => p.user === null && p.commit === null);
2017-05-04 15:25:04 -04:00
});
2017-05-04 15:25:04 -04:00
afterEach(() => {
component.$destroy();
});
it('should render a table row', () => {
2017-05-04 15:25:04 -04:00
component = buildComponent(pipeline);
2018-10-09 14:03:09 -04:00
expect(component.$el.getAttribute('class')).toContain('gl-responsive-table-row');
});
describe('status column', () => {
2017-05-04 15:25:04 -04:00
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-06-21 08:22:40 -04:00
expect(component.$el.querySelector('.table-section.commit-link a').textContent).toContain(
pipeline.details.status.text,
);
});
});
describe('information column', () => {
2017-05-04 15:25:04 -04:00
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-06-21 08:22:40 -04:00
component.$el
.querySelector('.table-section:nth-child(2) a:nth-child(3)')
.getAttribute('href'),
).toEqual(pipeline.user.path);
expect(
2018-06-21 08:22:40 -04:00
component.$el
2018-11-07 12:20:17 -05:00
.querySelector('.table-section:nth-child(2) .js-user-avatar-image-toolip')
.textContent.trim(),
).toEqual(pipeline.user.name);
});
});
});
describe('commit column', () => {
it('should render link to commit', () => {
2017-05-04 15:25:04 -04:00
component = buildComponent(pipeline);
const commitLink = component.$el.querySelector('.branch-commit .commit-sha');
2018-10-09 14:03:09 -04:00
2017-05-04 15:25:04 -04:00
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-06-21 08:22:40 -04:00
const commitAuthorName = commitAuthorElement
2018-11-07 12:20:17 -05:00
.querySelector('.js-user-avatar-image-toolip')
.textContent.trim();
2017-05-04 15:25:04 -04:00
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);
2017-05-04 15:25:04 -04:00
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', () => {
2017-05-04 15:25:04 -04:00
beforeEach(() => {
component = buildComponent(pipeline);
});
it('should render an icon for each stage', () => {
expect(
2018-06-21 08:22:40 -04:00
component.$el.querySelectorAll('.table-section:nth-child(4) .js-builds-dropdown-button')
.length,
).toEqual(pipeline.details.stages.length);
});
});
describe('actions column', () => {
const scheduledJobAction = {
name: 'some scheduled job',
};
2017-05-04 15:25:04 -04:00
beforeEach(() => {
const withActions = Object.assign({}, pipeline);
withActions.details.scheduled_actions = [scheduledJobAction];
withActions.flags.cancelable = true;
withActions.flags.retryable = true;
withActions.cancel_path = '/cancel';
withActions.retry_path = '/retry';
component = buildComponent(withActions);
2017-05-04 15:25:04 -04:00
});
it('should render the provided actions', () => {
expect(component.$el.querySelector('.js-pipelines-retry-button')).not.toBeNull();
expect(component.$el.querySelector('.js-pipelines-cancel-button')).not.toBeNull();
const dropdownMenu = component.$el.querySelectorAll('.dropdown-menu');
2018-10-09 14:03:09 -04:00
expect(dropdownMenu).toContainText(scheduledJobAction.name);
});
it('emits `retryPipeline` event when retry button is clicked and toggles loading', () => {
2018-06-21 08:22:40 -04:00
eventHub.$on('retryPipeline', endpoint => {
expect(endpoint).toEqual('/retry');
});
component.$el.querySelector('.js-pipelines-retry-button').click();
2018-10-09 14:03:09 -04:00
expect(component.isRetrying).toEqual(true);
});
it('emits `openConfirmationModal` event when cancel button is clicked and toggles loading', () => {
2018-06-21 08:22:40 -04:00
eventHub.$once('openConfirmationModal', data => {
expect(data.endpoint).toEqual('/cancel');
2019-03-06 01:39:31 -05:00
expect(data.pipeline.id).toEqual(pipeline.id);
});
component.$el.querySelector('.js-pipelines-cancel-button').click();
});
it('renders a loading icon when `cancelingPipeline` matches pipeline id', done => {
component.cancelingPipeline = pipeline.id;
2018-10-17 03:13:26 -04:00
component
.$nextTick()
.then(() => {
expect(component.isCancelling).toEqual(true);
})
.then(done)
.catch(done.fail);
});
});
});