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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

316 lines
9 KiB
JavaScript
Raw Normal View History

2022-08-13 15:12:31 +05:30
import { GlSearchBoxByClick } from '@gitlab/ui';
2020-10-24 23:57:45 +05:30
import { mount } from '@vue/test-utils';
import JobLogControllers from '~/jobs/components/job_log_controllers.vue';
2022-08-13 15:12:31 +05:30
import HelpPopover from '~/vue_shared/components/help_popover.vue';
2022-08-27 11:52:29 +05:30
import { backoffMockImplementation } from 'helpers/backoff_helper';
import * as commonUtils from '~/lib/utils/common_utils';
2022-08-13 15:12:31 +05:30
import { mockJobLog } from '../mock_data';
const mockToastShow = jest.fn();
2018-11-20 20:47:30 +05:30
describe('Job log controllers', () => {
2020-10-24 23:57:45 +05:30
let wrapper;
2018-11-20 20:47:30 +05:30
2022-08-27 11:52:29 +05:30
beforeEach(() => {
jest.spyOn(commonUtils, 'backOff').mockImplementation(backoffMockImplementation);
});
2018-11-20 20:47:30 +05:30
afterEach(() => {
2020-10-24 23:57:45 +05:30
if (wrapper?.destroy) {
wrapper.destroy();
}
2022-08-27 11:52:29 +05:30
commonUtils.backOff.mockReset();
2018-11-20 20:47:30 +05:30
});
2020-10-24 23:57:45 +05:30
const defaultProps = {
2018-12-05 23:21:45 +05:30
rawPath: '/raw',
erasePath: '/erase',
size: 511952,
isScrollTopDisabled: false,
isScrollBottomDisabled: false,
isScrollingDown: true,
2021-11-18 22:05:49 +05:30
isJobLogSizeVisible: true,
2022-08-27 11:52:29 +05:30
isComplete: true,
2022-08-13 15:12:31 +05:30
jobLog: mockJobLog,
2018-12-05 23:21:45 +05:30
};
2018-11-20 20:47:30 +05:30
2022-08-27 11:52:29 +05:30
const createWrapper = (props, { jobLogJumpToFailures = false } = {}) => {
2020-10-24 23:57:45 +05:30
wrapper = mount(JobLogControllers, {
propsData: {
...defaultProps,
...props,
},
2022-08-13 15:12:31 +05:30
provide: {
glFeatures: {
2022-08-27 11:52:29 +05:30
jobLogJumpToFailures,
2022-08-13 15:12:31 +05:30
},
},
data() {
return {
searchTerm: '82',
};
},
mocks: {
$toast: {
show: mockToastShow,
},
},
2020-10-24 23:57:45 +05:30
});
};
const findTruncatedInfo = () => wrapper.find('[data-testid="log-truncated-info"]');
const findRawLink = () => wrapper.find('[data-testid="raw-link"]');
const findRawLinkController = () => wrapper.find('[data-testid="job-raw-link-controller"]');
const findScrollTop = () => wrapper.find('[data-testid="job-controller-scroll-top"]');
const findScrollBottom = () => wrapper.find('[data-testid="job-controller-scroll-bottom"]');
2022-08-13 15:12:31 +05:30
const findJobLogSearch = () => wrapper.findComponent(GlSearchBoxByClick);
const findSearchHelp = () => wrapper.findComponent(HelpPopover);
2022-08-27 11:52:29 +05:30
const findScrollFailure = () => wrapper.find('[data-testid="job-controller-scroll-to-failure"]');
2020-10-24 23:57:45 +05:30
2018-12-05 23:21:45 +05:30
describe('Truncate information', () => {
2021-11-18 22:05:49 +05:30
describe('with isJobLogSizeVisible', () => {
2018-12-05 23:21:45 +05:30
beforeEach(() => {
2020-10-24 23:57:45 +05:30
createWrapper();
2018-12-05 23:21:45 +05:30
});
2018-12-13 13:39:08 +05:30
2018-12-05 23:21:45 +05:30
it('renders size information', () => {
2020-10-24 23:57:45 +05:30
expect(findTruncatedInfo().text()).toMatch('499.95 KiB');
2018-11-20 20:47:30 +05:30
});
2021-11-18 22:05:49 +05:30
it('renders link to raw job log', () => {
2020-10-24 23:57:45 +05:30
expect(findRawLink().attributes('href')).toBe(defaultProps.rawPath);
2018-12-05 23:21:45 +05:30
});
2018-11-20 20:47:30 +05:30
});
});
describe('links section', () => {
2021-11-18 22:05:49 +05:30
describe('with raw job log path', () => {
2020-10-24 23:57:45 +05:30
beforeEach(() => {
createWrapper();
});
2018-11-20 20:47:30 +05:30
2021-11-18 22:05:49 +05:30
it('renders raw job log link', () => {
2020-10-24 23:57:45 +05:30
expect(findRawLinkController().attributes('href')).toBe(defaultProps.rawPath);
2018-11-20 20:47:30 +05:30
});
});
2021-11-18 22:05:49 +05:30
describe('without raw job log path', () => {
2020-10-24 23:57:45 +05:30
beforeEach(() => {
createWrapper({
rawPath: null,
2018-11-20 20:47:30 +05:30
});
2020-10-24 23:57:45 +05:30
});
2018-11-20 20:47:30 +05:30
2021-11-18 22:05:49 +05:30
it('does not render raw job log link', () => {
2020-10-24 23:57:45 +05:30
expect(findRawLinkController().exists()).toBe(false);
2018-11-20 20:47:30 +05:30
});
});
});
describe('scroll buttons', () => {
describe('scroll top button', () => {
describe('when user can scroll top', () => {
beforeEach(() => {
2020-10-24 23:57:45 +05:30
createWrapper({
isScrollTopDisabled: false,
});
2018-11-20 20:47:30 +05:30
});
2020-10-24 23:57:45 +05:30
it('emits scrollJobLogTop event on click', async () => {
2022-08-27 11:52:29 +05:30
await findScrollTop().trigger('click');
2018-11-20 20:47:30 +05:30
2020-10-24 23:57:45 +05:30
expect(wrapper.emitted().scrollJobLogTop).toHaveLength(1);
2018-11-20 20:47:30 +05:30
});
});
describe('when user can not scroll top', () => {
beforeEach(() => {
2020-10-24 23:57:45 +05:30
createWrapper({
2018-12-05 23:21:45 +05:30
isScrollTopDisabled: true,
isScrollBottomDisabled: false,
isScrollingDown: false,
2018-11-20 20:47:30 +05:30
});
});
it('renders disabled scroll top button', () => {
2020-10-24 23:57:45 +05:30
expect(findScrollTop().attributes('disabled')).toBe('disabled');
2018-11-20 20:47:30 +05:30
});
2020-10-24 23:57:45 +05:30
it('does not emit scrollJobLogTop event on click', async () => {
2022-08-27 11:52:29 +05:30
await findScrollTop().trigger('click');
2020-10-24 23:57:45 +05:30
expect(wrapper.emitted().scrollJobLogTop).toBeUndefined();
2018-11-20 20:47:30 +05:30
});
});
});
describe('scroll bottom button', () => {
describe('when user can scroll bottom', () => {
beforeEach(() => {
2020-10-24 23:57:45 +05:30
createWrapper();
2018-11-20 20:47:30 +05:30
});
2020-10-24 23:57:45 +05:30
it('emits scrollJobLogBottom event on click', async () => {
2022-08-27 11:52:29 +05:30
await findScrollBottom().trigger('click');
2018-11-20 20:47:30 +05:30
2020-10-24 23:57:45 +05:30
expect(wrapper.emitted().scrollJobLogBottom).toHaveLength(1);
2018-11-20 20:47:30 +05:30
});
});
describe('when user can not scroll bottom', () => {
beforeEach(() => {
2020-10-24 23:57:45 +05:30
createWrapper({
2018-12-05 23:21:45 +05:30
isScrollTopDisabled: false,
isScrollBottomDisabled: true,
isScrollingDown: false,
2018-11-20 20:47:30 +05:30
});
});
it('renders disabled scroll bottom button', () => {
2020-10-24 23:57:45 +05:30
expect(findScrollBottom().attributes('disabled')).toEqual('disabled');
2018-11-20 20:47:30 +05:30
});
2020-10-24 23:57:45 +05:30
it('does not emit scrollJobLogBottom event on click', async () => {
2022-08-27 11:52:29 +05:30
await findScrollBottom().trigger('click');
2020-10-24 23:57:45 +05:30
expect(wrapper.emitted().scrollJobLogBottom).toBeUndefined();
2018-11-20 20:47:30 +05:30
});
});
2018-12-05 23:21:45 +05:30
describe('while isScrollingDown is true', () => {
2020-10-24 23:57:45 +05:30
beforeEach(() => {
createWrapper();
});
2018-12-05 23:21:45 +05:30
2020-10-24 23:57:45 +05:30
it('renders animate class for the scroll down button', () => {
expect(findScrollBottom().classes()).toContain('animate');
2018-12-05 23:21:45 +05:30
});
});
describe('while isScrollingDown is false', () => {
2020-10-24 23:57:45 +05:30
beforeEach(() => {
createWrapper({
2018-12-05 23:21:45 +05:30
isScrollTopDisabled: true,
isScrollBottomDisabled: false,
isScrollingDown: false,
});
2020-10-24 23:57:45 +05:30
});
2018-12-13 13:39:08 +05:30
2020-10-24 23:57:45 +05:30
it('does not render animate class for the scroll down button', () => {
expect(findScrollBottom().classes()).not.toContain('animate');
2018-12-05 23:21:45 +05:30
});
});
2018-11-20 20:47:30 +05:30
});
2022-08-13 15:12:31 +05:30
2022-08-27 11:52:29 +05:30
describe('scroll to failure button', () => {
describe('with feature flag disabled', () => {
it('does not display button', () => {
createWrapper();
2022-08-13 15:12:31 +05:30
2022-08-27 11:52:29 +05:30
expect(findScrollFailure().exists()).toBe(false);
});
2022-08-13 15:12:31 +05:30
});
2022-08-27 11:52:29 +05:30
describe('with red text failures on the page', () => {
let firstFailure;
let secondFailure;
beforeEach(() => {
jest.spyOn(document, 'querySelectorAll').mockReturnValueOnce(['mock-element']);
createWrapper({}, { jobLogJumpToFailures: true });
firstFailure = document.createElement('div');
firstFailure.className = 'term-fg-l-red';
document.body.appendChild(firstFailure);
secondFailure = document.createElement('div');
secondFailure.className = 'term-fg-l-red';
document.body.appendChild(secondFailure);
});
afterEach(() => {
if (firstFailure) {
firstFailure.remove();
firstFailure = null;
}
if (secondFailure) {
secondFailure.remove();
secondFailure = null;
}
});
it('is enabled', () => {
expect(findScrollFailure().props('disabled')).toBe(false);
});
it('scrolls to each failure', async () => {
jest.spyOn(firstFailure, 'scrollIntoView');
2022-08-13 15:12:31 +05:30
2022-08-27 11:52:29 +05:30
await findScrollFailure().trigger('click');
expect(firstFailure.scrollIntoView).toHaveBeenCalled();
await findScrollFailure().trigger('click');
expect(secondFailure.scrollIntoView).toHaveBeenCalled();
await findScrollFailure().trigger('click');
expect(firstFailure.scrollIntoView).toHaveBeenCalled();
});
2022-08-13 15:12:31 +05:30
});
2022-08-27 11:52:29 +05:30
describe('with no red text failures on the page', () => {
beforeEach(() => {
jest.spyOn(document, 'querySelectorAll').mockReturnValueOnce([]);
2022-08-13 15:12:31 +05:30
2022-08-27 11:52:29 +05:30
createWrapper({}, { jobLogJumpToFailures: true });
});
2022-08-13 15:12:31 +05:30
2022-08-27 11:52:29 +05:30
it('is disabled', () => {
expect(findScrollFailure().props('disabled')).toBe(true);
});
2022-08-13 15:12:31 +05:30
});
2022-08-27 11:52:29 +05:30
describe('when the job log is not complete', () => {
beforeEach(() => {
jest.spyOn(document, 'querySelectorAll').mockReturnValueOnce(['mock-element']);
createWrapper({ isComplete: false }, { jobLogJumpToFailures: true });
});
2022-08-13 15:12:31 +05:30
2022-08-27 11:52:29 +05:30
it('is enabled', () => {
expect(findScrollFailure().props('disabled')).toBe(false);
});
2022-08-13 15:12:31 +05:30
});
});
});
2022-08-27 11:52:29 +05:30
describe('Job log search', () => {
beforeEach(() => {
createWrapper();
});
it('displays job log search', () => {
expect(findJobLogSearch().exists()).toBe(true);
expect(findSearchHelp().exists()).toBe(true);
});
it('emits search results', () => {
const expectedSearchResults = [[[mockJobLog[6].lines[1], mockJobLog[6].lines[2]]]];
findJobLogSearch().vm.$emit('submit');
expect(wrapper.emitted('searchResults')).toEqual(expectedSearchResults);
});
it('clears search results', () => {
findJobLogSearch().vm.$emit('clear');
expect(wrapper.emitted('searchResults')).toEqual([[[]]]);
});
});
2018-11-20 20:47:30 +05:30
});