2022-04-04 11:22:00 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import Vue from 'vue';
|
2019-12-04 20:38:33 +05:30
|
|
|
import Vuex from 'vuex';
|
2023-07-09 08:55:56 +05:30
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
|
|
|
import { scrollToElement } from '~/lib/utils/common_utils';
|
2019-12-04 20:38:33 +05:30
|
|
|
import Log from '~/jobs/components/log/log.vue';
|
2023-05-27 22:25:52 +05:30
|
|
|
import LogLineHeader from '~/jobs/components/log/line_header.vue';
|
2022-08-13 15:12:31 +05:30
|
|
|
import { logLinesParser } from '~/jobs/store/utils';
|
2019-12-04 20:38:33 +05:30
|
|
|
import { jobLog } from './mock_data';
|
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
jest.mock('~/lib/utils/common_utils', () => ({
|
|
|
|
...jest.requireActual('~/lib/utils/common_utils'),
|
|
|
|
scrollToElement: jest.fn(),
|
|
|
|
}));
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
describe('Job Log', () => {
|
|
|
|
let wrapper;
|
|
|
|
let actions;
|
|
|
|
let state;
|
|
|
|
let store;
|
2023-05-27 22:25:52 +05:30
|
|
|
let toggleCollapsibleLineMock;
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
Vue.use(Vuex);
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
const createComponent = () => {
|
|
|
|
wrapper = mount(Log, {
|
|
|
|
store,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2023-05-27 22:25:52 +05:30
|
|
|
toggleCollapsibleLineMock = jest.fn();
|
2019-12-04 20:38:33 +05:30
|
|
|
actions = {
|
2023-05-27 22:25:52 +05:30
|
|
|
toggleCollapsibleLine: toggleCollapsibleLineMock,
|
2019-12-04 20:38:33 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
2022-08-13 15:12:31 +05:30
|
|
|
jobLog: logLinesParser(jobLog),
|
2021-11-18 22:05:49 +05:30
|
|
|
jobLogEndpoint: 'jobs/id',
|
2019-12-04 20:38:33 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
store = new Vuex.Store({
|
|
|
|
actions,
|
|
|
|
state,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
const findCollapsibleLine = () => wrapper.findComponent(LogLineHeader);
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
describe('line numbers', () => {
|
2023-07-09 08:55:56 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it('renders a line number for each open line', () => {
|
|
|
|
expect(wrapper.find('#L1').text()).toBe('1');
|
|
|
|
expect(wrapper.find('#L2').text()).toBe('2');
|
|
|
|
expect(wrapper.find('#L3').text()).toBe('3');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('links to the provided path and correct line number', () => {
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(wrapper.find('#L1').attributes('href')).toBe(`${state.jobLogEndpoint}#L1`);
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('collapsible sections', () => {
|
2023-07-09 08:55:56 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it('renders a clickable header section', () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(findCollapsibleLine().attributes('role')).toBe('button');
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
it('renders an icon with the open state', () => {
|
2022-07-23 23:45:48 +05:30
|
|
|
expect(findCollapsibleLine().find('[data-testid="chevron-lg-down-icon"]').exists()).toBe(
|
|
|
|
true,
|
|
|
|
);
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('on click header section', () => {
|
|
|
|
it('calls toggleCollapsibleLine', () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
findCollapsibleLine().trigger('click');
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
expect(toggleCollapsibleLineMock).toHaveBeenCalled();
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2023-07-09 08:55:56 +05:30
|
|
|
|
|
|
|
describe('anchor scrolling', () => {
|
|
|
|
afterEach(() => {
|
|
|
|
window.location.hash = '';
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when hash is not present', () => {
|
|
|
|
it('does not scroll to line number', async () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(wrapper.find('#L6').exists()).toBe(false);
|
|
|
|
expect(scrollToElement).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when hash is present', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
window.location.hash = '#L6';
|
|
|
|
});
|
|
|
|
|
|
|
|
it('scrolls to line number', async () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
state.jobLog = logLinesParser(jobLog, [], '#L6');
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(scrollToElement).toHaveBeenCalledTimes(1);
|
|
|
|
|
|
|
|
state.jobLog = logLinesParser(jobLog, [], '#L7');
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(scrollToElement).toHaveBeenCalledTimes(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('line number within collapsed section is visible', () => {
|
|
|
|
state.jobLog = logLinesParser(jobLog, [], '#L6');
|
|
|
|
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
expect(wrapper.find('#L6').exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|