|
| 1 | +/** |
| 2 | + * ObjectUI |
| 3 | + * Copyright (c) 2024-present ObjectStack Inc. |
| 4 | + * |
| 5 | + * This source code is licensed under the MIT license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. |
| 7 | + */ |
| 8 | + |
| 9 | +/** |
| 10 | + * The parser-tier half of the `header-bar` refusal clause, held on the live |
| 11 | + * registry (objectui#10981, the open question from objectui#10959). |
| 12 | + * |
| 13 | + * objectui#10959 corrected the `HeaderBarSchema` refusals of objectui#10387 |
| 14 | + * (`title`, `logo`, `nav`, `left`, `center`, `right`, `sticky`, `height`) and |
| 15 | + * objectui#10286 (`variant`) to say that nothing warned at render, and that |
| 16 | + * "only the parser tier's `unknown-prop` warning noticed it". The pin for that |
| 17 | + * wording lives in `@object-ui/types`, which cannot import the parser, so it |
| 18 | + * holds the prose only. The parser-tier behaviour was measured once, on the |
| 19 | + * objectui#10959 pull request, and pinned nowhere: `validateTree`'s generic |
| 20 | + * undeclared-key branch answers it, and no parser pin names `header-bar`. |
| 21 | + * |
| 22 | + * This file holds that half where the registry lives. The manifest is built |
| 23 | + * the way `container-declaration-ratchet.test.tsx` builds it — every KNOWN |
| 24 | + * registry key, through `manifestFromConfigs` — so a registration that starts |
| 25 | + * declaring one of these keys as an input turns this red, and so does a change |
| 26 | + * to the parser that stops answering an undeclared key with `unknown-prop`. |
| 27 | + * Either one makes the published clause false, and this is where it shows. |
| 28 | + * |
| 29 | + * Both spellings are held: the bare `header-bar` and the namespaced |
| 30 | + * `ui:header-bar`. Every value shape the objectui#10387 / objectui#10286 pins |
| 31 | + * refuse is held too, because the answer depends only on the key being |
| 32 | + * undeclared, and a pin that tried one shape could not show that. |
| 33 | + */ |
| 34 | + |
| 35 | +import { describe, it, expect } from 'vitest'; |
| 36 | +import { ComponentRegistry } from '@object-ui/core'; |
| 37 | +import { manifestFromConfigs, validateTree } from '@object-ui/sdui-parser'; |
| 38 | +import type { Diagnostic, SchemaElement } from '@object-ui/sdui-parser'; |
| 39 | + |
| 40 | +// Module scope, not a hook: this import IS the registration (AGENTS.md |
| 41 | +// §测试纪律 — an unbounded module load must not be billed to a bounded window). |
| 42 | +import '../index'; |
| 43 | + |
| 44 | +/** Every live registry key, as `container-declaration-ratchet.test.tsx` builds it. */ |
| 45 | +const diagnose = (schema: unknown): Diagnostic[] => { |
| 46 | + const configs = ComponentRegistry.getKnownTypes().map((t) => { |
| 47 | + const meta = ComponentRegistry.getMeta(t); |
| 48 | + return { type: t, namespace: meta?.namespace, isContainer: meta?.isContainer, inputs: meta?.inputs }; |
| 49 | + }); |
| 50 | + const manifest = manifestFromConfigs(configs as unknown as Parameters<typeof manifestFromConfigs>[0]); |
| 51 | + return validateTree(schema as SchemaElement, manifest).diagnostics; |
| 52 | +}; |
| 53 | + |
| 54 | +const TEXT = { type: 'text', content: 'x' }; |
| 55 | + |
| 56 | +/** The refused keys and the values their `@object-ui/types` pins refuse. */ |
| 57 | +const RETIRED: Record<string, unknown[]> = { |
| 58 | + title: ['My App'], |
| 59 | + logo: ['/logo.svg', TEXT, [TEXT]], |
| 60 | + nav: [[{ label: 'Docs', href: '/docs' }], []], |
| 61 | + left: [TEXT, [TEXT], 'plain text'], |
| 62 | + center: [TEXT, [TEXT], 'plain text'], |
| 63 | + right: [TEXT, [TEXT]], |
| 64 | + sticky: [true, false], |
| 65 | + height: ['64px', 64], |
| 66 | + variant: ['default', 'bordered', 'floating', 'transparent'], |
| 67 | +}; |
| 68 | + |
| 69 | +const TYPES = ['header-bar', 'ui:header-bar'] as const; |
| 70 | +const CRUMBS = [{ label: 'Home', href: '/' }]; |
| 71 | + |
| 72 | +describe('header-bar — the refused keys draw exactly the parser tier\'s `unknown-prop` (objectui#10981)', () => { |
| 73 | + it.each(TYPES)('`%s` is a live registration, and its control draws nothing', (type) => { |
| 74 | + expect(ComponentRegistry.getKnownTypes()).toContain(type); |
| 75 | + expect(diagnose({ type, crumbs: CRUMBS })).toEqual([]); |
| 76 | + }); |
| 77 | + |
| 78 | + it.each(TYPES)('`%s` — every refused key, in every refused shape, draws one `unknown-prop` naming it', (type) => { |
| 79 | + const wrong: string[] = []; |
| 80 | + for (const [key, values] of Object.entries(RETIRED)) { |
| 81 | + for (const value of values) { |
| 82 | + const found = diagnose({ type, crumbs: CRUMBS, [key]: value }); |
| 83 | + const one = found.length === 1 ? found[0] : undefined; |
| 84 | + if (one?.code !== 'unknown-prop' || !one.message.includes(`"${key}"`)) { |
| 85 | + wrong.push(`${key}=${JSON.stringify(value)} → ${JSON.stringify(found.map((d) => d.code))}`); |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | + expect(wrong).toEqual([]); |
| 90 | + }); |
| 91 | + |
| 92 | + it.each(TYPES)('`%s` — lit control: the keys it does declare draw no `unknown-prop`', (type) => { |
| 93 | + const declared = (ComponentRegistry.getMeta(type)?.inputs ?? []).map((input) => input.name); |
| 94 | + expect(declared).toContain('crumbs'); |
| 95 | + for (const key of Object.keys(RETIRED)) expect(declared).not.toContain(key); |
| 96 | + const found = diagnose({ type, crumbs: CRUMBS, rightContent: TEXT }); |
| 97 | + expect(found.filter((d) => d.code === 'unknown-prop')).toEqual([]); |
| 98 | + }); |
| 99 | +}); |
0 commit comments