bitrix_task_control/tests/bigSmallBuilder.test.ts

112 lines
4.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, expect, it } from 'vitest';
import {
BIG_SMALL_HEADERS,
buildBigSmallReportRows,
checkAttention,
getCrmElement,
isTaskOverdue,
} from '../src/reports/bigSmall/builder';
const headers = [
'ID',
'Название',
'ID базовой задачи',
'Дата создания',
'Крайний срок',
'Планируемая дата начала',
'Планируемая дата окончания',
'Может привести к потере клиента',
'Исполнитель',
'Постановщик',
'Цена задачи',
'CRM',
];
function row(values: Record<string, any>): any[] {
return headers.map(header => (header in values ? values[header] : ''));
}
describe('bigSmall builder helpers', () => {
it('берёт первый заполненный CRM-элемент', () => {
const col: Record<string, number> = { Лид: 0, Контакт: 1, CRM: 2 };
expect(getCrmElement(['', 'Иван', 'сделка'], col)).toBe('Иван');
});
it('определяет просрочку относительно now', () => {
const now = new Date('2026-06-18T12:00:00');
expect(isTaskOverdue(new Date('2026-06-17T12:00:00'), now)).toBe(true);
expect(isTaskOverdue(new Date('2026-06-19T12:00:00'), now)).toBe(false);
expect(isTaskOverdue('', now)).toBe(false);
});
it('собирает причины внимания', () => {
const now = new Date('2026-06-18T12:00:00');
const text = checkAttention({
taskType: 'Б',
parentDeadline: new Date('2026-06-20T12:00:00'),
taskDeadline: '',
isOverdue: true,
taskExecutionTime: 400,
taskClientLossMarker: '',
taskEnd: '',
hasSubtask: false,
taskCreationDate: new Date('2026-06-10T12:00:00'),
taskStart: '',
now,
});
expect(text.startsWith('Да:')).toBe(true);
expect(text).toContain('задача просрочена');
expect(text).toContain('нет подзадач у большой задачи');
expect(text).toContain('длителность задачи больше 6 часов');
});
});
describe('buildBigSmallReportRows', () => {
it('фильтрует по дате, сортирует и заполняет строки', () => {
const lastLaunch = new Date('2026-06-10T00:00:00');
const now = new Date('2026-06-18T15:00:00');
const parentDeadline = new Date('2026-06-25T12:00:00');
const start = new Date('2026-06-16T09:00:00');
const end = new Date('2026-06-16T10:00:00');
const sourceRows = [
row({
ID: 1,
Название: 'ЕПБ* Родитель',
'Крайний срок': parentDeadline,
}),
row({
ID: 2,
Название: 'ЕПМ* Подзадача А',
'ID базовой задачи': 1,
'Дата создания': new Date('2026-06-12T10:00:00'),
'Крайний срок': parentDeadline,
'Планируемая дата начала': start,
'Планируемая дата окончания': end,
'Может привести к потере клиента': 'Y',
Исполнитель: 'Иванов',
Постановщик: 'Петров',
'Цена задачи': 100,
CRM: 'сделка 1',
}),
row({
ID: 3,
Название: 'ЕПМ* Старая',
'Дата создания': new Date('2026-06-01T10:00:00'),
Исполнитель: 'Сидоров',
}),
];
const result = buildBigSmallReportRows(sourceRows, headers, lastLaunch, now);
expect(result[0]).toEqual(BIG_SMALL_HEADERS);
expect(result.length).toBe(2);
expect(result[1][0]).toBe('ЕПМ* Подзадача А');
expect(result[1][1]).toBe('ЕПБ* Родитель');
expect(result[1][7]).toBe('М');
expect(result[1][11]).toBe(60);
expect(result[1][12]).toBe('Да');
expect(result[1][6]).toBe('сделка 1');
});
});