|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +/** |
| 4 | + * objectstack#36860 — `walkMetadataForms` emits the form field slot |
| 5 | + * `metadataForms.<type>.fields.<path>.label` for every Studio list column |
| 6 | + * (`METADATA_LIST_REGISTRY`), so the server can translate each header. |
| 7 | + * |
| 8 | + * - a column whose path the type's form does not label (a type with no form, |
| 9 | + * or a path the form leaves out) gets its own entry, seeded with the |
| 10 | + * column's header; |
| 11 | + * - a column the form already labels keeps the form's entry, so the slot |
| 12 | + * holds one English source; |
| 13 | + * - every column of every type has an entry, so no header reaches a reader |
| 14 | + * untranslatable. |
| 15 | + */ |
| 16 | +import { describe, it, expect } from 'vitest'; |
| 17 | +import { METADATA_LIST_REGISTRY } from '@objectstack/spec/system'; |
| 18 | +import { collectExpectedEntries } from './i18n-walk.js'; |
| 19 | + |
| 20 | +const entries = collectExpectedEntries({}, { warnedGroups: new Set() }); |
| 21 | +const slot = (type: string, path: string) => |
| 22 | + entries.filter((e) => e.path.join('\u0000') === ['metadataForms', type, 'fields', path, 'label'].join('\u0000')); |
| 23 | + |
| 24 | +describe('list column headers are walked into the form field slot (objectstack#36860)', () => { |
| 25 | + it('a column on a type with no form gets its own entry, seeded with the header', () => { |
| 26 | + const [entry] = slot('job', 'schedule'); |
| 27 | + expect(entry).toBeDefined(); |
| 28 | + expect(entry.sourceValue).toBe('Schedule'); |
| 29 | + }); |
| 30 | + |
| 31 | + it('a dotted column path the form does not label gets its own entry', () => { |
| 32 | + const [entry] = slot('agent', 'model.model'); |
| 33 | + expect(entry).toBeDefined(); |
| 34 | + expect(entry.sourceValue).toBe('Model'); |
| 35 | + }); |
| 36 | + |
| 37 | + it('a column the form already labels keeps one entry, the form field\'s', () => { |
| 38 | + const found = slot('hook', 'events'); |
| 39 | + expect(found).toHaveLength(1); |
| 40 | + expect(found[0].source).toBe('metadataFormField'); |
| 41 | + }); |
| 42 | + |
| 43 | + it('every column of every declared list has an entry at its slot', () => { |
| 44 | + const missing: string[] = []; |
| 45 | + for (const [type, list] of Object.entries(METADATA_LIST_REGISTRY)) { |
| 46 | + for (const column of list.columns) { |
| 47 | + if (slot(type, column.field).length !== 1) missing.push(`${type}.${column.field}`); |
| 48 | + } |
| 49 | + } |
| 50 | + expect(missing).toEqual([]); |
| 51 | + }); |
| 52 | +}); |
0 commit comments