刘光辉
14 小时以前 0dfe84494048ce27ba8449831782128412d3eb13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { createPinia, setActivePinia } from 'pinia';
import { beforeEach, describe, expect, it } from 'vitest';
 
import { useFillerStore } from '../../src/stores/filler';
 
describe('filler store', () => {
  beforeEach(() => setActivePinia(createPinia()));
 
  it('keeps failed drafts and commits successful fields', () => {
    const store = useFillerStore();
    store.fields = [
      { alias: 'A', tag: 'eln.field.a', internalId: 'a', type: 'text', options: [], currentValue: '', documentValue: '', draftValue: 'new' },
      { alias: 'B', tag: 'eln.field.b', internalId: 'b', type: 'text', options: [], currentValue: '', documentValue: '', draftValue: 'bad' },
    ];
    store.applyResults([{ tag: 'eln.field.a', ok: true }, { tag: 'eln.field.b', ok: false, error: '失败' }]);
    expect(store.fields[0]?.documentValue).toBe('new');
    expect(store.fields[1]?.documentValue).toBe('');
    expect(store.fieldErrors).toEqual({ 'eln.field.b': '失败' });
  });
});