forked from izu/student-web-if-development-kit
32 lines
1.3 KiB
JavaScript
32 lines
1.3 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
|
|
import { DocumentFormatter } from '../js/utils/document-formatter.js';
|
|
|
|
test('parses comma-separated and JSON string tags', () => {
|
|
assert.deepEqual(DocumentFormatter.parseTags('akademik, panduan, 2026'), [
|
|
'akademik',
|
|
'panduan',
|
|
'2026',
|
|
]);
|
|
assert.deepEqual(DocumentFormatter.parseTags('["kerja praktik","kp"]'), [
|
|
'kerja praktik',
|
|
'kp',
|
|
]);
|
|
});
|
|
|
|
test('maps parsed tags to fixed repository categories', () => {
|
|
assert.equal(DocumentFormatter.categoryFromTags(['TA']), 'skripsi');
|
|
assert.equal(DocumentFormatter.categoryFromTags(['Kalender']), 'akademik');
|
|
assert.equal(DocumentFormatter.categoryFromTags(['kp']), 'praktik');
|
|
assert.equal(DocumentFormatter.categoryFromTags(['surat']), 'umum');
|
|
assert.equal(DocumentFormatter.categoryFromTags([]), 'umum');
|
|
});
|
|
|
|
test('derives file type and safe download filename from document name', () => {
|
|
assert.equal(DocumentFormatter.fileTypeFromName('Panduan Akademik.pdf'), 'pdf');
|
|
assert.equal(DocumentFormatter.fileTypeFromName('Form KP.DOCX'), 'docx');
|
|
assert.equal(DocumentFormatter.downloadFilename('Form KP', 'docx'), 'Form KP.docx');
|
|
assert.equal(DocumentFormatter.downloadFilename('Kalender.pdf', 'pdf'), 'Kalender.pdf');
|
|
});
|