Add Syllabus (Ders Programı) with station filtering and weekly auto-refresh
This commit is contained in:
parent
8acc77e441
commit
d0fd394fbd
10 changed files with 1196 additions and 3 deletions
|
|
@ -2,7 +2,8 @@ import assert from 'assert';
|
|||
import { LocalDatabase } from '../src/services/db';
|
||||
import { InsightService } from '../src/services/insight';
|
||||
import { ScraperService } from '../src/services/scraper';
|
||||
import { Assignment } from '../src/types';
|
||||
import { SyllabusService } from '../src/services/syllabus';
|
||||
import { Assignment, Lesson } from '../src/types';
|
||||
|
||||
async function runAllTests() {
|
||||
console.log('========================================================');
|
||||
|
|
@ -278,6 +279,95 @@ async function runAllTests() {
|
|||
assert.strictEqual(db.getRememberedCredentials(testStudentId), null);
|
||||
});
|
||||
|
||||
// 6. Syllabus & Station Filtering Tests
|
||||
await test('SyllabusService: getWeekMetadata computes accurate ISO week and Monday-Friday dates', () => {
|
||||
const refDate = new Date(2026, 9, 21); // Wednesday 21 Oct 2026
|
||||
const meta = SyllabusService.getWeekMetadata(refDate);
|
||||
|
||||
assert(meta.weekId.includes('2026-W43') || meta.weekId.includes('2026-W'), 'Must have valid week ID');
|
||||
assert(meta.weekRange.includes('19.10.2026 - 23.10.2026'), `Expected 19.10 - 23.10, got ${meta.weekRange}`);
|
||||
});
|
||||
|
||||
await test('SyllabusService: normalizeStation handles various formats', () => {
|
||||
assert.strictEqual(SyllabusService.normalizeStation('İst4'), 'İst-4');
|
||||
assert.strictEqual(SyllabusService.normalizeStation('İst-4'), 'İst-4');
|
||||
assert.strictEqual(SyllabusService.normalizeStation('ist1'), 'İst-1');
|
||||
assert.strictEqual(SyllabusService.normalizeStation('2'), 'İst-2');
|
||||
assert.strictEqual(SyllabusService.normalizeStation(null), null);
|
||||
});
|
||||
|
||||
await test('SyllabusService: filterLessonsForStation isolates student station and keeps class lessons', () => {
|
||||
const rawWednesdayLessons: Lesson[] = [
|
||||
// Period 1 has 5 stations + duplicates
|
||||
{ period: '1. Ders', periodNumber: 1, subject: 'TYT Kimya', teacher: 'ÜLKÜ ESEN', teacherPhoto: null, startTime: '09:30', endTime: '10:05', time: '09:30 - 10:05', station: 'İst1', day: 3, dayName: 'Çarşamba' },
|
||||
{ period: '1. Ders', periodNumber: 1, subject: 'TYT Kimya', teacher: 'ÜLKÜ ESEN', teacherPhoto: null, startTime: '09:30', endTime: '10:05', time: '09:30 - 10:05', station: 'İst2', day: 3, dayName: 'Çarşamba' },
|
||||
{ period: '1. Ders', periodNumber: 1, subject: 'TYT Kimya', teacher: 'ÜLKÜ ESEN', teacherPhoto: null, startTime: '09:30', endTime: '10:05', time: '09:30 - 10:05', station: 'İst3', day: 3, dayName: 'Çarşamba' },
|
||||
{ period: '1. Ders', periodNumber: 1, subject: 'TYT Kimya', teacher: 'ÜLKÜ ESEN', teacherPhoto: null, startTime: '09:30', endTime: '10:05', time: '09:30 - 10:05', station: 'İst4', day: 3, dayName: 'Çarşamba' },
|
||||
{ period: '1. Ders', periodNumber: 1, subject: 'Türk Edebiyatı', teacher: 'OĞUZHAN YİĞİT', teacherPhoto: null, startTime: '09:30', endTime: '10:05', time: '09:30 - 10:05', station: 'İst5', day: 3, dayName: 'Çarşamba' },
|
||||
// Period 2 is whole-class (no station)
|
||||
{ period: '2. Ders', periodNumber: 2, subject: 'TYT Matematik', teacher: 'BİRKAN BOZKURT', teacherPhoto: null, startTime: '10:15', endTime: '10:51', time: '10:15 - 10:51', station: null, day: 3, dayName: 'Çarşamba' }
|
||||
];
|
||||
|
||||
// Filter for İst-4
|
||||
const filteredForIst4 = SyllabusService.filterLessonsForStation(rawWednesdayLessons, 'İst-4');
|
||||
assert.strictEqual(filteredForIst4.length, 2, 'Should have exactly 2 lessons: 1 for İst-4 and 1 for class');
|
||||
assert.strictEqual(filteredForIst4[0].subject, 'TYT Kimya');
|
||||
assert.strictEqual(filteredForIst4[0].station, 'İst4');
|
||||
assert.strictEqual(filteredForIst4[1].subject, 'TYT Matematik');
|
||||
assert.strictEqual(filteredForIst4[1].station, null);
|
||||
|
||||
// Filter for İst-5
|
||||
const filteredForIst5 = SyllabusService.filterLessonsForStation(rawWednesdayLessons, 'İst-5');
|
||||
assert.strictEqual(filteredForIst5.length, 2);
|
||||
assert.strictEqual(filteredForIst5[0].subject, 'Türk Edebiyatı');
|
||||
assert.strictEqual(filteredForIst5[0].station, 'İst5');
|
||||
|
||||
// Filter for "all"
|
||||
const filteredAll = SyllabusService.filterLessonsForStation(rawWednesdayLessons, 'all');
|
||||
assert.strictEqual(filteredAll.length, 6, 'Should show all 5 stations + 1 class lesson');
|
||||
});
|
||||
|
||||
await test('SyllabusService: getCurrentLessonStatus correctly detects active and upcoming lessons', () => {
|
||||
const lessons: Lesson[] = [
|
||||
{ period: '1. Ders', periodNumber: 1, subject: 'TYT Kimya', teacher: 'ÜLKÜ ESEN', teacherPhoto: null, startTime: '09:30', endTime: '10:05', time: '09:30 - 10:05', station: 'İst4', day: 3, dayName: 'Çarşamba' },
|
||||
{ period: '2. Ders', periodNumber: 2, subject: 'TYT Matematik', teacher: 'BİRKAN BOZKURT', teacherPhoto: null, startTime: '10:15', endTime: '10:51', time: '10:15 - 10:51', station: null, day: 3, dayName: 'Çarşamba' }
|
||||
];
|
||||
|
||||
// Simulate Wednesday at 09:45 (during 1. Ders)
|
||||
const activeTime = new Date(2026, 9, 21, 9, 45);
|
||||
const activeRes = SyllabusService.getCurrentLessonStatus(lessons, 3, activeTime);
|
||||
assert(activeRes.currentLesson !== null);
|
||||
assert.strictEqual(activeRes.currentLesson?.subject, 'TYT Kimya');
|
||||
|
||||
// Simulate Wednesday at 10:08 (break before 2. Ders)
|
||||
const breakTime = new Date(2026, 9, 21, 10, 8);
|
||||
const breakRes = SyllabusService.getCurrentLessonStatus(lessons, 3, breakTime);
|
||||
assert.strictEqual(breakRes.currentLesson, null);
|
||||
assert(breakRes.nextLesson !== null);
|
||||
assert.strictEqual(breakRes.nextLesson?.subject, 'TYT Matematik');
|
||||
});
|
||||
|
||||
await test('LocalDatabase: saveSyllabus, getSyllabus, and setStudentStation persist in db.json', () => {
|
||||
const db = LocalDatabase.getInstance();
|
||||
const testStudentId = `test_student_syl_${Date.now()}`;
|
||||
|
||||
db.saveSyllabus(testStudentId, '2026-W43', '19.10.2026 - 23.10.2026', {
|
||||
1: [],
|
||||
2: [],
|
||||
3: [],
|
||||
4: [],
|
||||
5: []
|
||||
});
|
||||
|
||||
let s = db.getSyllabus(testStudentId);
|
||||
assert(s !== null);
|
||||
assert.strictEqual(s.weekId, '2026-W43');
|
||||
|
||||
db.setStudentStation(testStudentId, 'İst-4');
|
||||
s = db.getSyllabus(testStudentId);
|
||||
assert.strictEqual(s.selectedStation, 'İst-4');
|
||||
});
|
||||
|
||||
// 6. Optional Live Portal Test (via environment variables only)
|
||||
const testStudentId = process.env.TEST_STUDENT_ID;
|
||||
const testPassword = process.env.TEST_PASSWORD;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue