import {TestBed} from '@angular/core/testing'; import {AppInfoOxService} from './app-info-ox.service'; import {PostMessageBridgeFactory} from 'ngx-post-message'; import {CommunicationOxService, MicroLessonInfoOx, UserInfoOx} from 'ox-core'; import {EventEmitter} from '@angular/core'; import {MicroLessonLevelConfiguration} from '../../../../ox-core/src/lib/models/micro-lesson-info-ox'; describe('AppInfoOxService', () => { let appInfoService: AppInfoOxService; const infos = getValidsMicrolessonInfo(); const comunicationOxSpy = jasmine.createSpyObj('CommunicationOx', ['sendMessage']); comunicationOxSpy.receiveMicroLessonInfo = new EventEmitter(); comunicationOxSpy.receiveUserInfo = new EventEmitter(); beforeEach(() => { TestBed.configureTestingModule({ providers: [PostMessageBridgeFactory, {provide: CommunicationOxService, useValue: comunicationOxSpy}] }); appInfoService = TestBed.get(AppInfoOxService); }); it('should be created', () => { expect(appInfoService).toBeTruthy(); }); it('should receive user info just once', () => { const userInfo1 = new UserInfoOx('test alist', false, 'test token'); const userInfo2 = new UserInfoOx('test alis12312t', true, 'test toke111111n'); comunicationOxSpy.receiveUserInfo.emit(userInfo1); comunicationOxSpy.receiveUserInfo.emit(userInfo2); expect(appInfoService.userInfo).toEqual(userInfo1); }); it('should receive microlesson info just once', () => { comunicationOxSpy.receiveMicroLessonInfo.emit(infos[0]); comunicationOxSpy.receiveMicroLessonInfo.emit(infos[1]); expect(appInfoService.microLessonInfo).toEqual(infos[0]); }); it('getFirstMicroLessonInfo returns a valid value if there is just one microlesson info', () => { comunicationOxSpy.receiveMicroLessonInfo.emit(infos[0]); expect(appInfoService.microLessonInfo).toEqual(infos[0]); }); it('getFirstMicroLessonInfo returns a valid value if there is an array microlesson info', () => { comunicationOxSpy.receiveMicroLessonInfo.emit(infos[0]); expect(appInfoService.microLessonInfo).toEqual(infos[0]); }); // it('getMicroLessonInfoById return the microlesson with the specified id', () => { // comunicationOxSpy.receiveMicroLessonInfo.emit(infos); // expect(appInfoService.getMicroLessonInfoById(2)).toEqual(infos[1]); // }); it('getInitialLevel returns the correct level', () => { comunicationOxSpy.receiveMicroLessonInfo.emit(infos[0]); expect(appInfoService.getInitialLevel()).toEqual(infos[0].initialLevel); }); function getValidsMicrolessonInfo() { return [new MicroLessonInfoOx([new MicroLessonLevelConfiguration()], 1, 2, '', [], undefined), new MicroLessonInfoOx([new MicroLessonLevelConfiguration()], 3, 5, '', [], undefined)]; } });