2017-03-17 13:30:32 -04:00
|
|
|
import Vue from 'vue';
|
2017-06-20 10:54:55 -04:00
|
|
|
import tableRowComp from '~/pipelines/components/pipelines_table_row.vue';
|
2017-01-29 10:30:04 -05:00
|
|
|
|
|
|
|
describe('Pipelines Table Row', () => {
|
2017-05-05 06:34:42 -04:00
|
|
|
const jsonFixtureName = 'pipelines/pipelines.json';
|
2017-05-04 15:25:04 -04:00
|
|
|
const buildComponent = (pipeline) => {
|
|
|
|
const PipelinesTableRowComponent = Vue.extend(tableRowComp);
|
|
|
|
return new PipelinesTableRowComponent({
|
|
|
|
el: document.querySelector('.test-dom-element'),
|
|
|
|
propsData: {
|
|
|
|
pipeline,
|
2017-09-01 06:20:14 -04:00
|
|
|
autoDevopsHelpPath: 'foo',
|
2017-10-23 09:36:02 -04:00
|
|
|
viewType: 'root',
|
2017-05-04 15:25:04 -04:00
|
|
|
},
|
|
|
|
}).$mount();
|
|
|
|
};
|
2017-05-05 06:34:42 -04:00
|
|
|
|
2017-01-29 10:30:04 -05:00
|
|
|
let component;
|
2017-05-05 06:34:42 -04:00
|
|
|
let pipeline;
|
2017-05-04 15:25:04 -04:00
|
|
|
let pipelineWithoutAuthor;
|
|
|
|
let pipelineWithoutCommit;
|
2017-05-05 06:34:42 -04:00
|
|
|
|
|
|
|
preloadFixtures(jsonFixtureName);
|
2017-01-29 10:30:04 -05:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2018-01-24 13:36:54 -05:00
|
|
|
const pipelines = getJSONFixture(jsonFixtureName).pipelines;
|
|
|
|
|
|
|
|
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-01-29 10:30:04 -05:00
|
|
|
|
2017-05-04 15:25:04 -04:00
|
|
|
afterEach(() => {
|
|
|
|
component.$destroy();
|
2017-01-29 10:30:04 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render a table row', () => {
|
2017-05-04 15:25:04 -04:00
|
|
|
component = buildComponent(pipeline);
|
2017-06-16 08:00:28 -04:00
|
|
|
expect(component.$el.getAttribute('class')).toContain('gl-responsive-table-row');
|
2017-01-29 10:30:04 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('status column', () => {
|
2017-05-04 15:25:04 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
component = buildComponent(pipeline);
|
|
|
|
});
|
|
|
|
|
2017-01-29 10:30:04 -05:00
|
|
|
it('should render a pipeline link', () => {
|
|
|
|
expect(
|
2017-06-16 08:00:28 -04:00
|
|
|
component.$el.querySelector('.table-section.commit-link a').getAttribute('href'),
|
2017-01-29 10:30:04 -05:00
|
|
|
).toEqual(pipeline.path);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render status text', () => {
|
|
|
|
expect(
|
2017-06-16 08:00:28 -04:00
|
|
|
component.$el.querySelector('.table-section.commit-link a').textContent,
|
2017-01-29 10:30:04 -05:00
|
|
|
).toContain(pipeline.details.status.text);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('information column', () => {
|
2017-05-04 15:25:04 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
component = buildComponent(pipeline);
|
|
|
|
});
|
|
|
|
|
2017-01-29 10:30:04 -05:00
|
|
|
it('should render a pipeline link', () => {
|
|
|
|
expect(
|
2017-06-16 08:00:28 -04:00
|
|
|
component.$el.querySelector('.table-section:nth-child(2) a').getAttribute('href'),
|
2017-01-29 10:30:04 -05:00
|
|
|
).toEqual(pipeline.path);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render pipeline ID', () => {
|
|
|
|
expect(
|
2017-06-16 08:00:28 -04:00
|
|
|
component.$el.querySelector('.table-section:nth-child(2) a > span').textContent,
|
2017-01-29 10:30:04 -05:00
|
|
|
).toEqual(`#${pipeline.id}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when a user is provided', () => {
|
|
|
|
it('should render user information', () => {
|
|
|
|
expect(
|
2017-06-16 08:00:28 -04:00
|
|
|
component.$el.querySelector('.table-section:nth-child(2) a:nth-child(3)').getAttribute('href'),
|
2017-06-02 09:24:42 -04:00
|
|
|
).toEqual(pipeline.user.path);
|
2017-01-29 10:30:04 -05:00
|
|
|
|
|
|
|
expect(
|
2017-06-16 08:00:28 -04:00
|
|
|
component.$el.querySelector('.table-section:nth-child(2) img').getAttribute('data-original-title'),
|
2017-01-29 10:30:04 -05:00
|
|
|
).toEqual(pipeline.user.name);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('commit column', () => {
|
|
|
|
it('should render link to commit', () => {
|
2017-05-04 15:25:04 -04:00
|
|
|
component = buildComponent(pipeline);
|
|
|
|
|
2017-05-11 11:47:44 -04:00
|
|
|
const commitLink = component.$el.querySelector('.branch-commit .commit-sha');
|
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');
|
2017-04-15 19:38:07 -04:00
|
|
|
const commitAuthorName = commitAuthorElement.querySelector('img.avatar').getAttribute('data-original-title');
|
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();
|
|
|
|
|
2017-06-02 09:24:42 -04:00
|
|
|
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);
|
2017-01-29 10:30:04 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('stages column', () => {
|
2017-05-04 15:25:04 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
component = buildComponent(pipeline);
|
|
|
|
});
|
|
|
|
|
2017-01-29 10:30:04 -05:00
|
|
|
it('should render an icon for each stage', () => {
|
|
|
|
expect(
|
2017-06-16 08:00:28 -04:00
|
|
|
component.$el.querySelectorAll('.table-section:nth-child(4) .js-builds-dropdown-button').length,
|
2017-01-29 10:30:04 -05:00
|
|
|
).toEqual(pipeline.details.stages.length);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('actions column', () => {
|
2017-05-04 15:25:04 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
component = buildComponent(pipeline);
|
|
|
|
});
|
|
|
|
|
2017-01-29 10:30:04 -05:00
|
|
|
it('should render the provided actions', () => {
|
|
|
|
expect(
|
2017-06-16 08:00:28 -04:00
|
|
|
component.$el.querySelectorAll('.table-section:nth-child(6) ul li').length,
|
2017-01-29 10:30:04 -05:00
|
|
|
).toEqual(pipeline.details.manual_actions.length);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|