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

102 lines
3 KiB
JavaScript
Raw Normal View History

2020-10-24 23:57:45 +05:30
import { GlBadge, GlLink } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import StuckBlock from '~/jobs/components/stuck_block.vue';
2018-11-20 20:47:30 +05:30
describe('Stuck Block Job component', () => {
2020-10-24 23:57:45 +05:30
let wrapper;
2018-11-20 20:47:30 +05:30
afterEach(() => {
2020-10-24 23:57:45 +05:30
if (wrapper?.destroy) {
wrapper.destroy();
wrapper = null;
}
2018-11-20 20:47:30 +05:30
});
2021-03-08 18:12:59 +05:30
const createWrapper = (props) => {
2020-10-24 23:57:45 +05:30
wrapper = shallowMount(StuckBlock, {
propsData: {
...props,
},
});
};
const tags = ['docker', 'gitlab-org'];
const findStuckNoActiveRunners = () =>
wrapper.find('[data-testid="job-stuck-no-active-runners"]');
const findStuckNoRunners = () => wrapper.find('[data-testid="job-stuck-no-runners"]');
const findStuckWithTags = () => wrapper.find('[data-testid="job-stuck-with-tags"]');
const findRunnerPathLink = () => wrapper.find(GlLink);
const findAllBadges = () => wrapper.findAll(GlBadge);
2018-11-20 20:47:30 +05:30
describe('with no runners for project', () => {
beforeEach(() => {
2020-10-24 23:57:45 +05:30
createWrapper({
2018-11-20 20:47:30 +05:30
hasNoRunnersForProject: true,
runnersPath: '/root/project/runners#js-runners-settings',
});
});
it('renders only information about project not having runners', () => {
2020-10-24 23:57:45 +05:30
expect(findStuckNoRunners().exists()).toBe(true);
expect(findStuckWithTags().exists()).toBe(false);
expect(findStuckNoActiveRunners().exists()).toBe(false);
2018-11-20 20:47:30 +05:30
});
it('renders link to runners page', () => {
2020-10-24 23:57:45 +05:30
expect(findRunnerPathLink().attributes('href')).toBe(
2018-11-20 20:47:30 +05:30
'/root/project/runners#js-runners-settings',
);
});
});
describe('with tags', () => {
beforeEach(() => {
2020-10-24 23:57:45 +05:30
createWrapper({
2018-11-20 20:47:30 +05:30
hasNoRunnersForProject: false,
2020-10-24 23:57:45 +05:30
tags,
2018-11-20 20:47:30 +05:30
runnersPath: '/root/project/runners#js-runners-settings',
});
});
it('renders information about the tags not being set', () => {
2020-10-24 23:57:45 +05:30
expect(findStuckWithTags().exists()).toBe(true);
expect(findStuckNoActiveRunners().exists()).toBe(false);
expect(findStuckNoRunners().exists()).toBe(false);
2018-11-20 20:47:30 +05:30
});
it('renders tags', () => {
2020-10-24 23:57:45 +05:30
findAllBadges().wrappers.forEach((badgeElt, index) => {
return expect(badgeElt.text()).toBe(tags[index]);
});
2018-11-20 20:47:30 +05:30
});
it('renders link to runners page', () => {
2020-10-24 23:57:45 +05:30
expect(findRunnerPathLink().attributes('href')).toBe(
2018-11-20 20:47:30 +05:30
'/root/project/runners#js-runners-settings',
);
});
});
describe('without active runners', () => {
beforeEach(() => {
2020-10-24 23:57:45 +05:30
createWrapper({
2018-11-20 20:47:30 +05:30
hasNoRunnersForProject: false,
runnersPath: '/root/project/runners#js-runners-settings',
});
});
it('renders information about project not having runners', () => {
2020-10-24 23:57:45 +05:30
expect(findStuckNoActiveRunners().exists()).toBe(true);
expect(findStuckNoRunners().exists()).toBe(false);
expect(findStuckWithTags().exists()).toBe(false);
2018-11-20 20:47:30 +05:30
});
it('renders link to runners page', () => {
2020-10-24 23:57:45 +05:30
expect(findRunnerPathLink().attributes('href')).toBe(
2018-11-20 20:47:30 +05:30
'/root/project/runners#js-runners-settings',
);
});
});
});