store-template-schema.test.mjs 1.62 KB
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { loadSchemaFixture } from './schemaFixture.mjs'

const storeSchema = loadSchemaFixture('store')

function findFieldByKey(list, key) {
	return list.find(item => item.key === key)
}

describe('store template schema fixture', () => {
	it('IT-STORE-TPL-001: F2-1 completeFun targets F2-2 staff count', () => {
		const f21 = findFieldByKey(storeSchema.list, 'F2-1')
		assert.equal(f21?.type, 'multipleSelect')
		assert.equal(f21?.optionsKey, 'storeStaffList')
		assert.deepEqual(f21?.completeFun, {
			key: 'F2-2',
			result: '(list.length)'
		})
	})

	it('IT-STORE-TPL-002: F2-2 has disabledFun keyed on F2-1', () => {
		const f22 = findFieldByKey(storeSchema.list, 'F2-2')
		assert.equal(f22?.type, 'numberInput')
		assert.equal(f22?.value, 0)
		assert.deepEqual(f22?.disabledFun, {
			keys: ['F2-1'],
			result: 'val1 != null'
		})
	})

	it('IT-STORE-TPL-003: F2-91 isYB divider includes ybCode and qyCode', () => {
		const divider = findFieldByKey(storeSchema.list, 'F2-91')
		assert.equal(divider?.type, 'divider')
		assert.equal(divider?.isYB, true)
		assert.deepEqual(divider?.ybCode, [110201, 110202])
		assert.deepEqual(divider?.qyCode, [110101, 110102])
	})

	it('IT-STORE-TPL-004: F2-11 other-brand subform has filterBrandId', () => {
		const subform = findFieldByKey(storeSchema.list, 'F2-11')
		assert.equal(subform?.type, 'subform')
		assert.deepEqual(subform?.filterBrandId, [
			3454, 3503, 3458, 3574, 3502, 3067
		])
		const orderChild = subform?.children?.[0]?.find(item => item.key === 'F2-11-1')
		assert.equal(orderChild?.optionsKey, '4sStaffList')
	})
})