Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dependency_linker_util_spec.js « utils « plugins « source_viewer « components « vue_shared « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 66e2020da27d24f4a190c0d470648f9775deec10 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import {
  createLink,
  generateHLJSOpenTag,
  getObjectKeysByKeyName,
} from '~/vue_shared/components/source_viewer/plugins/utils/dependency_linker_util';
import { PODSPEC_JSON_CONTENT } from '../mock_data';

describe('createLink', () => {
  it('generates a link with the correct attributes', () => {
    const href = 'http://test.com';
    const innerText = 'testing';
    const result = `<a href="${href}" target="_blank" rel="nofollow noreferrer noopener">${innerText}</a>`;

    expect(createLink(href, innerText)).toBe(result);
  });

  it('escapes the user-controlled content', () => {
    const unescapedXSS = '<script>XSS</script>';
    const escapedPackageName = '&lt;script&gt;XSS&lt;/script&gt;';
    const escapedHref = '&lt;script&gt;XSS&lt;/script&gt;';
    const href = `http://test.com/${unescapedXSS}`;
    const innerText = `testing${unescapedXSS}`;
    const result = `<a href="http://test.com/${escapedHref}" target="_blank" rel="nofollow noreferrer noopener">testing${escapedPackageName}</a>`;

    expect(createLink(href, innerText)).toBe(result);
  });
});

describe('generateHLJSOpenTag', () => {
  it('generates an open tag with the correct selector', () => {
    const type = 'string';
    const result = `<span class="hljs-${type}">&quot;`;

    expect(generateHLJSOpenTag(type)).toBe(result);
  });
});

describe('getObjectKeysByKeyName method', () => {
  it('gets all object keys within specified key', () => {
    const acc = [];
    const keys = getObjectKeysByKeyName(JSON.parse(PODSPEC_JSON_CONTENT), 'dependencies', acc);
    expect(keys).toEqual(['MyCheckCore', 'AFNetworking/Security']);
  });
});