2019-12-26 22:10:19 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2020-11-24 15:15:51 +05:30
|
|
|
import { GlSprintf, GlIcon } from '@gitlab/ui';
|
2020-10-24 23:57:45 +05:30
|
|
|
import { trimText } from 'helpers/text_helper';
|
2019-12-26 22:10:19 +05:30
|
|
|
import StackTraceEntry from '~/error_tracking/components/stacktrace_entry.vue';
|
|
|
|
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
|
|
|
|
import FileIcon from '~/vue_shared/components/file_icon.vue';
|
|
|
|
|
|
|
|
describe('Stacktrace Entry', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
const lines = [
|
|
|
|
[22, ' def safe_thread(name, \u0026block)\n'],
|
|
|
|
[23, ' Thread.new do\n'],
|
|
|
|
[24, " Thread.current['sidekiq_label'] = name\n"],
|
|
|
|
[25, ' watchdog(name, \u0026block)\n'],
|
|
|
|
];
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
function mountComponent(props) {
|
|
|
|
wrapper = shallowMount(StackTraceEntry, {
|
|
|
|
propsData: {
|
|
|
|
filePath: 'sidekiq/util.rb',
|
|
|
|
errorLine: 24,
|
|
|
|
...props,
|
|
|
|
},
|
2020-07-02 01:45:43 +05:30
|
|
|
stubs: {
|
|
|
|
GlSprintf,
|
|
|
|
},
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
if (wrapper) {
|
|
|
|
wrapper.destroy();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render stacktrace entry collapsed', () => {
|
2020-01-01 13:55:28 +05:30
|
|
|
mountComponent({ lines });
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(wrapper.find(StackTraceEntry).exists()).toBe(true);
|
|
|
|
expect(wrapper.find(ClipboardButton).exists()).toBe(true);
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(wrapper.find(GlIcon).exists()).toBe(true);
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(wrapper.find(FileIcon).exists()).toBe(true);
|
2020-01-01 13:55:28 +05:30
|
|
|
expect(wrapper.find('table').exists()).toBe(false);
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should render stacktrace entry table expanded', () => {
|
2020-01-01 13:55:28 +05:30
|
|
|
mountComponent({ expanded: true, lines });
|
|
|
|
expect(wrapper.find('table').exists()).toBe(true);
|
|
|
|
expect(wrapper.findAll('tr.line_holder').length).toBe(4);
|
|
|
|
expect(wrapper.findAll('.line_content.old').length).toBe(1);
|
|
|
|
});
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
describe('entry caption', () => {
|
|
|
|
const findFileHeaderContent = () => wrapper.find('.file-header-content').text();
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
it('should hide collapse icon and render error fn name and error line when there is no code block', () => {
|
|
|
|
const extraInfo = { errorLine: 34, errorFn: 'errorFn', errorColumn: 77 };
|
|
|
|
mountComponent({ expanded: false, lines: [], ...extraInfo });
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(wrapper.find(GlIcon).exists()).toBe(false);
|
2020-07-02 01:45:43 +05:30
|
|
|
expect(trimText(findFileHeaderContent())).toContain(
|
2020-01-01 13:55:28 +05:30
|
|
|
`in ${extraInfo.errorFn} at line ${extraInfo.errorLine}:${extraInfo.errorColumn}`,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render only lineNo:columnNO when there is no errorFn ', () => {
|
|
|
|
const extraInfo = { errorLine: 34, errorFn: null, errorColumn: 77 };
|
|
|
|
mountComponent({ expanded: false, lines: [], ...extraInfo });
|
2020-07-02 01:45:43 +05:30
|
|
|
const fileHeaderContent = trimText(findFileHeaderContent());
|
|
|
|
expect(fileHeaderContent).not.toContain(`in ${extraInfo.errorFn}`);
|
|
|
|
expect(fileHeaderContent).toContain(`${extraInfo.errorLine}:${extraInfo.errorColumn}`);
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should render only lineNo when there is no errorColumn ', () => {
|
|
|
|
const extraInfo = { errorLine: 34, errorFn: 'errorFn', errorColumn: null };
|
|
|
|
mountComponent({ expanded: false, lines: [], ...extraInfo });
|
2020-07-02 01:45:43 +05:30
|
|
|
const fileHeaderContent = trimText(findFileHeaderContent());
|
|
|
|
expect(fileHeaderContent).toContain(`in ${extraInfo.errorFn} at line ${extraInfo.errorLine}`);
|
|
|
|
expect(fileHeaderContent).not.toContain(`:${extraInfo.errorColumn}`);
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
});
|