@@ -37,6 +37,7 @@ import {
3737import type { DataSource } from '@object-ui/types' ;
3838// Registers `record:related_list`, the block under test.
3939import '../../index' ;
40+ import { RecordBodyTablesContext } from '../../relatedListCompact' ;
4041
4142beforeAll ( ( ) => {
4243 Object . defineProperty ( window , 'innerWidth' , { configurable : true , value : 1280 } ) ;
@@ -79,7 +80,7 @@ const ACCOUNT_ROWS: Rows = {
7980 ] ,
8081} ;
8182
82- function mount ( nodes : object [ ] , rows : Rows ) {
83+ function mount ( nodes : object [ ] , rows : Rows , bodyTables : ReadonlySet < string > = new Set ( ) ) {
8384 const ds = makeDataSource ( rows ) ;
8485 const created = vi . fn ( ) ;
8586 const host : RelatedRecordActionsValue = {
@@ -89,12 +90,14 @@ function mount(nodes: object[], rows: Rows) {
8990 < SchemaRendererProvider dataSource = { ds as unknown as DataSource } >
9091 < RecordContextProvider objectName = { PARENT } recordId = "a1" dataSource = { ds as never } >
9192 < RelatedRecordActionsProvider value = { host } >
92- { /* The stack: siblings in one container, as `page:tabs` draws a tab's children. */ }
93- < div data-testid = "stack" >
94- { nodes . map ( ( node , idx ) => (
95- < SchemaRenderer key = { idx } schema = { node as never } />
96- ) ) }
97- </ div >
93+ < RecordBodyTablesContext . Provider value = { bodyTables } >
94+ { /* The stack: siblings in one container, as `page:tabs` draws a tab's children. */ }
95+ < div data-testid = "stack" >
96+ { nodes . map ( ( node , idx ) => (
97+ < SchemaRenderer key = { idx } schema = { node as never } />
98+ ) ) }
99+ </ div >
100+ </ RecordBodyTablesContext . Provider >
98101 </ RelatedRecordActionsProvider >
99102 </ RecordContextProvider >
100103 </ SchemaRendererProvider > ,
@@ -200,3 +203,56 @@ describe('record:related_list — empty lists of a stack fold into one line (#25
200203 expect ( cardTitled ( 'Team' ) ) . toBeVisible ( ) ;
201204 } ) ;
202205} ) ;
206+
207+ /**
208+ * objectstack#29944 — the record page's BODY tables (their ids in
209+ * `RecordBodyTablesContext`) are sections of the record, drawn side by side in
210+ * the details column (or the Details tab), so they share a container like a
211+ * Related tab's lists do. They are not a related-list stack: an empty one
212+ * keeps its own header — title, 0, New — with the empty sentence under it,
213+ * where the table of a non-empty one is. Measured on hotclm's contract page:
214+ * the empty 偏离 table folded into 「暂无相关记录 偏离 + 新建」.
215+ */
216+ describe ( 'record:related_list — a body table of the record page never folds (objectstack#29944)' , ( ) => {
217+ const CONTRACT = [
218+ list ( 'crm_quote' , 'Payment plan' ) ,
219+ list ( 'crm_child_account' , 'Deviations' ) ,
220+ list ( 'crm_contact' , 'Versions' ) ,
221+ ] ;
222+ const CONTRACT_ROWS : Rows = {
223+ crm_quote : [ { id : 'q1' , name : 'Q-001' , account_id : 'a1' } ] ,
224+ crm_contact : [ { id : 'c1' , name : 'Ada' , account_id : 'a1' } ] ,
225+ } ;
226+ const BODY = new Set ( [ 'crm_quote.account_id' , 'crm_child_account.account_id' , 'crm_contact.account_id' ] ) ;
227+
228+ it ( 'an empty body table beside tables with records keeps its header, with the empty sentence under it' , async ( ) => {
229+ const { ds, created } = mount ( CONTRACT , CONTRACT_ROWS , BODY ) ;
230+ await settled ( ds , 3 ) ;
231+ // Every list has answered once Deviations counts 0; give a fold the time to draw.
232+ await screen . findByLabelText ( '0 records' ) ;
233+ await new Promise ( ( resolve ) => setTimeout ( resolve , 50 ) ) ;
234+ expect ( fold ( ) ) . toBeNull ( ) ;
235+ const title = cardTitled ( 'Deviations' ) ;
236+ expect ( title ) . toBeVisible ( ) ;
237+
238+ // The header row is the non-empty tables' header: title, count, New.
239+ const head = title . closest ( '[data-related-list-head]' ) as HTMLElement ;
240+ expect ( head ) . not . toBeNull ( ) ;
241+ fireEvent . click ( within ( head ) . getByRole ( 'button' , { name : / N e w / } ) ) ;
242+ expect ( created ) . toHaveBeenCalledWith ( 'crm_child_account' ) ;
243+
244+ // The sentence is not in the header row: it is drawn under it.
245+ expect ( within ( head ) . queryByText ( 'No related records found' ) ) . toBeNull ( ) ;
246+ const sentence = screen . getByText ( 'No related records found' ) ;
247+ expect ( sentence ) . toBeVisible ( ) ;
248+ expect ( head . compareDocumentPosition ( sentence ) & Node . DOCUMENT_POSITION_FOLLOWING ) . toBeTruthy ( ) ;
249+ } ) ;
250+
251+ it ( 'CONTROL: a Related tab stack under the same context folds as before — only the listed ids are body tables' , async ( ) => {
252+ const { ds } = mount ( ACCOUNT_STACK , ACCOUNT_ROWS , new Set ( [ 'crm_opportunity.account_id' ] ) ) ;
253+ await settled ( ds , 4 ) ;
254+ await waitFor ( ( ) => expect ( fold ( ) ) . not . toBeNull ( ) ) ;
255+ const names = within ( fold ( ) ! ) . getAllByRole ( 'group' ) . map ( ( g ) => g . getAttribute ( 'aria-label' ) ) ;
256+ expect ( names ) . toEqual ( [ 'Child accounts' , 'Leads' ] ) ;
257+ } ) ;
258+ } ) ;
0 commit comments