fix: widen NOTE column and add pagination to study load PDF
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
const { test } = require('node:test');
|
||||
const assert = require('node:assert');
|
||||
const fs = require('node:fs');
|
||||
const os = require('node:os');
|
||||
const path = require('node:path');
|
||||
const { execFileSync } = require('node:child_process');
|
||||
global.PDFLib = require('pdf-lib');
|
||||
const { buildStudyLoadPdf } = require('../pdf.js');
|
||||
|
||||
@@ -20,6 +24,20 @@ const sampleData = {
|
||||
totalUnits: '6.00'
|
||||
};
|
||||
|
||||
function extractPdfText(bytes) {
|
||||
const tmp = path.join(os.tmpdir(), 'study-load-test.pdf');
|
||||
fs.writeFileSync(tmp, Buffer.from(bytes));
|
||||
const script = [
|
||||
'import fitz',
|
||||
`doc = fitz.open('${tmp}')`,
|
||||
'text = ""',
|
||||
'for page in doc:',
|
||||
' text += page.get_text()',
|
||||
'print(text)'
|
||||
].join('\n');
|
||||
return execFileSync('python3', ['-c', script], { encoding: 'utf8' });
|
||||
}
|
||||
|
||||
test('buildStudyLoadPdf returns valid PDF bytes', async () => {
|
||||
const bytes = await buildStudyLoadPdf(sampleData);
|
||||
assert.ok(bytes instanceof Uint8Array);
|
||||
@@ -27,4 +45,8 @@ test('buildStudyLoadPdf returns valid PDF bytes', async () => {
|
||||
assert.strictEqual(head, '%PDF-');
|
||||
const doc = await PDFLib.PDFDocument.load(bytes);
|
||||
assert.strictEqual(doc.getPageCount(), 1);
|
||||
|
||||
const text = extractPdfText(bytes);
|
||||
assert.ok(text.includes('CIS 2101'), 'PDF text should contain course code CIS 2101');
|
||||
assert.ok(text.includes("STUDENT'S STUDY LOAD"), 'PDF text should contain the title');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user