35 lines
1.2 KiB
JavaScript
35 lines
1.2 KiB
JavaScript
import {
|
|
createLink,
|
|
generateHLJSOpenTag,
|
|
} from '~/vue_shared/components/source_viewer/plugins/utils/dependency_linker_util';
|
|
|
|
describe('createLink', () => {
|
|
it('generates a link with the correct attributes', () => {
|
|
const href = 'http://test.com';
|
|
const innerText = 'testing';
|
|
const result = `<a href="${href}" 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 = '<script>XSS</script>';
|
|
const escapedHref = '<script>XSS</script>';
|
|
const href = `http://test.com/${unescapedXSS}`;
|
|
const innerText = `testing${unescapedXSS}`;
|
|
const result = `<a href="http://test.com/${escapedHref}" 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}">"`;
|
|
|
|
expect(generateHLJSOpenTag(type)).toBe(result);
|
|
});
|
|
});
|