|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +/** |
| 4 | + * objectui#11173 — the `page:header` panel on screen after the designer's |
| 5 | + * `breadcrumb` toggle left `BLOCK_CONFIG['page:header']`. |
| 6 | + * |
| 7 | + * The sibling `previews/__tests__/block-config.test.ts` pins the TABLE (the |
| 8 | + * curated field set is `title` / `subtitle`). This file pins the two facts only |
| 9 | + * a real render and a real commit can answer: |
| 10 | + * |
| 11 | + * - the panel offers no breadcrumb control, in either locale; |
| 12 | + * - a page that ALREADY carries `breadcrumb` (a released designer build wrote |
| 13 | + * it) opens, and its next save keeps the key. That is the triage ruling on |
| 14 | + * the card: no strip in the designer. objectstack#20758's ADR-0087 |
| 15 | + * conversion is the one strip, on load, with its notice; a second strip |
| 16 | + * here would be a second mechanism and would hide that notice. So |
| 17 | + * `RETIRED_BLOCK_PROP_KEYS` has no `page:header` entry, and the round-trip |
| 18 | + * case below is the control that goes red if one is added. |
| 19 | + * |
| 20 | + * FIXTURE DISCIPLINE (#3216's method, as in the sibling suites): the page is |
| 21 | + * authored the way a user does and fed through `PageSchema.parse`, so the |
| 22 | + * fixture cannot drift from the spec. `PageSchema` does not judge a block's |
| 23 | + * `properties` (the sibling `PageBlockInspector.retiredBlockProps.test.tsx` |
| 24 | + * header records that measurement), so the stored fixture keeps parsing when a |
| 25 | + * later spec pin tombstones the key. |
| 26 | + */ |
| 27 | + |
| 28 | +import { describe, it, expect, vi, afterEach } from 'vitest'; |
| 29 | +import { render, screen, fireEvent, cleanup } from '@testing-library/react'; |
| 30 | +import { PageSchema } from '@objectstack/spec/ui'; |
| 31 | + |
| 32 | +// objectui#4697 — see PageBlockInspector.i18n.test.tsx for the full mechanism; |
| 33 | +// same STABLE stub, short-circuiting useObjectFields/useObjectOptions's |
| 34 | +// mount-time fetch instead of letting it escape to the real network. No |
| 35 | +// assertion here reads the fetched object list or its fields. |
| 36 | +const state = vi.hoisted(() => ({ |
| 37 | + metadataClient: { get: vi.fn(async () => undefined), list: vi.fn(async () => [] as unknown[]) }, |
| 38 | +})); |
| 39 | +vi.mock('../useMetadata', () => ({ |
| 40 | + useMetadataClient: () => state.metadataClient, |
| 41 | +})); |
| 42 | + |
| 43 | +import { PageBlockInspector } from './PageBlockInspector'; |
| 44 | + |
| 45 | +afterEach(cleanup); |
| 46 | + |
| 47 | +const BLOCK_PATH = 'regions[0].components[0]'; |
| 48 | + |
| 49 | +/** A record page carrying one `page:header` block with the given properties. */ |
| 50 | +function pageDraft(properties: Record<string, unknown>): Record<string, unknown> { |
| 51 | + return PageSchema.parse({ |
| 52 | + name: 'account_record', |
| 53 | + label: 'Account', |
| 54 | + type: 'record', |
| 55 | + object: 'account', |
| 56 | + template: 'default', |
| 57 | + regions: [{ name: 'main', components: [{ type: 'page:header', id: 'b1', properties }] }], |
| 58 | + }) as unknown as Record<string, unknown>; |
| 59 | +} |
| 60 | + |
| 61 | +function renderInspector( |
| 62 | + draft: Record<string, unknown>, |
| 63 | + locale: 'en-US' | 'zh-CN', |
| 64 | + onPatch = vi.fn(), |
| 65 | +) { |
| 66 | + render( |
| 67 | + <PageBlockInspector |
| 68 | + type="page" |
| 69 | + name="account_record" |
| 70 | + draft={draft} |
| 71 | + selection={{ kind: 'block', id: BLOCK_PATH }} |
| 72 | + onPatch={onPatch} |
| 73 | + onClearSelection={() => {}} |
| 74 | + readOnly={false} |
| 75 | + locale={locale as never} |
| 76 | + />, |
| 77 | + ); |
| 78 | + return onPatch; |
| 79 | +} |
| 80 | + |
| 81 | +/** The block's `properties` as the inspector last committed them. */ |
| 82 | +function committedProps(onPatch: ReturnType<typeof vi.fn>): Record<string, unknown> { |
| 83 | + const patch = onPatch.mock.calls.at(-1)![0] as { |
| 84 | + regions: Array<{ components: Array<{ properties: Record<string, unknown> }> }>; |
| 85 | + }; |
| 86 | + return patch.regions[0].components[0].properties; |
| 87 | +} |
| 88 | + |
| 89 | +const LABELS = { |
| 90 | + 'en-US': { title: 'Title', subtitle: 'Subtitle' }, |
| 91 | + 'zh-CN': { title: '标题', subtitle: '副标题' }, |
| 92 | +} as const; |
| 93 | + |
| 94 | +describe('page:header inspector · no breadcrumb toggle (objectui#11173)', () => { |
| 95 | + it.each(['en-US', 'zh-CN'] as const)('%s: offers title and subtitle, and no toggle at all', (locale) => { |
| 96 | + renderInspector(pageDraft({}), locale); |
| 97 | + // Non-vacuity: the curated section IS rendering, so the zeroes below are a |
| 98 | + // reading about the toggle rather than about an empty panel. |
| 99 | + expect(screen.getByLabelText(LABELS[locale].title)).toBeTruthy(); |
| 100 | + expect(screen.getByLabelText(LABELS[locale].subtitle)).toBeTruthy(); |
| 101 | + // The toggle was the header's only boolean control, so no checkbox is left. |
| 102 | + expect(screen.queryAllByRole('checkbox')).toEqual([]); |
| 103 | + // Neither label spelling, and no raw key standing in for a missing one. |
| 104 | + expect(screen.queryByText('Show breadcrumb')).toBeNull(); |
| 105 | + expect(screen.queryByText('显示面包屑')).toBeNull(); |
| 106 | + expect(document.body.textContent ?? '').not.toContain('engine.inspector.pageBlock.'); |
| 107 | + }); |
| 108 | +}); |
| 109 | + |
| 110 | +describe('page:header inspector · a stored `breadcrumb` round-trips (objectui#11173)', () => { |
| 111 | + /** A block saved by a released build, while the toggle was still offered. */ |
| 112 | + const stored = () => pageDraft({ title: 'Account', breadcrumb: true }); |
| 113 | + |
| 114 | + it('opens: the stored key stays visible, in Advanced under its raw name', () => { |
| 115 | + renderInspector(stored(), 'en-US'); |
| 116 | + expect((screen.getByLabelText('Title') as HTMLInputElement).value).toBe('Account'); |
| 117 | + // No longer curated, so the generic editor shows it; it was not dropped on |
| 118 | + // read, which is what a strip would have done. |
| 119 | + const box = screen.getByLabelText('breadcrumb') as HTMLInputElement; |
| 120 | + expect(box.type).toBe('checkbox'); |
| 121 | + expect(box.checked).toBe(true); |
| 122 | + }); |
| 123 | + |
| 124 | + it('saves: an edit to another field keeps `breadcrumb` in the committed document', () => { |
| 125 | + const onPatch = renderInspector(stored(), 'en-US'); |
| 126 | + fireEvent.change(screen.getByLabelText('Title'), { target: { value: 'Customer' } }); |
| 127 | + // Everything the block carried rides out; only the edited field moved. |
| 128 | + expect(committedProps(onPatch)).toEqual({ title: 'Customer', breadcrumb: true }); |
| 129 | + }); |
| 130 | +}); |
0 commit comments