diff --git a/projects/player/modules/verona/services/verona-post.service.spec.ts b/projects/player/modules/verona/services/verona-post.service.spec.ts index c9c14d8e4fbe2bbf76afad6584182362c72ecbe7..849b23cc3f6b7a7a3f4911009c7983ea8c533a5c 100644 --- a/projects/player/modules/verona/services/verona-post.service.spec.ts +++ b/projects/player/modules/verona/services/verona-post.service.spec.ts @@ -20,7 +20,7 @@ describe('VeronaPostService', () => { expect(service).toBeTruthy(); }); - it('should post a VopStateChangedNotification', () => { + it('should post a VopStateChangedNotification', done => { const expectedStateChangedNotification: VopStateChangedNotification = { type: 'vopStateChangedNotification', sessionId: 'test', @@ -28,14 +28,17 @@ describe('VeronaPostService', () => { }; const eventSubscription = fromEvent(window.parent, 'message') .subscribe(event => { - expect((event as MessageEvent).data as VopStateChangedNotification) - .toEqual(expectedStateChangedNotification); + const data = ((event as MessageEvent).data as VopStateChangedNotification); + expect(data.type).toEqual(expectedStateChangedNotification.type); + expect(data.sessionId).toEqual(expectedStateChangedNotification.sessionId); + expect(Object.prototype.hasOwnProperty.call(data, 'timeStamp')).toBeTruthy(); eventSubscription.unsubscribe(); + done(); }); service.sendVopStateChangedNotification({}); }); - it('should post a VopReadyNotification', () => { + it('should post a VopReadyNotification', done => { const expectedReadyNotification: VopReadyNotification = { type: 'vopReadyNotification', apiVersion: 'test' @@ -45,11 +48,12 @@ describe('VeronaPostService', () => { expect((event as MessageEvent).data as VopReadyNotification) .toEqual(expectedReadyNotification); eventSubscription.unsubscribe(); + done(); } ); service.sendVopReadyNotification({ apiVersion: 'test' }); }); - it('should post a VopUnitNavigationRequestedNotification', () => { + it('should post a VopUnitNavigationRequestedNotification', done => { const expectedUnitNavigationRequestedNotification: VopUnitNavigationRequestedNotification = { type: 'vopUnitNavigationRequestedNotification', sessionId: 'test', @@ -60,12 +64,13 @@ describe('VeronaPostService', () => { expect((event as MessageEvent).data as VopUnitNavigationRequestedNotification) .toEqual(expectedUnitNavigationRequestedNotification); eventSubscription.unsubscribe(); + done(); } ); service.sendVopUnitNavigationRequestedNotification('next'); }); - it('should post a VopUnitNavigationRequestedNotification', () => { + it('should post a VopUnitNavigationRequestedNotification', done => { const expectedWindowFocusChangedNotification: VopWindowFocusChangedNotification = { type: 'vopWindowFocusChangedNotification', timeStamp: Date.now(), @@ -73,9 +78,12 @@ describe('VeronaPostService', () => { }; const eventSubscription = fromEvent(window.parent, 'message') .subscribe(event => { - expect((event as MessageEvent).data as VopWindowFocusChangedNotification) - .toEqual(expectedWindowFocusChangedNotification); + const data = ((event as MessageEvent).data as VopWindowFocusChangedNotification); + expect(data.type).toEqual(expectedWindowFocusChangedNotification.type); + expect(data.hasFocus).toEqual(expectedWindowFocusChangedNotification.hasFocus); + expect(Object.prototype.hasOwnProperty.call(data, 'timeStamp')).toBeTruthy(); eventSubscription.unsubscribe(); + done(); } ); service.sendVopWindowFocusChangedNotification(true); }); diff --git a/projects/player/modules/verona/services/verona-subscription.service.spec.ts b/projects/player/modules/verona/services/verona-subscription.service.spec.ts index b461abea16f264f4fd0683074a5af1dc7e5a4148..94e5a972659499f18b4f279d24c833ac7a704141 100644 --- a/projects/player/modules/verona/services/verona-subscription.service.spec.ts +++ b/projects/player/modules/verona/services/verona-subscription.service.spec.ts @@ -16,7 +16,7 @@ describe('VeronaSubscriptionService', () => { expect(service).toBeTruthy(); }); - it('should get a vopStartCommand', () => { + it('should get a vopStartCommand', done => { const startMessage: VopStartCommand = { type: 'vopStartCommand', sessionId: 'test', @@ -27,12 +27,14 @@ describe('VeronaSubscriptionService', () => { }; service.vopStartCommand .subscribe( - message => - expect(message).toEqual(startMessage)); + message => { + expect(message).toEqual(startMessage); + done(); + }); window.postMessage(startMessage, '*'); }); - it('should get a VopGetStateRequest', () => { + it('should get a VopGetStateRequest', done => { const StateRequestMessage: VopGetStateRequest = { type: 'vopGetStateRequest', sessionId: 'test', @@ -40,25 +42,29 @@ describe('VeronaSubscriptionService', () => { }; service.vopGetStateRequest .subscribe( - message => - expect(message).toEqual(StateRequestMessage)); + message => { + expect(message).toEqual(StateRequestMessage); + done(); + }); window.postMessage(StateRequestMessage, '*'); }); - it('should get a VopContinueCommand', () => { + it('should get a VopContinueCommand', done => { const continueCommandMessage: VopContinueCommand = { type: 'vopContinueCommand', sessionId: 'test' }; service.vopContinueCommand .subscribe( - message => - expect(message).toEqual(continueCommandMessage)); + message => { + expect(message).toEqual(continueCommandMessage); + done(); + }); window.postMessage(continueCommandMessage, '*'); }); - it('should get a VopNavigationDeniedNotification', () => { + it('should get a VopNavigationDeniedNotification', done => { const navigationDeniedNotificationMessage: VopNavigationDeniedNotification = { type: 'vopNavigationDeniedNotification', sessionId: 'test', @@ -66,12 +72,14 @@ describe('VeronaSubscriptionService', () => { }; service.vopNavigationDeniedNotification .subscribe( - message => - expect(message).toEqual(navigationDeniedNotificationMessage)); + message => { + expect(message).toEqual(navigationDeniedNotificationMessage); + done(); + }); window.postMessage(navigationDeniedNotificationMessage, '*'); }); - it('should get a VopPageNavigationCommand', () => { + it('should get a VopPageNavigationCommand', done => { const pageNavigationCommandMessage: VopPageNavigationCommand = { type: 'vopPageNavigationCommand', sessionId: 'test', @@ -79,20 +87,24 @@ describe('VeronaSubscriptionService', () => { }; service.vopPageNavigationCommand .subscribe( - message => - expect(message).toEqual(pageNavigationCommandMessage)); + message => { + expect(message).toEqual(pageNavigationCommandMessage); + done(); + }); window.postMessage(pageNavigationCommandMessage, '*'); }); - it('should get a VopPageNavigationCommand', () => { + it('should get a VopPageNavigationCommand', done => { const startCommandMessage: VopStopCommand = { type: 'vopStopCommand', sessionId: 'test' }; service.vopStopCommand .subscribe( - message => - expect(message).toEqual(startCommandMessage)); + message => { + expect(message).toEqual(startCommandMessage); + done(); + }); window.postMessage(startCommandMessage, '*'); }); }); diff --git a/projects/player/src/app/services/media-player.service.spec.ts b/projects/player/src/app/services/media-player.service.spec.ts index 9353e33cdeb0d275c266e6dd8c2866a712e20060..57c27cabb92773e68384568017047aec231c56c9 100644 --- a/projects/player/src/app/services/media-player.service.spec.ts +++ b/projects/player/src/app/services/media-player.service.spec.ts @@ -13,30 +13,39 @@ describe('MediaPlayerService', () => { expect(service).toBeTruthy(); }); - it('mediaStatus of audio_1 should be changed', () => { + it('mediaStatus of audio_1 should be changed', done => { const mediaId = 'audio_1'; service.registerMediaElement(mediaId, false); - service.setValidStatusChanged(mediaId); service.mediaStatusChanged - .subscribe( id => expect(id).toEqual(mediaId)); + .subscribe( id => { + expect(id).toEqual(mediaId); + done(); + }); + service.setValidStatusChanged(mediaId); }); - it('mediaStatus of audio_1 should be changed', () => { + it('mediaStatus of audio_1 should be changed', done => { const mediaId = 'audio_1'; service.registerMediaElement(mediaId, false); service.registerMediaElement('audio_2', false); - service.setValidStatusChanged(mediaId); service.mediaStatusChanged - .subscribe( id => expect(id).toEqual(mediaId)); + .subscribe( id => { + expect(id).toEqual(mediaId); + done(); + }); + service.setValidStatusChanged(mediaId); }); - it('mediaStatus of audio_2 should not be changed', () => { + it('mediaStatus of audio_2 should not be changed', done => { const mediaId = 'audio_1'; service.registerMediaElement(mediaId, false); service.registerMediaElement('audio_2', false); - service.setValidStatusChanged('audio_2'); service.mediaStatusChanged - .subscribe( id => expect(id).not.toEqual(mediaId)); + .subscribe( id => { + expect(id).not.toEqual(mediaId); + done(); + }); + service.setValidStatusChanged('audio_2'); }); it('mediaStatus should be complete', () => { @@ -65,17 +74,23 @@ describe('MediaPlayerService', () => { expect(service.mediaStatus).toEqual('complete'); }); - it('actualPlayingMediaId should be audio_1', () => { + it('actualPlayingMediaId should be audio_1', done => { const mediaId = 'audio_1'; service.actualPlayingId - .subscribe( id => expect(id).toEqual(mediaId)); + .subscribe( id => { + expect(id).toEqual(mediaId); + done(); + }); service.setActualPlayingId(mediaId); }); - it('pageIndex should not be audio_1', () => { + it('pageIndex should not be audio_1', done => { const mediaId = 'audio_1'; service.actualPlayingId - .subscribe( id => expect(id).not.toEqual(mediaId)); + .subscribe( id => { + expect(id).not.toEqual(mediaId); + done(); + }); service.setActualPlayingId('audio_2'); }); }); diff --git a/projects/player/src/app/services/navigation.service.spec.ts b/projects/player/src/app/services/navigation.service.spec.ts index 69d3431403436668c875a1025a61be8eba39dcf5..cba9d2f721f4e19efe56f8c4b15dac89ed818910 100644 --- a/projects/player/src/app/services/navigation.service.spec.ts +++ b/projects/player/src/app/services/navigation.service.spec.ts @@ -12,15 +12,21 @@ describe('NavigationService', () => { expect(service).toBeTruthy(); }); - it('pageIndex should be 2', () => { + it('pageIndex should be 2', done => { service.pageIndex - .subscribe( pageIndex => expect(pageIndex).toEqual(2)); + .subscribe( pageIndex => { + expect(pageIndex).toEqual(2); + done(); + }); service.setPage(2); }); - it('pageIndex should not be 2', () => { + it('pageIndex should not be 2', done => { service.pageIndex - .subscribe( pageIndex => expect(pageIndex).not.toEqual(2)); + .subscribe( pageIndex => { + expect(pageIndex).not.toEqual(2); + done(); + }); service.setPage(1); }); }); diff --git a/projects/player/src/app/services/unit-state.service.spec.ts b/projects/player/src/app/services/unit-state.service.spec.ts index 8db66628d6bd30d2d6d5306d446d98c941de38b9..92c47c8b43fc12d0ab39d4629b8ea2c7ec4bda47 100644 --- a/projects/player/src/app/services/unit-state.service.spec.ts +++ b/projects/player/src/app/services/unit-state.service.spec.ts @@ -48,19 +48,23 @@ describe('UnitStateService', () => { expect(service.elementCodes).toEqual([ { id: 'element', status: 'NOT_REACHED', value: 'TEST' } ]); }); - it('elementCode of an element should change', () => { + it('elementCode of an element should change', done => { service.elementCodes = [{ id: 'element_1', status: 'NOT_REACHED', value: 'TEST1' }]; service.elementCodeChanged - .subscribe( code => expect(code.status).toEqual('DISPLAYED')); + .subscribe( code => { + expect(code.status).toEqual('DISPLAYED'); + done(); + }); service.changeElementCodeStatus({ id: 'element_1', status: 'DISPLAYED' }); }); - it('elementCode of an element should change', () => { + it('elementCode of an element should change', done => { service.elementCodes = [{ id: 'element_1', status: 'NOT_REACHED', value: 'TEST1' }]; service.elementCodeChanged .subscribe( code => { expect(code.status).toEqual('VALUE_CHANGED'); expect(code.value).toEqual('NEU'); + done(); }) ; service.changeElementCodeValue({ id: 'element_1', value: 'NEU' }); }); @@ -113,21 +117,27 @@ describe('UnitStateService', () => { expect(service.presentedPagesProgress).toEqual('complete'); }); - it('presented page with index 1 should be added', () => { + it('presented page with index 1 should be added', done => { service.elementCodes = []; const element = document.createElement('div'); service.registerElement('element_1', 'TEST1', element, 1); service.presentedPageAdded - .subscribe( index => expect(index).toEqual(1)); + .subscribe( index => { + expect(index).toEqual(1); + done(); + }); service.changeElementCodeStatus({ id: 'element_1', status: 'DISPLAYED' }); }); - it('presented page with index 1 should be added', () => { + it('presented page with index 1 should be added', done => { service.elementCodes = []; const element = document.createElement('div'); service.registerElement('element_1', 'TEST1', element, 1); service.presentedPageAdded - .subscribe( index => expect(index).toEqual(1)); + .subscribe( index => { + expect(index).toEqual(1); + done(); + }); service.changeElementCodeValue({ id: 'element_1', value: 'NEU' }); });