debian-mirror-gitlab/spec/frontend/jobs/components/log/log_spec.js

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

167 lines
3.9 KiB
JavaScript
Raw Normal View History

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';
2021-09-30 23:02:18 +05:30
import { logLinesParserLegacy, 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;
2021-09-30 23:02:18 +05:30
let origGon;
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(() => {
actions = {
toggleCollapsibleLine: () => {},
};
2021-09-30 23:02:18 +05:30
origGon = window.gon;
window.gon = { features: { infinitelyCollapsibleSections: false } };
state = {
2021-11-18 22:05:49 +05:30
jobLog: logLinesParserLegacy(jobLog),
jobLogEndpoint: 'jobs/id',
2021-09-30 23:02:18 +05:30
};
store = new Vuex.Store({
actions,
state,
});
createComponent();
});
afterEach(() => {
wrapper.destroy();
window.gon = origGon;
});
const findCollapsibleLine = () => wrapper.find('.collapsible-line');
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`);
2021-09-30 23:02:18 +05:30
});
});
describe('collapsible sections', () => {
it('renders a clickable header section', () => {
expect(findCollapsibleLine().attributes('role')).toBe('button');
});
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,
);
2021-09-30 23:02:18 +05:30
});
describe('on click header section', () => {
it('calls toggleCollapsibleLine', () => {
jest.spyOn(wrapper.vm, 'toggleCollapsibleLine');
findCollapsibleLine().trigger('click');
expect(wrapper.vm.toggleCollapsibleLine).toHaveBeenCalled();
});
});
});
});
describe('Job Log, infinitelyCollapsibleSections feature flag enabled', () => {
let wrapper;
let actions;
let state;
let store;
let origGon;
2022-04-04 11:22:00 +05:30
Vue.use(Vuex);
2021-09-30 23:02:18 +05:30
const createComponent = () => {
wrapper = mount(Log, {
store,
});
};
beforeEach(() => {
actions = {
toggleCollapsibleLine: () => {},
};
origGon = window.gon;
window.gon = { features: { infinitelyCollapsibleSections: true } };
2019-12-04 20:38:33 +05:30
state = {
2021-11-18 22:05:49 +05:30
jobLog: logLinesParser(jobLog).parsedLines,
jobLogEndpoint: 'jobs/id',
2019-12-04 20:38:33 +05:30
};
store = new Vuex.Store({
actions,
state,
});
createComponent();
});
afterEach(() => {
wrapper.destroy();
2021-09-30 23:02:18 +05:30
window.gon = origGon;
2019-12-04 20:38:33 +05:30
});
2020-11-24 15:15:51 +05:30
const findCollapsibleLine = () => wrapper.find('.collapsible-line');
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', () => {
jest.spyOn(wrapper.vm, 'toggleCollapsibleLine');
2020-11-24 15:15:51 +05:30
findCollapsibleLine().trigger('click');
2019-12-04 20:38:33 +05:30
expect(wrapper.vm.toggleCollapsibleLine).toHaveBeenCalled();
});
});
});
});