@@ -16,12 +16,22 @@ const subform = namedNode('http://example.com/#subForm')
1616const property = namedNode ( 'http://schema.org/knowsLanguage' )
1717const xsdBoolean = namedNode ( 'http://www.w3.org/2001/XMLSchema#boolean' )
1818
19+ /** Helper: return all list-head triples for subject/property in the test document */
20+ function getListHeads ( ) {
21+ return store . each ( subject , property , null as any , doc )
22+ }
23+
24+ /** Helper: wait for pending microtasks and short async operations to settle */
25+ function waitForAsync ( ) {
26+ return new Promise ( resolve => setTimeout ( resolve , 10 ) )
27+ }
28+
1929/** Set up the minimum store triples needed for an ordered Multiple field */
2030function setupOrderedMultipleForm ( ) {
2131 store . add ( form , ns . rdf ( 'type' ) , ns . ui ( 'Multiple' ) , doc )
2232 store . add ( form , ns . ui ( 'property' ) , property , doc )
2333 // ui:ordered true as a proper xsd:boolean literal
24- store . add ( form , ns . ui ( 'ordered' ) , literal ( 'true' , null as any , xsdBoolean ) , doc )
34+ store . add ( form , ns . ui ( 'ordered' ) , literal ( 'true' , undefined , xsdBoolean ) , doc )
2535 store . add ( form , ns . ui ( 'part' ) , subform , doc )
2636 // Subform: an empty Group (no parts)
2737 store . add ( subform , ns . rdf ( 'type' ) , ns . ui ( 'Group' ) , doc )
@@ -51,7 +61,7 @@ describe('Multiple ordered field', () => {
5161 renderMultipleField ( )
5262
5363 // After rendering, there should still be exactly ONE list head
54- const heads = store . each ( subject , property , null as any , doc )
64+ const heads = getListHeads ( )
5565 expect ( heads . length ) . toBe ( 1 )
5666 expect ( heads [ 0 ] ) . toBe ( existingCollection )
5767 } )
@@ -62,8 +72,7 @@ describe('Multiple ordered field', () => {
6272 renderMultipleField ( )
6373
6474 // No list head should exist until the user adds an item
65- const heads = store . each ( subject , property , null as any , doc )
66- expect ( heads . length ) . toBe ( 0 )
75+ expect ( getListHeads ( ) . length ) . toBe ( 0 )
6776 } )
6877 } )
6978
@@ -87,7 +96,7 @@ describe('Multiple ordered field', () => {
8796 renderMultipleField ( )
8897
8998 // The list head should remain intact with the original 2 elements
90- const heads = store . each ( subject , property , null as any , doc )
99+ const heads = getListHeads ( )
91100 expect ( heads . length ) . toBe ( 1 )
92101 expect ( ( heads [ 0 ] as Collection ) . elements . length ) . toBe ( 2 )
93102 } )
@@ -107,14 +116,14 @@ describe('Multiple ordered field', () => {
107116 const reloadedCollection = new Collection ( [ namedNode ( 'http://example.com/#item1' ) ] )
108117 store . add ( subject , property , reloadedCollection , doc )
109118
110- expect ( store . each ( subject , property , null as any , doc ) . length ) . toBe ( 2 )
119+ expect ( getListHeads ( ) . length ) . toBe ( 2 )
111120
112121 // After refresh, the field's internal list should be synced to one of the collections.
113122 // The refresh function itself does not remove duplicates — that happens in saveListThenRefresh.
114123 body . refresh ! ( )
115124
116125 // Both heads still exist (removal happens during save)
117- expect ( store . each ( subject , property , null as any , doc ) . length ) . toBe ( 2 )
126+ expect ( getListHeads ( ) . length ) . toBe ( 2 )
118127 } )
119128 } )
120129
@@ -125,18 +134,18 @@ describe('Multiple ordered field', () => {
125134 const { box } = renderMultipleField ( )
126135
127136 // Initially no list head
128- expect ( store . each ( subject , property , null as any , doc ) . length ) . toBe ( 0 )
137+ expect ( getListHeads ( ) . length ) . toBe ( 0 )
129138
130139 // Find and click the add/tail div (second child of box, after body)
131140 const children = box . children
132141 const tail = children [ children . length - 1 ] as HTMLElement
133142 tail . click ( )
134143
135144 // Allow async operations (addItem + saveListThenRefresh) to complete
136- await new Promise ( resolve => setTimeout ( resolve , 10 ) )
145+ await waitForAsync ( )
137146
138147 // After clicking add, exactly one list head should exist in the store
139- const heads = store . each ( subject , property , null as any , doc )
148+ const heads = getListHeads ( )
140149 expect ( heads . length ) . toBe ( 1 )
141150 expect ( heads [ 0 ] . termType ) . toBe ( 'Collection' )
142151 } )
@@ -151,11 +160,11 @@ describe('Multiple ordered field', () => {
151160
152161 // Click add twice
153162 tail . click ( )
154- await new Promise ( resolve => setTimeout ( resolve , 10 ) )
163+ await waitForAsync ( )
155164 tail . click ( )
156- await new Promise ( resolve => setTimeout ( resolve , 10 ) )
165+ await waitForAsync ( )
157166
158- const heads = store . each ( subject , property , null as any , doc )
167+ const heads = getListHeads ( )
159168 expect ( heads . length ) . toBe ( 1 )
160169 const collection = heads [ 0 ] as Collection
161170 expect ( collection . termType ) . toBe ( 'Collection' )
@@ -177,20 +186,21 @@ describe('Multiple ordered field', () => {
177186 const reloadedCollection = new Collection ( [ namedNode ( 'http://example.com/#item1' ) ] )
178187 store . add ( subject , property , reloadedCollection , doc )
179188
180- expect ( store . each ( subject , property , null as any , doc ) . length ) . toBe ( 2 )
189+ expect ( getListHeads ( ) . length ) . toBe ( 2 )
181190
182191 // Click add — this triggers createListIfNecessary (no-op, list already set)
183192 // and saveListThenRefresh (which should deduplicate)
184193 const children = box . children
185194 const tail = children [ children . length - 1 ] as HTMLElement
186195 tail . click ( )
187- await new Promise ( resolve => setTimeout ( resolve , 10 ) )
196+ await waitForAsync ( )
188197
189198 // After the save, there should be exactly ONE list head
190- const heads = store . each ( subject , property , null as any , doc )
199+ const heads = getListHeads ( )
191200 expect ( heads . length ) . toBe ( 1 )
192201 expect ( heads [ 0 ] . termType ) . toBe ( 'Collection' )
193202 } )
194203 } )
195204} )
196205
206+
0 commit comments