debian-mirror-gitlab/spec/frontend/jobs/components/jobs_container_spec.js

132 lines
3.1 KiB
JavaScript
Raw Normal View History

2018-11-20 20:47:30 +05:30
import Vue from 'vue';
import component from '~/jobs/components/jobs_container.vue';
import mountComponent from '../../helpers/vue_mount_component_helper';
2018-12-05 23:21:45 +05:30
describe('Jobs List block', () => {
2018-11-20 20:47:30 +05:30
const Component = Vue.extend(component);
let vm;
const retried = {
status: {
2019-12-04 20:38:33 +05:30
details_path: '/gitlab-org/gitlab-foss/pipelines/28029444',
2018-11-20 20:47:30 +05:30
group: 'success',
has_details: true,
icon: 'status_success',
label: 'passed',
text: 'passed',
tooltip: 'passed',
},
2018-12-05 23:21:45 +05:30
id: 233432756,
2018-11-20 20:47:30 +05:30
tooltip: 'build - passed',
retried: true,
};
const active = {
name: 'test',
status: {
2019-12-04 20:38:33 +05:30
details_path: '/gitlab-org/gitlab-foss/pipelines/28029444',
2018-11-20 20:47:30 +05:30
group: 'success',
has_details: true,
icon: 'status_success',
label: 'passed',
text: 'passed',
tooltip: 'passed',
},
2018-12-05 23:21:45 +05:30
id: 2322756,
2018-11-20 20:47:30 +05:30
tooltip: 'build - passed',
active: true,
};
const job = {
name: 'build',
status: {
2019-12-04 20:38:33 +05:30
details_path: '/gitlab-org/gitlab-foss/pipelines/28029444',
2018-11-20 20:47:30 +05:30
group: 'success',
has_details: true,
icon: 'status_success',
label: 'passed',
text: 'passed',
tooltip: 'passed',
},
2018-12-05 23:21:45 +05:30
id: 232153,
2018-11-20 20:47:30 +05:30
tooltip: 'build - passed',
};
afterEach(() => {
vm.$destroy();
});
it('renders list of jobs', () => {
vm = mountComponent(Component, {
jobs: [job, retried, active],
2018-12-05 23:21:45 +05:30
jobId: 12313,
2018-11-20 20:47:30 +05:30
});
expect(vm.$el.querySelectorAll('a').length).toEqual(3);
});
2018-12-05 23:21:45 +05:30
it('renders arrow right when job id matches `jobId`', () => {
2018-11-20 20:47:30 +05:30
vm = mountComponent(Component, {
jobs: [active],
2018-12-05 23:21:45 +05:30
jobId: active.id,
2018-11-20 20:47:30 +05:30
});
expect(vm.$el.querySelector('a .js-arrow-right')).not.toBeNull();
});
it('does not render arrow right when job is not active', () => {
vm = mountComponent(Component, {
jobs: [job],
2018-12-05 23:21:45 +05:30
jobId: active.id,
2018-11-20 20:47:30 +05:30
});
expect(vm.$el.querySelector('a .js-arrow-right')).toBeNull();
});
it('renders job name when present', () => {
vm = mountComponent(Component, {
jobs: [job],
2018-12-05 23:21:45 +05:30
jobId: active.id,
2018-11-20 20:47:30 +05:30
});
expect(vm.$el.querySelector('a').textContent.trim()).toContain(job.name);
expect(vm.$el.querySelector('a').textContent.trim()).not.toContain(job.id);
});
it('renders job id when job name is not available', () => {
vm = mountComponent(Component, {
jobs: [retried],
2018-12-05 23:21:45 +05:30
jobId: active.id,
2018-11-20 20:47:30 +05:30
});
expect(vm.$el.querySelector('a').textContent.trim()).toContain(retried.id);
});
it('links to the job page', () => {
vm = mountComponent(Component, {
jobs: [job],
2018-12-05 23:21:45 +05:30
jobId: active.id,
2018-11-20 20:47:30 +05:30
});
2018-12-05 23:21:45 +05:30
expect(vm.$el.querySelector('a').getAttribute('href')).toEqual(job.status.details_path);
2018-11-20 20:47:30 +05:30
});
it('renders retry icon when job was retried', () => {
vm = mountComponent(Component, {
jobs: [retried],
2018-12-05 23:21:45 +05:30
jobId: active.id,
2018-11-20 20:47:30 +05:30
});
expect(vm.$el.querySelector('.js-retry-icon')).not.toBeNull();
});
it('does not render retry icon when job was not retried', () => {
vm = mountComponent(Component, {
jobs: [job],
2018-12-05 23:21:45 +05:30
jobId: active.id,
2018-11-20 20:47:30 +05:30
});
expect(vm.$el.querySelector('.js-retry-icon')).toBeNull();
});
});