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';
|
|
|
|
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';
|
|
|
|
|
|
|
|
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,
|
|
|
|
});
|
|
|
|
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
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', () => {
|
|
|
|
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', () => {
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|