1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import ChunkLine from '~/vue_shared/components/source_viewer/components/chunk_line.vue';
import {
BIDI_CHARS,
BIDI_CHARS_CLASS_LIST,
BIDI_CHAR_TOOLTIP,
} from '~/vue_shared/components/source_viewer/constants';
const DEFAULT_PROPS = {
number: 2,
content: '// Line content',
language: 'javascript',
blamePath: 'blame/file.js',
};
describe('Chunk Line component', () => {
let wrapper;
const fileLineBlame = true;
const createComponent = (props = {}) => {
wrapper = shallowMountExtended(ChunkLine, {
propsData: { ...DEFAULT_PROPS, ...props },
provide: {
glFeatures: {
fileLineBlame,
},
},
});
};
const findLineLink = () => wrapper.find('.file-line-num');
const findBlameLink = () => wrapper.find('.file-line-blame');
const findContent = () => wrapper.findByTestId('content');
const findWrappedBidiChars = () => wrapper.findAllByTestId('bidi-wrapper');
beforeEach(() => {
createComponent();
});
afterEach(() => wrapper.destroy());
describe('rendering', () => {
it('wraps BiDi characters', () => {
const content = `// some content ${BIDI_CHARS.toString()} with BiDi chars`;
createComponent({ content });
const wrappedBidiChars = findWrappedBidiChars();
expect(wrappedBidiChars.length).toBe(BIDI_CHARS.length);
wrappedBidiChars.wrappers.forEach((_, i) => {
expect(wrappedBidiChars.at(i).text()).toBe(BIDI_CHARS[i]);
expect(wrappedBidiChars.at(i).attributes()).toMatchObject({
class: BIDI_CHARS_CLASS_LIST,
title: BIDI_CHAR_TOOLTIP,
});
});
});
it('renders a blame link', () => {
expect(findBlameLink().attributes()).toMatchObject({
href: `${DEFAULT_PROPS.blamePath}#L${DEFAULT_PROPS.number}`,
});
expect(findBlameLink().text()).toBe('');
});
it('renders a line number', () => {
expect(findLineLink().attributes()).toMatchObject({
'data-line-number': `${DEFAULT_PROPS.number}`,
href: `#L${DEFAULT_PROPS.number}`,
id: `L${DEFAULT_PROPS.number}`,
});
expect(findLineLink().text()).toBe(DEFAULT_PROPS.number.toString());
});
it('renders content', () => {
expect(findContent().attributes()).toMatchObject({
id: `LC${DEFAULT_PROPS.number}`,
lang: DEFAULT_PROPS.language,
});
expect(findContent().text()).toBe(DEFAULT_PROPS.content);
});
});
});
|