detail-echo.test.mjs 973 Bytes
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'

import {
	stripValuesFromSchemaRoot,
	parseDetailEchoValues
} from '../form-engine/detail-echo.js'
import { createFormEngine } from '../form-engine/core.js'

describe('detail-echo', () => {
	it('IT-ECHO-001: stripValuesFromSchemaRoot removes field.value', () => {
		const root = {
			list: [{ key: 'F1-1', type: 'radio', value: '1', options: [] }]
		}
		const stripped = stripValuesFromSchemaRoot(root)
		assert.equal(stripped.list[0].value, undefined)
	})

	it('IT-ECHO-002: engine init uses initialValues not schema.value', () => {
		const engine = createFormEngine()
		const schema = {
			list: [
				{
					key: 'F1-1',
					type: 'radio',
					options: [
						{ label: '在岗', value: 'on' },
						{ label: '调休', value: 'off' }
					]
				}
			]
		}
		const view = engine.init(schema, {
			initialValues: { 'F1-1': 'on' }
		})
		assert.equal(view.values['F1-1'], 'on')
	})
})