@@ -53,7 +53,9 @@ describe('pos-make-findable', () => {
5353 } ;
5454 when ( mockOs . store . get ) . calledWith ( 'https://thing.example#it' ) . mockReturnValue ( { fake : 'thing' } ) ;
5555 const labelIndexAssume = jest . fn ( ) ;
56- when ( labelIndexAssume ) . calledWith ( LabelIndex ) . mockReturnValue ( { fake : 'index' } ) ;
56+ when ( labelIndexAssume )
57+ . calledWith ( LabelIndex )
58+ . mockReturnValue ( { fake : 'index' , contains : ( ) => false } ) ;
5759 when ( mockOs . store . get ) . calledWith ( 'https://pod.example/label-index' ) . mockReturnValue ( {
5860 assume : labelIndexAssume ,
5961 } ) ;
@@ -66,10 +68,47 @@ describe('pos-make-findable', () => {
6668 await page . waitForChanges ( ) ;
6769
6870 // then the thing is added to the index
69- expect ( mockOs . addToLabelIndex ) . toHaveBeenCalledWith ( { fake : 'thing' } , { fake : 'index' } ) ;
71+ expect ( mockOs . addToLabelIndex ) . toHaveBeenCalledWith ( { fake : 'thing' } , expect . objectContaining ( { fake : 'index' } ) ) ;
7072
71- // and the state changes to success
72- expect ( page . rootInstance . success ) . toEqual ( true ) ;
73+ // and the state changes to indexed
74+ expect ( page . rootInstance . isIndexed ) . toEqual ( true ) ;
75+ } ) ;
76+
77+ it ( 'indicates if thing is already indexed' , async ( ) => {
78+ // given a user profile in the current session with a single private label index
79+ session . state . isLoggedIn = true ;
80+ session . state . profile = {
81+ getPrivateLabelIndexes : ( ) => [ 'https://pod.example/label-index' ] ,
82+ } as unknown as WebIdProfile ;
83+
84+ // and a make findable component for a thing
85+ page = await newSpecPage ( {
86+ components : [ PosMakeFindable ] ,
87+ html : `<pos-make-findable uri="https://thing.example#it"/>` ,
88+ } ) ;
89+
90+ // and a PodOS instance that yields Thing and LabelIndex instances for the URIs in question
91+ const mockOs = {
92+ store : {
93+ get : jest . fn ( ) ,
94+ } ,
95+ } ;
96+ when ( mockOs . store . get ) . calledWith ( 'https://thing.example#it' ) . mockReturnValue ( { fake : 'thing' } ) ;
97+ const contains = jest . fn ( ) ;
98+ const labelIndexAssume = jest . fn ( ) ;
99+ when ( labelIndexAssume ) . calledWith ( LabelIndex ) . mockReturnValue ( { fake : 'index' , contains } ) ;
100+ when ( mockOs . store . get ) . calledWith ( 'https://pod.example/label-index' ) . mockReturnValue ( {
101+ assume : labelIndexAssume ,
102+ } ) ;
103+
104+ // and the index already contains the URI
105+ when ( contains ) . calledWith ( 'https://thing.example#it' ) . mockReturnValue ( true ) ;
106+
107+ // and the component received that PodOs instance
108+ page . rootInstance . receivePodOs ( mockOs ) ;
109+
110+ // then the state indicates that the URI is already indexed
111+ expect ( page . rootInstance . isIndexed ) . toEqual ( true ) ;
73112 } ) ;
74113
75114 it ( 'emits error if updating the index fails' , async ( ) => {
@@ -98,7 +137,9 @@ describe('pos-make-findable', () => {
98137 } ;
99138 when ( mockOs . store . get ) . calledWith ( 'https://thing.example#it' ) . mockReturnValue ( { fake : 'thing' } ) ;
100139 const labelIndexAssume = jest . fn ( ) ;
101- when ( labelIndexAssume ) . calledWith ( LabelIndex ) . mockReturnValue ( { fake : 'index' } ) ;
140+ when ( labelIndexAssume )
141+ . calledWith ( LabelIndex )
142+ . mockReturnValue ( { fake : 'index' , contains : ( ) => false } ) ;
102143 when ( mockOs . store . get ) . calledWith ( 'https://pod.example/label-index' ) . mockReturnValue ( {
103144 assume : labelIndexAssume ,
104145 } ) ;
@@ -204,7 +245,9 @@ describe('pos-make-findable', () => {
204245 } ;
205246 when ( mockOs . store . get ) . calledWith ( 'https://thing.example#it' ) . mockReturnValue ( { fake : 'thing' } ) ;
206247 const labelIndexAssume = jest . fn ( ) ;
207- when ( labelIndexAssume ) . calledWith ( LabelIndex ) . mockReturnValue ( { fake : 'index' } ) ;
248+ when ( labelIndexAssume )
249+ . calledWith ( LabelIndex )
250+ . mockReturnValue ( { fake : 'index' , contains : ( ) => false } ) ;
208251 when ( mockOs . store . get ) . calledWith ( 'https://pod.example/label-index' ) . mockReturnValue ( {
209252 assume : labelIndexAssume ,
210253 } ) ;
@@ -229,7 +272,7 @@ describe('pos-make-findable', () => {
229272
230273 // and is working
231274 fireEvent . click ( button ) ;
232- expect ( mockOs . addToLabelIndex ) . toHaveBeenCalledWith ( { fake : 'thing' } , { fake : 'index' } ) ;
275+ expect ( mockOs . addToLabelIndex ) . toHaveBeenCalledWith ( { fake : 'thing' } , expect . objectContaining ( { fake : 'index' } ) ) ;
233276 } ) ;
234277
235278 it ( 'updates thing when URI changes' , async ( ) => {
@@ -258,7 +301,7 @@ describe('pos-make-findable', () => {
258301 expect ( page . rootInstance . thing ) . toEqual ( { uri : 'https://other.example#it' } ) ;
259302 } ) ;
260303
261- it ( 'resets success state when URI changes' , async ( ) => {
304+ it ( 'resets index indication when URI changes' , async ( ) => {
262305 // given a make findable component for a thing
263306 page = await newSpecPage ( {
264307 components : [ PosMakeFindable ] ,
@@ -274,13 +317,13 @@ describe('pos-make-findable', () => {
274317
275318 // and the component received that PodOs instance already
276319 page . rootInstance . receivePodOs ( mockOs ) ;
277- // and the component is in success state
278- page . rootInstance . success = true ;
320+ // and the component is in indexed state
321+ page . rootInstance . isIndexed = true ;
279322
280323 // when the URI attribute changes
281324 page . root . setAttribute ( 'uri' , 'https://other.example#it' ) ;
282- // then the success status resets
283- expect ( page . rootInstance . success ) . toEqual ( false ) ;
325+ // then the indexed status resets
326+ expect ( page . rootInstance . isIndexed ) . toEqual ( false ) ;
284327 } ) ;
285328
286329 describe ( 'multiple indexes to choose from' , ( ) => {
@@ -386,8 +429,8 @@ describe('pos-make-findable', () => {
386429 const list = screen . queryByRole ( 'listbox' ) ;
387430 expect ( list ) . toBeNull ( ) ;
388431
389- // and the state changes to success
390- expect ( page . rootInstance . success ) . toEqual ( true ) ;
432+ // and the state changes to indexed
433+ expect ( page . rootInstance . isIndexed ) . toEqual ( true ) ;
391434 } ) ;
392435
393436 it ( 'closes the options, if clicked elsewhere' , async ( ) => {
0 commit comments