11import { newSpecPage } from '@stencil/core/testing' ;
22import { PosSwitch } from './pos-switch' ;
33import { when } from 'jest-when' ;
4- import { RdfType , Thing } from '@pod-os/core' ;
4+ import { RdfType , Relation , Thing } from '@pod-os/core' ;
55import { Subject } from 'rxjs' ;
66
77describe ( 'pos-switch' , ( ) => {
@@ -203,16 +203,15 @@ describe('pos-switch', () => {
203203 </pos-case>
204204 </pos-switch>` ,
205205 } ) ;
206+ const observedRelations$ = new Subject < Relation [ ] > ( ) ;
206207 const thing = {
207208 uri : 'https://pod.example/resource' ,
208- relations : jest . fn ( ) ,
209+ observeRelations : ( ) => observedRelations$ ,
209210 } ;
210- when ( thing . relations )
211- . calledWith ( 'https://schema.org/video' )
212- . mockReturnValue ( [ { predicate : 'https://schema.org/video' , uris : [ 'https://video.test/video-1' ] } ] ) ;
213- when ( thing . relations ) . calledWith ( 'https://schema.org/description' ) . mockReturnValue ( [ ] ) ;
214-
215- await page . rootInstance . receiveResource ( thing ) ;
211+ page . rootInstance . receiveResource ( thing ) ;
212+ observedRelations$ . next ( [
213+ { predicate : 'https://schema.org/video' , label : 'video' , uris : [ 'https://video.test/video-1' ] } ,
214+ ] ) ;
216215 await page . waitForChanges ( ) ;
217216 expect ( page . root ?. innerHTML ) . toEqualHtml ( `
218217 <div>Resource has video</div>
@@ -236,16 +235,15 @@ describe('pos-switch', () => {
236235 </pos-case>
237236 </pos-switch>` ,
238237 } ) ;
238+ const observedReverseRelations$ = new Subject < Relation [ ] > ( ) ;
239239 const thing = {
240240 uri : 'https://pod.example/resource' ,
241- reverseRelations : jest . fn ( ) ,
241+ observeReverseRelations : ( ) => observedReverseRelations$ ,
242242 } ;
243- when ( thing . reverseRelations )
244- . calledWith ( 'https://schema.org/video' )
245- . mockReturnValue ( [ { predicate : 'https://schema.org/video' , uris : [ 'https://video.test/video-1' ] } ] ) ;
246- when ( thing . reverseRelations ) . calledWith ( 'https://schema.org/subjectOf' ) . mockReturnValue ( [ ] ) ;
247-
248- await page . rootInstance . receiveResource ( thing ) ;
243+ page . rootInstance . receiveResource ( thing ) ;
244+ observedReverseRelations$ . next ( [
245+ { predicate : 'https://schema.org/video' , label : 'video' , uris : [ 'https://video.test/video-1' ] } ,
246+ ] ) ;
249247 await page . waitForChanges ( ) ;
250248 expect ( page . root ?. innerHTML ) . toEqualHtml ( `
251249 <div>Resource is video</div>
0 commit comments