|
1 | 1 | import { Component, DebugElement } from '@angular/core';
|
2 |
| -import { ComponentFixture, TestBed } from '@angular/core/testing'; |
| 2 | +import {ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing'; |
3 | 3 | import { By } from '@angular/platform-browser';
|
4 | 4 | import { Cloudinary } from './cloudinary.service';
|
5 | 5 | import CloudinaryConfiguration from './cloudinary-configuration.class';
|
@@ -401,3 +401,54 @@ describe('CloudinaryVideo', () => {
|
401 | 401 | });
|
402 | 402 | });
|
403 | 403 |
|
| 404 | + |
| 405 | +describe('Video event handler', () => { |
| 406 | + let localCloudinary: Cloudinary = new Cloudinary(require('cloudinary-core'), |
| 407 | + { cloud_name: '@@fake_angular2_sdk@@' } as CloudinaryConfiguration); |
| 408 | + let component: CloudinaryVideo; |
| 409 | + let fixture: ComponentFixture<CloudinaryVideo>; |
| 410 | + |
| 411 | + beforeEach(() => { |
| 412 | + TestBed.configureTestingModule({ |
| 413 | + declarations: [CloudinaryVideo], |
| 414 | + providers: [{ provide: Cloudinary , useValue: localCloudinary}] |
| 415 | + }); |
| 416 | + fixture = TestBed.createComponent(CloudinaryVideo); |
| 417 | + component = fixture.componentInstance; |
| 418 | + component.publicId = 'demo'; |
| 419 | + }); |
| 420 | + |
| 421 | + it('should emit play event', fakeAsync(() => { |
| 422 | + spyOn(component, 'emitPlayEvent'); |
| 423 | + const videoElement: HTMLVideoElement = fixture.nativeElement; |
| 424 | + const vid = videoElement.querySelector('video'); |
| 425 | + |
| 426 | + vid.dispatchEvent(new Event('play')); |
| 427 | + fixture.detectChanges(); |
| 428 | + |
| 429 | + expect(component.emitPlayEvent).toHaveBeenCalled(); |
| 430 | + })); |
| 431 | + |
| 432 | + it('should emit playing event', fakeAsync(() => { |
| 433 | + spyOn(component, 'emitPlayingEvent'); |
| 434 | + const videoElement: HTMLVideoElement = fixture.nativeElement; |
| 435 | + const vid = videoElement.querySelector('video'); |
| 436 | + |
| 437 | + vid.dispatchEvent(new Event('playing')); |
| 438 | + fixture.detectChanges(); |
| 439 | + |
| 440 | + expect(component.emitPlayingEvent).toHaveBeenCalled(); |
| 441 | + })); |
| 442 | + |
| 443 | + it('should emit loadstart event', fakeAsync(() => { |
| 444 | + spyOn(component, 'emitLoadstartEvent'); |
| 445 | + const videoElement: HTMLVideoElement = fixture.nativeElement; |
| 446 | + const vid = videoElement.querySelector('video'); |
| 447 | + |
| 448 | + vid.dispatchEvent(new Event('loadstart')); |
| 449 | + fixture.detectChanges(); |
| 450 | + |
| 451 | + expect(component.emitLoadstartEvent).toHaveBeenCalled(); |
| 452 | + })); |
| 453 | +}); |
| 454 | + |
0 commit comments