刘光辉
2 小时以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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);
  });
});