98 lines
3.9 KiB
JavaScript
98 lines
3.9 KiB
JavaScript
const { test } = require('node:test');
|
|
const assert = require('node:assert');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const { parseStudyLoadTable } = require('../parsers.js');
|
|
const { parseProfilePage } = require('../parsers.js');
|
|
const { parseOfferedCourses } = require('../parsers.js');
|
|
|
|
const fixture = fs.readFileSync(path.join(__dirname, 'fixtures', 'study-load-table.html'), 'utf8');
|
|
const profileFixture = fs.readFileSync(path.join(__dirname, 'fixtures', 'profile.html'), 'utf8');
|
|
const offeredFixture = fs.readFileSync(path.join(__dirname, 'fixtures', 'offered-courses.html'), 'utf8');
|
|
|
|
test('parseStudyLoadTable extracts all course rows', () => {
|
|
const rows = parseStudyLoadTable(fixture);
|
|
assert.strictEqual(rows.length, 5);
|
|
});
|
|
|
|
test('parseStudyLoadTable maps columns correctly', () => {
|
|
const rows = parseStudyLoadTable(fixture);
|
|
const first = rows[0];
|
|
assert.strictEqual(first.group, '1');
|
|
assert.strictEqual(first.courseCode, 'CS 5105');
|
|
assert.strictEqual(first.units, '3.00');
|
|
assert.strictEqual(first.status, 'DISSOLVED');
|
|
assert.ok(first.schedule.includes('F 01:30 PM'));
|
|
});
|
|
|
|
test('parseStudyLoadTable handles empty faculty', () => {
|
|
const rows = parseStudyLoadTable(fixture);
|
|
const it4102 = rows.find(r => r.courseCode === 'IT 4102N');
|
|
assert.strictEqual(it4102.faculty, '');
|
|
});
|
|
|
|
test('parseProfilePage extracts header fields', () => {
|
|
const p = parseProfilePage(profileFixture);
|
|
assert.strictEqual(p.fullName, 'ADRIAN ALFRED CHIONG BONPIN');
|
|
assert.strictEqual(p.studentId, '22103625');
|
|
assert.strictEqual(p.yearLevel, '4');
|
|
assert.strictEqual(p.studentType, 'CONTINUING');
|
|
assert.strictEqual(p.program, 'BACHELOR OF SCIENCE IN INFORMATION TECHNOLOGY');
|
|
assert.strictEqual(p.semester, '1ST Semester 2026');
|
|
});
|
|
|
|
test('parseProfilePage matches bold class token with single quotes and extra classes', () => {
|
|
const html = `
|
|
<h3><b>BACHELOR OF SCIENCE</b></h3>
|
|
<table>
|
|
<tr><td>Full Name</td><td class='bold text-right'>JOHN DOE</td></tr>
|
|
<tr><td>Student Type</td><td class="bold">CONTINUING</td></tr>
|
|
</table>
|
|
`;
|
|
const p = parseProfilePage(html);
|
|
assert.strictEqual(p.fullName, 'JOHN DOE');
|
|
assert.strictEqual(p.studentType, 'CONTINUING');
|
|
assert.strictEqual(p.program, 'BACHELOR OF SCIENCE');
|
|
});
|
|
|
|
test('parseProfilePage degrades gracefully on empty input', () => {
|
|
const p = parseProfilePage('');
|
|
assert.deepStrictEqual(p, {});
|
|
});
|
|
|
|
test('parseOfferedCourses extracts course code and description', () => {
|
|
const courses = parseOfferedCourses(offeredFixture);
|
|
const it3206 = courses.find(c => c.courseCode === 'IT 3206');
|
|
assert.ok(it3206, 'should find IT 3206');
|
|
assert.strictEqual(it3206.description, 'INTEGRATIVE PROGRAMMING AND TECHNOLOGY');
|
|
});
|
|
|
|
test('parseOfferedCourses strips group suffix from code', () => {
|
|
const courses = parseOfferedCourses(offeredFixture);
|
|
assert.ok(courses.every(c => !/Group/.test(c.courseCode)));
|
|
const it3206n = courses.find(c => c.courseCode === 'IT 3206N');
|
|
assert.ok(it3206n, 'should find IT 3206N');
|
|
});
|
|
|
|
const { filterStudyLoadCourses, sumUnits } = require('../parsers.js');
|
|
|
|
test('filterStudyLoadCourses excludes DISSOLVED courses', () => {
|
|
const courses = [
|
|
{ courseCode: 'CS 5105', status: 'DISSOLVED', units: '3.00' },
|
|
{ courseCode: 'IT 3206', status: 'PARALLEL', units: '3.00' },
|
|
{ courseCode: 'IT 4102N', status: 'REGULAR', units: '3.00' }
|
|
];
|
|
const filtered = filterStudyLoadCourses(courses);
|
|
assert.deepStrictEqual(filtered.map((c) => c.courseCode), ['IT 3206', 'IT 4102N']);
|
|
});
|
|
|
|
test('filterStudyLoadCourses handles missing status', () => {
|
|
const filtered = filterStudyLoadCourses([{ courseCode: 'X', status: '', units: '1' }]);
|
|
assert.strictEqual(filtered.length, 1);
|
|
});
|
|
|
|
test('sumUnits computes total from course units', () => {
|
|
const courses = [{ units: '3.00' }, { units: '3.00' }, { units: '2.00' }];
|
|
assert.strictEqual(sumUnits(courses), '8.00');
|
|
});
|