summaryrefslogtreecommitdiff
path: root/spec/frontend/vue_shared/components/source_viewer/plugins/utils/dependency_linker_util_spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/vue_shared/components/source_viewer/plugins/utils/dependency_linker_util_spec.js')
-rw-r--r--spec/frontend/vue_shared/components/source_viewer/plugins/utils/dependency_linker_util_spec.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/frontend/vue_shared/components/source_viewer/plugins/utils/dependency_linker_util_spec.js b/spec/frontend/vue_shared/components/source_viewer/plugins/utils/dependency_linker_util_spec.js
new file mode 100644
index 00000000000..ee200747af9
--- /dev/null
+++ b/spec/frontend/vue_shared/components/source_viewer/plugins/utils/dependency_linker_util_spec.js
@@ -0,0 +1,33 @@
+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 escapedXSS = '&amp;lt;script&amp;gt;XSS&amp;lt;/script&amp;gt;';
+ const href = `http://test.com/${unescapedXSS}`;
+ const innerText = `testing${unescapedXSS}`;
+ const result = `<a href="http://test.com/${escapedXSS}" rel="nofollow noreferrer noopener">testing${escapedXSS}</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);
+ });
+});