тесты
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
import { ComparisonOperator, Employee, HeadType, ProjectRole, RouteStepStatus, TemplateRouteStep } from '../models';
|
||||
import { describeStepCondition, describeStepExecutor, detectExecutorKind } from './stepExecutor';
|
||||
|
||||
function step(overrides: Partial<TemplateRouteStep>): TemplateRouteStep {
|
||||
return {
|
||||
id: 1,
|
||||
orderNo: 1,
|
||||
executorEmail: null,
|
||||
position: null,
|
||||
projectRole: null,
|
||||
headType: null,
|
||||
status: RouteStepStatus.Approval,
|
||||
routeId: 1,
|
||||
allowReassignToOtherApprovers: false,
|
||||
fieldName: null,
|
||||
operation: null,
|
||||
value: null,
|
||||
...overrides
|
||||
};
|
||||
}
|
||||
|
||||
describe('detectExecutorKind', () => {
|
||||
it('email имеет приоритет над остальными способами', () => {
|
||||
expect(detectExecutorKind({ executorEmail: 'a@tnsu.kz', position: 'Директор' })).toBe('email');
|
||||
});
|
||||
|
||||
it('при отсутствии email — position', () => {
|
||||
expect(detectExecutorKind({ position: 'Директор' })).toBe('position');
|
||||
});
|
||||
|
||||
it('при отсутствии email/position — projectRole, если он не None', () => {
|
||||
expect(detectExecutorKind({ projectRole: ProjectRole.Planner })).toBe('projectRole');
|
||||
});
|
||||
|
||||
it('projectRole=None не считается заданным способом', () => {
|
||||
expect(detectExecutorKind({ projectRole: ProjectRole.None })).toBe('headType');
|
||||
});
|
||||
|
||||
it('если ничего не задано — headType (последний вариант по умолчанию)', () => {
|
||||
expect(detectExecutorKind({})).toBe('headType');
|
||||
});
|
||||
});
|
||||
|
||||
describe('describeStepExecutor', () => {
|
||||
const employees: Employee[] = [{ fio: 'Горбенко Павел', email: 'gorbenko.pavel@tnsu.kz', position: 'Разработчик' }];
|
||||
|
||||
it('для email найденного сотрудника показывает ФИО и email отдельной строкой', () => {
|
||||
const result = describeStepExecutor(step({ executorEmail: 'gorbenko.pavel@tnsu.kz' }), employees);
|
||||
expect(result).toEqual({ primary: 'Горбенко Павел', secondary: 'gorbenko.pavel@tnsu.kz' });
|
||||
});
|
||||
|
||||
it('для email, которого нет в справочнике, показывает сам email без secondary', () => {
|
||||
const result = describeStepExecutor(step({ executorEmail: 'unknown@tnsu.kz' }), employees);
|
||||
expect(result).toEqual({ primary: 'unknown@tnsu.kz' });
|
||||
});
|
||||
|
||||
it('для шага по должности показывает должность', () => {
|
||||
const result = describeStepExecutor(step({ position: 'Главный бухгалтер' }), employees);
|
||||
expect(result.primary).toBe('Главный бухгалтер');
|
||||
});
|
||||
|
||||
it('для шага по проектной роли показывает подпись роли', () => {
|
||||
const result = describeStepExecutor(step({ projectRole: ProjectRole.Planner }), employees);
|
||||
expect(result.primary).toEqual(expect.stringContaining('Роль:'));
|
||||
});
|
||||
|
||||
it('для шага по типу руководителя показывает подпись типа', () => {
|
||||
const result = describeStepExecutor(step({ headType: HeadType.Chief }), employees);
|
||||
expect(result.primary).toEqual(expect.stringContaining('Руководитель:'));
|
||||
});
|
||||
|
||||
it('если у шага вообще не задан исполнитель — пустое значение', () => {
|
||||
const result = describeStepExecutor(step({}), employees);
|
||||
expect(result.secondary).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('describeStepCondition', () => {
|
||||
it('undefined, если условие не задано целиком', () => {
|
||||
expect(describeStepCondition(step({}))).toBeUndefined();
|
||||
});
|
||||
|
||||
it('undefined, если operation === None', () => {
|
||||
expect(describeStepCondition(step({ fieldName: 'Amount', operation: ComparisonOperator.None, value: '100' }))).toBeUndefined();
|
||||
});
|
||||
|
||||
it('собирает "поле оператор значение", если условие задано полностью', () => {
|
||||
const result = describeStepCondition(step({ fieldName: 'Amount', operation: ComparisonOperator.GreaterThan, value: '100' }));
|
||||
expect(result).toBe('Amount > 100');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user