35 lines
999 B
JavaScript
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);
|
|
});
|