import { describe, expect, it } from 'vitest';
|
|
import { canUseBatchShared, fieldActions, versionActions } from '../fieldRules';
|
|
describe('ELN field catalog action rules', () => {
|
it('limits draft versions to edit, pre-release and cancel', () => {
|
expect(versionActions({ current: false, enabled: true, status: 'DRAFT' })).toEqual(['edit', 'preRelease', 'cancel']);
|
});
|
|
it('allows pre-release versions to publish, cancel or copy', () => {
|
expect(versionActions({ current: false, enabled: true, status: 'PRE_RELEASE' })).toEqual(['publish', 'cancel', 'copy']);
|
});
|
|
it('only offers current switching for a non-current published version', () => {
|
expect(versionActions({ current: false, enabled: true, status: 'PUBLISHED' })).toEqual(['setCurrent', 'copy']);
|
expect(versionActions({ current: true, enabled: true, status: 'PUBLISHED' })).toEqual(['copy']);
|
});
|
|
it('does not expose version actions for cancelled versions', () => {
|
expect(versionActions({ current: false, enabled: true, status: 'CANCELLED' })).toEqual([]);
|
});
|
|
it('only allows cancelling editable versions after a field is disabled', () => {
|
expect(versionActions({ current: false, enabled: false, status: 'DRAFT' })).toEqual(['cancel']);
|
expect(versionActions({ current: false, enabled: false, status: 'PRE_RELEASE' })).toEqual(['cancel']);
|
expect(versionActions({ current: false, enabled: false, status: 'PUBLISHED' })).toEqual([]);
|
expect(versionActions({ current: false, enabled: false, status: 'CANCELLED' })).toEqual([]);
|
});
|
|
it('only offers promotion for enabled template fields', () => {
|
expect(fieldActions({ enabled: true, scope: 'TEMPLATE' })).toContain('promoteGlobal');
|
expect(fieldActions({ enabled: true, scope: 'GLOBAL' })).not.toContain('promoteGlobal');
|
expect(fieldActions({ enabled: false, scope: 'TEMPLATE' })).not.toContain('promoteGlobal');
|
});
|
|
it('switches the field lifecycle action between enable and disable', () => {
|
expect(fieldActions({ enabled: true, scope: 'GLOBAL' })).toContain('disable');
|
expect(fieldActions({ enabled: false, scope: 'GLOBAL' })).toContain('enable');
|
});
|
|
it('allows batch sharing only for fields without an external read source', () => {
|
expect(canUseBatchShared({ readSource: 'NONE' })).toBe(true);
|
expect(canUseBatchShared({ readSource: 'LIMS_TASK' })).toBe(false);
|
expect(canUseBatchShared({ readSource: 'SYSTEM' })).toBe(false);
|
});
|
});
|