Files
Adminive/frontend/src/gallery_protocol.test.mjs
2026-08-08 19:16:58 +08:00

16 lines
1.2 KiB
JavaScript

import assert from 'node:assert/strict';
import {describe, it} from 'node:test';
import {collect_slot_names, ordered_slots, resolve_renderer_kind} from './gallery_protocol.js';
describe('gallery protocol', () => {
it('recursively preserves backend slot order', () => {
assert.deepEqual(collect_slot_names({kind: 'frontend', children: [{kind: 'slot', slot: 'alpha'}, {kind: 'group', children: [{kind: 'slot', slot: 'beta'}]}]}), ['alpha', 'beta']);
});
it('uses the manifest registry instead of business field knowledge', () => {
const manifest = {protocol: 'adminive.composition-manifest', protocol_version: 1, view: {protocol: 'adminive.view', protocol_version: 1, kind: 'composition', name: 'demo', body: {kind: 'frontend', children: [{kind: 'slot', slot: 'one'}, {kind: 'slot', slot: 'two'}]}}, slots: {one: {component_kind: 'amis_schema', schema: {type: 'tpl'}}, two: {component_kind: 'amis_schema', schema: {type: 'form'}}}};
assert.deepEqual(ordered_slots(manifest).map(item => item.name), ['one', 'two']);
});
it('rejects an unregistered component kind', () => {
assert.throws(() => resolve_renderer_kind('vue_component', new Set(['amis_schema'])), /未注册的 component_kind/);
});
});