summaryrefslogtreecommitdiff
path: root/spec/frontend/vue_shared/components/source_viewer/plugins/wrap_comments_spec.js
blob: 5fd4182da2900297aba920168a5cfe3336c08012 (plain)
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
import { HLJS_COMMENT_SELECTOR } from '~/vue_shared/components/source_viewer/constants';
import wrapComments from '~/vue_shared/components/source_viewer/plugins/wrap_comments';

describe('Highlight.js plugin for wrapping comments', () => {
  it('mutates the input value by wrapping each line in a span tag', () => {
    const inputValue = `<span class="${HLJS_COMMENT_SELECTOR}">/* Line 1 \n* Line 2 \n*/</span>`;
    const outputValue = `<span class="${HLJS_COMMENT_SELECTOR}">/* Line 1 \n<span class="${HLJS_COMMENT_SELECTOR}">* Line 2 </span>\n<span class="${HLJS_COMMENT_SELECTOR}">*/</span>`;
    const hljsResultMock = { value: inputValue };

    wrapComments(hljsResultMock);
    expect(hljsResultMock.value).toBe(outputValue);
  });

  it('does not mutate the input value if the hljs comment selector is not present', () => {
    const inputValue = '<span class="hljs-keyword">const</span>';
    const hljsResultMock = { value: inputValue };

    wrapComments(hljsResultMock);
    expect(hljsResultMock.value).toBe(inputValue);
  });

  it('does not mutate the input value if the hljs comment line includes a closing tag', () => {
    const inputValue = `<span class="${HLJS_COMMENT_SELECTOR}">/* Line 1 </span> \n* Line 2 \n*/`;
    const hljsResultMock = { value: inputValue };

    wrapComments(hljsResultMock);
    expect(hljsResultMock.value).toBe(inputValue);
  });
});