forked from izu/student-web-if-development-kit
refactor(tapops): modularize page code
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
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');
|
||||
});
|
||||
Reference in New Issue
Block a user