@@ -68,6 +68,52 @@ describe('pos-make-findable', () => {
6868 expect ( mockOs . addToLabelIndex ) . toHaveBeenCalledWith ( { fake : 'thing' } , { fake : 'index' } ) ;
6969 } ) ;
7070
71+ fit ( 'emits error if updating the index fails' , async ( ) => {
72+ // given a user profile in the current session with a single private label index
73+ session . state . isLoggedIn = true ;
74+ session . state . profile = {
75+ getPrivateLabelIndexes : ( ) => [ 'https://pod.example/label-index' ] ,
76+ } as unknown as WebIdProfile ;
77+
78+ // and a make findable component for a thing
79+ page = await newSpecPage ( {
80+ components : [ PosMakeFindable ] ,
81+ html : `<pos-make-findable uri="https://thing.example#it"/>` ,
82+ } ) ;
83+
84+ // and the page listens for error
85+ const errorListener = jest . fn ( ) ;
86+ page . root . addEventListener ( 'pod-os:error' , errorListener ) ;
87+
88+ // and a PodOS instance that yields Thing and LabelIndex instances for the URIs in question
89+ const mockOs = {
90+ store : {
91+ get : jest . fn ( ) ,
92+ } ,
93+ addToLabelIndex : jest . fn ( ) ,
94+ } ;
95+ when ( mockOs . store . get ) . calledWith ( 'https://thing.example#it' ) . mockReturnValue ( { fake : 'thing' } ) ;
96+ const labelIndexAssume = jest . fn ( ) ;
97+ when ( labelIndexAssume ) . calledWith ( LabelIndex ) . mockReturnValue ( { fake : 'index' } ) ;
98+ when ( mockOs . store . get ) . calledWith ( 'https://pod.example/label-index' ) . mockReturnValue ( {
99+ assume : labelIndexAssume ,
100+ } ) ;
101+
102+ // but leads to an error when adding a thing to index
103+ mockOs . addToLabelIndex . mockRejectedValue ( new Error ( 'simulated error' ) ) ;
104+
105+ // and the component received that PodOs instance
106+ page . rootInstance . receivePodOs ( mockOs ) ;
107+
108+ // when the button is clicked
109+ const button = screen . getByRole ( 'button' ) ;
110+ fireEvent . click ( button ) ;
111+ await page . waitForChanges ( ) ;
112+
113+ // then an error event is emitted
114+ expect ( errorListener ) . toHaveBeenCalledWith ( expect . objectContaining ( { detail : new Error ( 'simulated error' ) } ) ) ;
115+ } ) ;
116+
71117 it ( 'does not show up, when not logged in' , async ( ) => {
72118 // given no user session
73119 session . state . isLoggedIn = false ;
0 commit comments