1111 * a server refusal is shown in place; a reader who may not edit the status
1212 * field — and every path that does not opt in — keeps the readout.
1313 *
14+ * The last two groups pin objectstack#30075 (ruling: option A): the
15+ * synthesized default record page's path carries the opt-in, mounted here as
16+ * the JSON document `buildDefaultPageSchema` emits, through the real
17+ * `SchemaRenderer`; an authored `highlights` slot keeps its declared value;
18+ * and a stage the field's blocking `state_machine` cannot reach from the
19+ * stored value is never offered as a press.
20+ *
1421 * The subject is imported relatively and `@object-ui/*` resolves to source
1522 * through the root vitest alias table, so nothing here reads a `dist/`.
1623 */
@@ -19,7 +26,7 @@ import * as React from 'react';
1926import { describe , it , expect , vi , afterEach , beforeEach } from 'vitest' ;
2027import { render , cleanup , fireEvent , screen , waitFor , within } from '@testing-library/react' ;
2128import '@testing-library/jest-dom' ;
22- import { InlineEditProvider , RecordContextProvider , useInlineEdit } from '@object-ui/react' ;
29+ import { InlineEditProvider , RecordContextProvider , SchemaRenderer , useInlineEdit } from '@object-ui/react' ;
2330
2431const { permsStub, perms } = vi . hoisted ( ( ) => {
2532 const perms : { isLoaded : boolean ; writeDenied : string [ ] } = { isLoaded : true , writeDenied : [ ] } ;
@@ -49,6 +56,9 @@ vi.mock('@object-ui/permissions', async (importOriginal) => {
4956} ) ;
5057
5158import { RecordPathRenderer } from '../record-path' ;
59+ import { buildDefaultPageSchema } from '../../synth/buildDefaultPageSchema' ;
60+ // Registers `record:path` for the `SchemaRenderer` mounts below.
61+ import '../../index' ;
5262
5363const STAGES = [
5464 { value : 'draft' , label : 'Draft' } ,
@@ -272,3 +282,151 @@ describe('record:path allowStageChange — who sees the readout', () => {
272282 await waitFor ( ( ) => noButtons ( container ) ) ;
273283 } ) ;
274284} ) ;
285+
286+ /** The object as a host binds it: a stage picklist the default page derives its path from. */
287+ const QUOTE_DEF = {
288+ name : 'crm_quote' ,
289+ fields : {
290+ name : { type : 'text' , label : 'Name' } ,
291+ status : {
292+ type : 'select' ,
293+ label : 'Status' ,
294+ options : STAGES . map ( ( { value, label } ) => ( { value, label } ) ) ,
295+ } ,
296+ amount : { type : 'currency' , label : 'Amount' } ,
297+ } ,
298+ stageField : 'status' ,
299+ } ;
300+
301+ /** A blocking machine: from draft only in_review (or declined); never straight to accepted. */
302+ const MACHINE = {
303+ type : 'state_machine' ,
304+ name : 'quote_flow' ,
305+ field : 'status' ,
306+ message : 'A quote cannot skip review.' ,
307+ transitions : { draft : [ 'in_review' , 'declined' ] , in_review : [ 'accepted' , 'declined' ] } ,
308+ } ;
309+
310+ /** Every `record:path` node among a synthesized page's top-level components. */
311+ const pathNodesOf = ( page : any ) : any [ ] =>
312+ page . regions [ 0 ] . components . filter ( ( c : any ) => c ?. type === 'record:path' ) ;
313+
314+ function mountNode ( node : unknown , opts : Omit < MountOptions , 'allowStageChange' > = { } ) {
315+ const dataSource = opts . dataSource ?? makeDataSource ( ) ;
316+ const refresh = opts . refresh ?? vi . fn ( async ( ) => { } ) ;
317+ const r = render (
318+ < RecordContextProvider
319+ objectName = "crm_quote"
320+ recordId = "q1"
321+ data = { { id : 'q1' , status : 'draft' , updated_at : VERSION } }
322+ objectSchema = { opts . objectSchema ?? QUOTE_DEF }
323+ dataSource = { dataSource as any }
324+ refresh = { refresh }
325+ >
326+ < InlineEditProvider canEdit = { opts . canEdit ?? true } >
327+ < SchemaRenderer schema = { node as never } />
328+ </ InlineEditProvider >
329+ </ RecordContextProvider > ,
330+ ) ;
331+ return { ...r , dataSource, refresh } ;
332+ }
333+
334+ const buttonNames = ( row : HTMLElement ) : ( string | null ) [ ] =>
335+ within ( row ) . queryAllByRole ( 'button' ) . map ( ( b ) => b . getAttribute ( 'aria-label' ) ) ;
336+
337+ describe ( '#30075 the default record page turns click-to-advance on' , ( ) => {
338+ it ( 'the synthesized page writes allowStageChange: true on its path node' , ( ) => {
339+ const [ path ] = pathNodesOf ( buildDefaultPageSchema ( QUOTE_DEF as never ) ) ;
340+ expect ( path . properties ) . toMatchObject ( { statusField : 'status' , allowStageChange : true } ) ;
341+ } ) ;
342+
343+ it ( 'a reader who may edit the stage field gets a press, with a confirmation, through the record update' , async ( ) => {
344+ const [ path ] = pathNodesOf ( buildDefaultPageSchema ( QUOTE_DEF as never ) ) ;
345+ const { container, dataSource, refresh } = mountNode ( path ) ;
346+ expect ( rows ( container ) ) . toHaveLength ( 2 ) ;
347+ for ( const row of rows ( container ) ) {
348+ expect ( buttonNames ( row ) ) . toEqual ( [ 'Move to In review' , 'Move to Accepted' , 'Move to Declined' ] ) ;
349+ }
350+ fireEvent . click ( within ( rows ( container ) [ 0 ] ) . getByRole ( 'button' , { name : 'Move to In review' } ) ) ;
351+ // Nothing is written before the reader confirms.
352+ const dialog = await screen . findByRole ( 'alertdialog' ) ;
353+ expect ( dataSource . update ) . not . toHaveBeenCalled ( ) ;
354+ fireEvent . click ( within ( dialog ) . getByRole ( 'button' , { name : 'Move' } ) ) ;
355+ await waitFor ( ( ) => expect ( dataSource . update ) . toHaveBeenCalledTimes ( 1 ) ) ;
356+ expect ( dataSource . update ) . toHaveBeenCalledWith ( 'crm_quote' , 'q1' , { status : 'in_review' } , { ifMatch : VERSION } ) ;
357+ await waitFor ( ( ) => expect ( refresh ) . toHaveBeenCalledTimes ( 1 ) ) ;
358+ } ) ;
359+
360+ it ( 'a reader the page may not let edit this record keeps the read-only path' , ( ) => {
361+ const [ path ] = pathNodesOf ( buildDefaultPageSchema ( QUOTE_DEF as never ) ) ;
362+ const { container } = mountNode ( path , { canEdit : false } ) ;
363+ expect ( rows ( container ) ) . toHaveLength ( 2 ) ;
364+ for ( const row of rows ( container ) ) expect ( row . querySelectorAll ( 'button,[tabindex]' ) ) . toHaveLength ( 0 ) ;
365+ } ) ;
366+
367+ it ( 'a reader without the edit grant on the stage field keeps the read-only path' , ( ) => {
368+ perms . writeDenied = [ 'status' ] ;
369+ const [ path ] = pathNodesOf ( buildDefaultPageSchema ( QUOTE_DEF as never ) ) ;
370+ const { container } = mountNode ( path ) ;
371+ expect ( rows ( container ) ) . toHaveLength ( 2 ) ;
372+ for ( const row of rows ( container ) ) expect ( row . querySelectorAll ( 'button,[tabindex]' ) ) . toHaveLength ( 0 ) ;
373+ } ) ;
374+
375+ it . each ( [ true , false ] ) ( 'an authored highlights slot keeps its declared allowStageChange: %s' , ( declared ) => {
376+ const authored = { type : 'record:path' , properties : { statusField : 'status' , stages : STAGES , allowStageChange : declared } } ;
377+ const page = buildDefaultPageSchema ( QUOTE_DEF as never , { slots : { highlights : [ authored ] } } as never ) ;
378+ const [ path ] = pathNodesOf ( page ) ;
379+ expect ( path . properties . allowStageChange ) . toBe ( declared ) ;
380+ const { container } = mountNode ( path ) ;
381+ const names = buttonNames ( rows ( container ) [ 0 ] ) ;
382+ expect ( names . length > 0 ) . toBe ( declared ) ;
383+ } ) ;
384+
385+ it ( 'an authored highlights slot that leaves the key out keeps the readout' , ( ) => {
386+ const authored = { type : 'record:path' , properties : { statusField : 'status' , stages : STAGES } } ;
387+ const page = buildDefaultPageSchema ( QUOTE_DEF as never , { slots : { highlights : [ authored ] } } as never ) ;
388+ const [ path ] = pathNodesOf ( page ) ;
389+ expect ( 'allowStageChange' in path . properties ) . toBe ( false ) ;
390+ for ( const row of rows ( mountNode ( path ) . container ) ) expect ( buttonNames ( row ) ) . toEqual ( [ ] ) ;
391+ } ) ;
392+ } ) ;
393+
394+ describe ( '#30075 the press offers only the moves the field\'s state machine admits' , ( ) => {
395+ const MACHINED = { ...QUOTE_DEF , validations : [ MACHINE ] } ;
396+
397+ it ( 'a stage the machine cannot reach from the stored value is a readout, not a button' , ( ) => {
398+ const [ path ] = pathNodesOf ( buildDefaultPageSchema ( MACHINED as never ) ) ;
399+ const { container } = mountNode ( path , { objectSchema : MACHINED } ) ;
400+ for ( const row of rows ( container ) ) {
401+ expect ( buttonNames ( row ) ) . toEqual ( [ 'Move to In review' , 'Move to Declined' ] ) ;
402+ // The unreachable stage is still drawn, as a plain listitem.
403+ expect ( within ( row ) . getByText ( 'Accepted' ) . closest ( 'button' ) ) . toBeNull ( ) ;
404+ }
405+ } ) ;
406+
407+ it ( 'control: a warning-severity machine does not narrow the press (the server would not refuse)' , ( ) => {
408+ const warned = { ...QUOTE_DEF , validations : [ { ...MACHINE , severity : 'warning' } ] } ;
409+ const [ path ] = pathNodesOf ( buildDefaultPageSchema ( warned as never ) ) ;
410+ const { container } = mountNode ( path , { objectSchema : warned } ) ;
411+ expect ( buttonNames ( rows ( container ) [ 0 ] ) ) . toEqual ( [ 'Move to In review' , 'Move to Accepted' , 'Move to Declined' ] ) ;
412+ } ) ;
413+
414+ it ( 'a move the server still refuses (here a required field elsewhere) is shown in place, nothing else changes' , async ( ) => {
415+ const refusal = Object . assign ( new Error ( 'VALIDATION_FAILED' ) , {
416+ code : 'VALIDATION_FAILED' ,
417+ fields : [ { field : 'amount' , code : 'required' , message : 'is required to send a quote for review' } ] ,
418+ } ) ;
419+ const [ path ] = pathNodesOf ( buildDefaultPageSchema ( MACHINED as never ) ) ;
420+ const { container, refresh } = mountNode ( path , {
421+ objectSchema : MACHINED ,
422+ dataSource : makeDataSource ( async ( ) => { throw refusal ; } ) ,
423+ } ) ;
424+ await pressAndConfirm ( container , 'In review' ) ;
425+ const alert = await within ( container ) . findByRole ( 'alert' ) ;
426+ expect ( alert ) . toHaveTextContent ( 'Amount: is required to send a quote for review' ) ;
427+ expect ( refresh ) . not . toHaveBeenCalled ( ) ;
428+ for ( const row of rows ( container ) ) {
429+ expect ( row . querySelector ( '[aria-current="step"]' ) ) . toHaveAttribute ( 'aria-label' , 'Draft, current stage' ) ;
430+ }
431+ } ) ;
432+ } ) ;
0 commit comments