@@ -107,6 +107,11 @@ describe('askName', () => {
107107} )
108108
109109describe ( 'attachmentList' , ( ) => {
110+ afterEach ( ( ) => {
111+ clearStore ( )
112+ jest . restoreAllMocks ( )
113+ } )
114+
110115 it ( 'exists' , ( ) => {
111116 expect ( attachmentList ) . toBeInstanceOf ( Function )
112117 } )
@@ -116,6 +121,70 @@ describe('attachmentList', () => {
116121 const options = { }
117122 expect ( attachmentList ( dom , subject , div , options ) ) . toBeTruthy ( )
118123 } )
124+
125+ it ( 'refreshes rows after pending profile fetches by default' , ( ) => {
126+ const subject = sym ( 'https://subject.example/profile/card#me' )
127+ const predicate = ns . foaf ( 'knows' )
128+ const target = sym ( 'https://friend.example/profile/card#me' )
129+ const div = element
130+ const fetcher = store . fetcher as any
131+
132+ store . add ( subject , predicate , target , subject . doc ( ) )
133+ fetcher . requested = {
134+ ...fetcher . requested ,
135+ [ target . doc ( ) . uri ] : 'requested'
136+ }
137+
138+ const nowOrWhenFetched = jest
139+ . spyOn ( fetcher , 'nowOrWhenFetched' )
140+ . mockImplementation ( ( ) => undefined as any )
141+
142+ attachmentList ( dom , subject , div , {
143+ predicate,
144+ renderSupportingInfo : ( ) => null
145+ } )
146+
147+ expect ( nowOrWhenFetched ) . toHaveBeenCalledWith (
148+ target . doc ( ) ,
149+ undefined ,
150+ expect . any ( Function )
151+ )
152+ } )
153+
154+ it ( 'adds one extra document-load refresh hook only when enabled' , ( ) => {
155+ const subject = sym ( 'https://subject.example/profile/card#me' )
156+ const predicate = ns . foaf ( 'knows' )
157+ const target = sym ( 'https://friend.example/profile/card#me' )
158+ const div = element
159+ const fetcher = store . fetcher as any
160+
161+ store . add ( subject , predicate , target , subject . doc ( ) )
162+ fetcher . requested = {
163+ ...fetcher . requested ,
164+ [ target . doc ( ) . uri ] : 'requested'
165+ }
166+
167+ const nowOrWhenFetched = jest
168+ . spyOn ( fetcher , 'nowOrWhenFetched' )
169+ . mockImplementation ( ( ) => undefined as any )
170+
171+ attachmentList ( dom , subject , div , {
172+ predicate,
173+ refreshOnDocumentLoad : false ,
174+ renderSupportingInfo : ( ) => null
175+ } )
176+ const disabledCallCount = nowOrWhenFetched . mock . calls . length
177+
178+ nowOrWhenFetched . mockClear ( )
179+ div . innerHTML = ''
180+
181+ attachmentList ( dom , subject , div , {
182+ predicate,
183+ renderSupportingInfo : ( ) => null
184+ } )
185+
186+ expect ( nowOrWhenFetched . mock . calls . length ) . toBe ( disabledCallCount + 1 )
187+ } )
119188} )
120189
121190describe ( 'button' , ( ) => {
0 commit comments