114 lines
4.2 KiB
JavaScript
114 lines
4.2 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {
|
|
loadDraft,
|
|
workloadHours,
|
|
subjectPayload,
|
|
compatibleGroups,
|
|
planTeacherEndpoint,
|
|
} from '../react/admin/study-plans-service.js';
|
|
import { allowedAdminTabs } from '../react/admin/admin-service.js';
|
|
|
|
test('лабораторные 18×2 увеличивают нагрузку до 108, учебные часы остаются 90', () => {
|
|
const loads = loadDraft();
|
|
loads[0].academicHours = 36;
|
|
loads[1].academicHours = 36;
|
|
loads[2].academicHours = 18;
|
|
loads[2].splitSubgroups = true;
|
|
const payload = subjectPayload(loads, 5);
|
|
assert.equal(
|
|
payload.loads.reduce((sum, l) => sum + l.academicHours, 0),
|
|
90,
|
|
);
|
|
assert.equal(
|
|
loads.reduce((sum, l) => sum + workloadHours(l), 0),
|
|
108,
|
|
);
|
|
assert.equal(payload.expectedRevision, 5);
|
|
loads[0].splitSubgroups = true;
|
|
assert.equal(workloadHours(loads[0]), 36);
|
|
assert.equal(subjectPayload(loads, 5).loads[0].splitSubgroups, false);
|
|
});
|
|
test('запрещены нечётные часы и нулевая нагрузка с преподавателем', () => {
|
|
const loads = loadDraft();
|
|
loads[0].academicHours = 17;
|
|
assert.throws(() => subjectPayload(loads, 1), /чётными/);
|
|
loads[0].academicHours = 18;
|
|
loads[2].teacherId = 4;
|
|
assert.throws(() => subjectPayload(loads, 1), /нулевой/);
|
|
});
|
|
test('назначение доступно только группам нужного профиля, формы и номера семестра', () => {
|
|
const plan = {
|
|
specialtyProfileId: 2,
|
|
educationFormId: 1,
|
|
semesterNumber: 3,
|
|
};
|
|
const metadata = {
|
|
semesters: [{ id: 4, startYear: 2026, semesterType: 'autumn' }],
|
|
groups: [
|
|
{
|
|
id: 1,
|
|
specialtyProfileId: 2,
|
|
educationFormId: 1,
|
|
yearStartStudy: 2025,
|
|
},
|
|
{
|
|
id: 2,
|
|
specialtyProfileId: 3,
|
|
educationFormId: 1,
|
|
yearStartStudy: 2025,
|
|
},
|
|
{
|
|
id: 3,
|
|
specialtyProfileId: 2,
|
|
educationFormId: 1,
|
|
yearStartStudy: 2026,
|
|
},
|
|
{
|
|
id: 4,
|
|
specialtyProfileId: 2,
|
|
educationFormId: 2,
|
|
yearStartStudy: 2025,
|
|
},
|
|
],
|
|
};
|
|
assert.deepEqual(
|
|
compatibleGroups(metadata, plan, 4).map((g) => g.id),
|
|
[1],
|
|
);
|
|
});
|
|
test('выбор преподавателя в правиле передаёт все группы и вид нагрузки для пересечения профилей', () => {
|
|
const url = new URL(
|
|
planTeacherEndpoint(3, 'Иванов', [7, 8], 4, 2),
|
|
'http://localhost',
|
|
);
|
|
assert.deepEqual(url.searchParams.getAll('groupId'), ['7', '8']);
|
|
assert.equal(url.searchParams.get('subjectId'), '3');
|
|
assert.equal(url.searchParams.get('lessonTypeId'), '2');
|
|
});
|
|
test('учебные планы доступны администратору, учебному отделу и кафедре', () => {
|
|
for (const role of ['ADMIN', 'EDUCATION_OFFICE', 'DEPARTMENT'])
|
|
assert.ok(allowedAdminTabs(role).has('study-plans'));
|
|
assert.ok(!allowedAdminTabs('SCHEDULE_VIEWER').has('study-plans'));
|
|
});
|
|
|
|
import { plannedTypeLimits } from '../react/admin/study-plans-service.js';
|
|
test('часы плана подставляются в объекты видов нагрузки конструктора, сохраняя неделю начала', () => {
|
|
const current = {
|
|
lecture: { hours: '0', startWeek: '3' },
|
|
practice: { hours: '0', startWeek: '1' },
|
|
laboratory: { hours: '0', startWeek: '1' },
|
|
};
|
|
const next = plannedTypeLimits(
|
|
[
|
|
{ category: 'LECTURE', academicHours: 36 },
|
|
{ category: 'LABORATORY', academicHours: 18 },
|
|
],
|
|
current,
|
|
);
|
|
assert.equal(next.lecture.hours, '36');
|
|
assert.equal(next.lecture.startWeek, '3');
|
|
assert.equal(next.laboratory.hours, '18');
|
|
assert.equal(next.practice.hours, '0');
|
|
});
|