Incognito-Wiki/tests/open-exam-links.test.mjs
msa46 aa28e1ff21
Some checks failed
Deploy to GitHub Pages / build (push) Has been cancelled
Deploy to GitHub Pages / deploy (push) Has been cancelled
Open exam PDFs in new tabs
2026-09-18 09:20:36 +02:00

35 lines
999 B
JavaScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { openExamLinksInNewTab } from '../src/config/open-exam-links.mjs';
test('opens PDF links from the exam archive in a new tab', () => {
const tree = {
type: 'root',
children: [
{ type: 'link', url: '/media/exam.pdf', children: [] },
{ type: 'link', url: '/computer-science/', children: [] },
],
};
openExamLinksInNewTab()(tree, {
path: '/project/src/content/docs/previous-exams-and-documents.md',
});
assert.deepEqual(tree.children[0].data, {
hProperties: {
target: '_blank',
rel: 'noopener noreferrer',
},
});
assert.equal(tree.children[1].data, undefined);
});
test('leaves PDF links on other pages unchanged', () => {
const link = { type: 'link', url: '/media/notes.pdf', children: [] };
openExamLinksInNewTab()({ type: 'root', children: [link] }, {
path: '/project/src/content/docs/course.md',
});
assert.equal(link.data, undefined);
});