@@ -225,5 +225,58 @@ describe('CloudinaryVideo', () => {
225225 }
226226 } ) ;
227227 } ) ;
228+
229+ describe ( 'Bound public-id' , ( ) => {
230+ @Component ( {
231+ template : `
232+ <cl-video cloud-name="my_other_cloud" [public-id]="publicId" secure="true" class="my-videos">
233+ <cl-transformation overlay="text:arial_60:watchme" gravity="north" y="20"></cl-transformation>
234+ </cl-video>
235+ `
236+ } )
237+ class TestComponent {
238+ publicId : string = 'watchme' ;
239+ }
240+
241+ let fixture : ComponentFixture < TestComponent > ;
242+ let des : DebugElement ; // the elements w/ the directive
243+
244+ beforeEach ( ( ) => {
245+ fixture = TestBed . configureTestingModule ( {
246+ declarations : [ CloudinaryTransformationDirective , CloudinaryVideo , TestComponent ] ,
247+ providers : [ { provide : Cloudinary , useValue : localCloudinary } ]
248+ } ) . createComponent ( TestComponent ) ;
249+
250+ fixture . detectChanges ( ) ; // initial binding
251+
252+ // Our element under test, which is attached to CloudinaryVideo
253+ des = fixture . debugElement . query ( By . directive ( CloudinaryVideo ) ) ;
254+ } ) ;
255+
256+ it ( 'creates a video element with a bound public-id' , ( ) => {
257+ const video = des . children [ 0 ] . nativeElement as HTMLVideoElement ;
258+ // Created <video> element should have 3 child <source> elements for mp4, webm, ogg
259+ expect ( video . childElementCount ) . toBe ( 3 ) ;
260+
261+ const testMarkup = ( id : string ) => {
262+ for ( let i = 0 ; i < 3 ; i ++ ) {
263+ expect ( video . children [ i ] . attributes . getNamedItem ( 'src' ) ) . toBeDefined ( ) ;
264+ expect ( video . children [ i ] . attributes . getNamedItem ( 'src' ) . value ) . toEqual (
265+ jasmine . stringMatching
266+ ( new RegExp ( `https:\/\/res.cloudinary.com\/my_other_cloud\/video\/upload\/g_north,l_text:arial_60:watchme,y_20\/${ id } ` ) ) ) ;
267+ }
268+ } ;
269+
270+ // Check initial binding
271+ testMarkup ( 'watchme' ) ;
272+
273+ // Update data-bound publicId
274+ fixture . componentInstance . publicId = 'updatedId' ;
275+ fixture . detectChanges ( ) ;
276+
277+ // Verify that the video elememnt has updated
278+ testMarkup ( 'updatedId' ) ;
279+ } ) ;
280+ } ) ;
228281} ) ;
229282
0 commit comments