beforeEach(() => { const mockedAssetService = mock(AssetService); when(mockedAssetService.resolveFromRequire(anyNumber())).thenReturn({ height: 100, scale: 1, uri: 'lol', width: 100 }); const assetService = instance(mockedAssetService); const mockedColorService = mock(ColorService); when(mockedColorService.toNativeColor(anyString())).thenReturn(666); const colorService = instance(mockedColorService); uut = new OptionsProcessor(store, new UniqueIdProvider(), colorService, assetService); });
describe('AcLabelDescComponent', () => { let component: AcLabelDescComponent; let fixture: ComponentFixture<AcLabelDescComponent>; const cesiumService = mock(CesiumService); const labelCollection = mock(Cesium.LabelCollection); when(cesiumService.getScene()).thenReturn({primitives: instance(labelCollection)}); beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [AcLabelDescComponent], providers: [LabelDrawerService, providerFromMock(CesiumService, cesiumService), mockProvider(LayerService), mockProvider(CesiumProperties), mockProvider(ComputationCache)] }) .compileComponents(); })); beforeEach(() => { fixture = TestBed.createComponent(AcLabelDescComponent); component = fixture.componentInstance; fixture.detectChanges(); }); it('should create', () => { expect(component).toBeTruthy(); }); });
it("should call onSuccess after segment loading succeeded", () => { const loader = mock<LoaderInterface>(LoaderInterfaceEmptyImpl); const onSuccess = sinon.spy(); let segmentLoadedListener: Function = () => { throw new Error("SegmentLoaded listener not set"); }; when(loader.on(Events.SegmentLoaded, anyFunction())).thenCall((eventName_unused, listener) => { segmentLoadedListener = listener; }); const segment = new Segment( "id", testPlaylist.baseUrl + "segment-1045.ts", testPlaylist.url, testPlaylist.url, undefined, "1045", undefined, 0, new ArrayBuffer(0)); const manager = new SegmentManager(instance(loader)); manager.processPlaylist(testPlaylist.url, testPlaylist.content, testPlaylist.url); manager.loadSegment(segment.url, undefined, onSuccess, () => {}); segmentLoadedListener(segment); onSuccess.calledWith(segment.data); });
describe('AcAcrComponent', () => { let component: AcArcComponent; let fixture: ComponentFixture<AcArcComponent>; const cesiumService = mock(CesiumService); const arcCollection = mock(Cesium.PrimitiveCollection); when(cesiumService.getScene()).thenReturn({primitives: instance(arcCollection)}); beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [AcArcComponent], providers: [ArcDrawerService, providerFromMock(CesiumService, cesiumService)] }) .compileComponents(); fixture = TestBed.createComponent(AcArcComponent); component = fixture.componentInstance; })); it('should create', () => { expect(component).toBeTruthy(); }); });
test('all checks OK gives OK', () => { const group = new HealthCheckGroup('test1'); const mockHealthCheck = mock<HealthCheck>(HealthCheck); when(mockHealthCheck.getCheckName()).thenReturn('check1'); when(mockHealthCheck.getLastResult()).thenReturn(new HealthCheckResult(HealthCheckStatus.OK, 'OK')); const mockHealthCheck2 = mock<HealthCheck>(HealthCheck); when(mockHealthCheck2.getCheckName()).thenReturn('check2'); when(mockHealthCheck2.getLastResult()).thenReturn(new HealthCheckResult(HealthCheckStatus.OK, 'OK')); group.addCheck(instance(mockHealthCheck)); group.addCheck(instance(mockHealthCheck2)); group.start(); const result = group.getLastResult(); result.status.must.equal(HealthCheckStatus.OK); group.stop(); });
test('adding simple test adds it directly', () => { const group = new HealthCheckGroup('test1'); const mockHealthCheck = mock<HealthCheck>(HealthCheck); when(mockHealthCheck.getCheckName()).thenReturn('simpleId'); group.addCheck(instance(mockHealthCheck)); group.healthChecks.size.must.equal(1); Array.from(group.healthChecks.keys()).must.eql(['simpleId']); });
test('Readonly flag is passed (true)', async () => { const check = new MySQLHealthCheck('testCheck', true); const mockedMysqlClient = mock(MySQLClient); when(mockedMysqlClient.ping(anything())).thenReturn(Promise.resolve(undefined)); check.mysqlClient = instance(mockedMysqlClient); await check.doCheck(); verify(mockedMysqlClient.ping(true)).once(); });
test('adding 2 2nd level tests adds it to the subgroup', () => { const group = new HealthCheckGroup('test1'); const mockHealthCheck = mock<HealthCheck>(HealthCheck); when(mockHealthCheck.getCheckName()).thenReturn('simpleId.subtest'); group.addCheck(instance(mockHealthCheck)); const mockHealthCheck2 = mock<HealthCheck>(HealthCheck); when(mockHealthCheck2.getCheckName()).thenReturn('simpleId.subtest2'); group.addCheck(instance(mockHealthCheck2)); group.healthChecks.size.must.equal(1); Array.from(group.healthChecks.keys()).must.eql(['simpleId']); const simpleIdGroup = group.healthChecks.get('simpleId'); simpleIdGroup.must.be.instanceOf(HealthCheckGroup); const asGroup = simpleIdGroup as HealthCheckGroup; asGroup.healthChecks.size.must.equal(2); Array.from(asGroup.healthChecks.keys()).must.eql(['subtest', 'subtest2']); });
test('starting the group starts the checks', () => { const group = new HealthCheckGroup('test1'); const mockHealthCheck = mock<HealthCheck>(HealthCheck); when(mockHealthCheck.getCheckName()).thenReturn('simpleId'); group.addCheck(instance(mockHealthCheck)); group.start(); verify(mockHealthCheck.start()).once(); group.stop(); });
test('CRITICAL on exception', async () => { const check = new MySQLHealthCheck('testCheck', false); const mockedMysqlClient = mock(MySQLClient); when(mockedMysqlClient.ping(anything())).thenThrow(new Error('Error')); check.mysqlClient = instance(mockedMysqlClient); await check.runCheck(); const result = check.getLastResult(); result.status.must.equal(HealthCheckStatus.CRITICAL); });