import {async, discardPeriodicTasks, fakeAsync, flush, TestBed, tick} from '@angular/core/testing'; import {InWumboxService} from './in-wumbox.service'; import {PostMessageBridgeFactory} from 'ngx-post-message'; import {HttpClientTestingModule} from '@angular/common/http/testing'; import {CommunicationOxService} from 'ox-core'; import {EventEmitter} from '@angular/core'; import {ScreenOxService} from './screen-ox.service'; import {GameActionsService} from './game-actions.service'; import 'zone.js/dist/zone-patch-rxjs-fake-async'; import {timer} from 'rxjs'; describe('InWumboxService', () => { let inWumboxService: InWumboxService; // const screenServiceSpy = jasmine.createSpyObj('MyScreenOxService', ['showNotInWumboxScreen']); const communicationServiceSpy = jasmine.createSpyObj('CommunicationOxService', ['sendMessage']); communicationServiceSpy.receiveMicroLessonInfo = new EventEmitter(); communicationServiceSpy.receiveUserInfo = new EventEmitter(); communicationServiceSpy.receiveSettings = new EventEmitter(); beforeEach(() => { TestBed.configureTestingModule({ providers: [PostMessageBridgeFactory, InWumboxService, {provide: CommunicationOxService, useValue: communicationServiceSpy}, ScreenOxService, // {provide: ScreenOxService, useValue: screenServiceSpy}, GameActionsService], imports: [HttpClientTestingModule] }); inWumboxService = TestBed.get(InWumboxService); }); it('should be created', () => { expect(inWumboxService).toBeTruthy(); }); // this.timerSubscription = timer(5000, 1000).pipe(takeUntil(this.inWumbox)).subscribe((e) => { // this.screenService.showNotInWumboxScreen(); // }); function toBeInWumboxEvents() { communicationServiceSpy.receiveSettings.emit(); communicationServiceSpy.receiveMicroLessonInfo.emit(); communicationServiceSpy.receiveUserInfo.emit(); } it('In wumbox service send true to in wumbox after recived settings, microlesson info and user info', () => { spyOn(inWumboxService.inWumbox, 'emit'); toBeInWumboxEvents(); expect(inWumboxService.inWumbox.emit).toHaveBeenCalledWith(true); toBeInWumboxEvents(); }); it('Just the first time in wumbox service listen the events', () => { spyOn(inWumboxService.inWumbox, 'emit'); toBeInWumboxEvents(); expect(inWumboxService.inWumbox.emit).toHaveBeenCalledTimes(1); toBeInWumboxEvents(); expect(inWumboxService.inWumbox.emit).toHaveBeenCalledTimes(1); }); // TODO correct this test // it('If one of the events does not arrive showNowInWumboxScreen is fired', fakeAsync((done) => { // const mySpy2 = spyOn(inWumboxService, 'showNotInWumboxScreen'); // expect(mySpy2).toHaveBeenCalledTimes(0); // tick(6000); // after 5 seconds must call the method // expect(mySpy2).toHaveBeenCalledTimes(1); // // })); });