it('should only keep a max of 3 alerts', fakeAsync(inject([AlertService], (service: AlertService) => { component.ngOnInit(); service.successStatus$.next({title: 'myTitle1', text: 'myText', icon: '#icon', keep: true}); tick(); component['messages'].length.should.equal(1); component['messages'][0].should.deep.equal({title: 'myTitle1', text: 'myText', icon: '#icon', keep: true}); service.successStatus$.next({title: 'myTitle2', text: 'myText', icon: '#icon', keep: true}); tick(); component['messages'].length.should.equal(2); component['messages'][0].should.deep.equal({title: 'myTitle1', text: 'myText', icon: '#icon', keep: true}); component['messages'][1].should.deep.equal({title: 'myTitle2', text: 'myText', icon: '#icon', keep: true}); service.successStatus$.next({title: 'myTitle3', text: 'myText', icon: '#icon', keep: true}); tick(); component['messages'].length.should.equal(3); component['messages'][0].should.deep.equal({title: 'myTitle1', text: 'myText', icon: '#icon', keep: true}); component['messages'][1].should.deep.equal({title: 'myTitle2', text: 'myText', icon: '#icon', keep: true}); component['messages'][2].should.deep.equal({title: 'myTitle3', text: 'myText', icon: '#icon', keep: true}); service.successStatus$.next({title: 'myTitle4', text: 'myText', icon: '#icon', keep: true}); tick(); tick(); component['messages'].length.should.equal(3); component['messages'][0].should.deep.equal({title: 'myTitle2', text: 'myText', icon: '#icon', keep: true}); component['messages'][1].should.deep.equal({title: 'myTitle3', text: 'myText', icon: '#icon', keep: true}); component['messages'][2].should.deep.equal({title: 'myTitle4', text: 'myText', icon: '#icon', keep: true}); tick(messageTimeout); })));
it('should load all the identities and handle those bound to participants not found', fakeAsync(() => { let myLoadParticipantsMock = sinon.stub(component, 'loadParticipants'); let myGetParticipantMock = sinon.stub(component, 'getParticipant'); myLoadParticipantsMock.returns(Promise.resolve()); myGetParticipantMock.onFirstCall().returns(true); myGetParticipantMock.onSecondCall().returns(false); myGetParticipantMock.onThirdCall().returns(true); component.loadAllIdentities(); tick(); component['businessNetworkName'].should.equal('penguin-network'); myLoadParticipantsMock.should.have.been.called; component['allIdentities'].length.should.deep.equal(4); component['allIdentities'][0]['ref'].should.deep.equal('bob@penguin-network'); component['allIdentities'][0].should.not.have.property('state'); component['allIdentities'][1]['ref'].should.deep.equal('cardOne'); component['allIdentities'][1]['state'].should.deep.equal('BOUND PARTICIPANT NOT FOUND'); component['allIdentities'][2]['ref'].should.deep.equal('networkAdmin'); component['allIdentities'][2].should.not.have.property('state'); component['allIdentities'][3]['name'].should.deep.equal('tony'); component['allIdentities'][3].should.not.have.property('state'); component['currentIdentity'].should.deep.equal(currentCardRef); component['identityCards'].size.should.deep.equal(3); component['identityCards'].get(currentCardRef).should.deep.equal(currentIdCard); component['identityCards'].get('cardOne').should.deep.equal(cardOne); component['myIDs'].length.should.deep.equal(3); component['myIDs'][0]['ref'].should.deep.equal('bob@penguin-network'); component['myIDs'][0]['usable'].should.deep.equal(true); component['myIDs'][1]['ref'].should.deep.equal('cardOne'); component['myIDs'][1]['usable'].should.deep.equal(false); component['myIDs'][2]['ref'].should.deep.equal('networkAdmin'); component['myIDs'][2]['usable'].should.deep.equal(true); }));
it('should receive and parse station information', fakeAsync(() => { const stations: StationMap = dashboardService.stations; dashboardService.subscribe(); connectSuccessfully(); const message = {}; addStationToMessage(message, '12000', 'ONLINE'); addStationToMessage(message, '12001', 'UNREACHABLE'); receiveMockMessage(message); tick(); expect(dashboardService.isSubscribing).toBe(false); expect(dashboardService.hasError).toBe(false); // The API responses should be converted into Station objects. expect(Object.keys(stations).length).toEqual(2); expect(stations['localhost:12000'].stationId) .toEqual('mock-station-12000'); expect(stations['localhost:12000'].status).toEqual(StationStatus.online); expect(stations['localhost:12001'].stationId) .toEqual('mock-station-12001'); expect(stations['localhost:12001'].status) .toEqual(StationStatus.unreachable); }));
inject([JhiApplicationsService], (service: JhiApplicationsService) => { spyOn(service, 'findAll').and.returnValue(Observable.of({ status: null, applications: [ { name: 'app1', instances: [ { instanceId: 1, status: 'UP' }, { instanceId: 2, status: 'DOWN' } ] }, { name: 'app2', instances: [ { instanceId: 3, status: 'UP' } ] } ] })); comp.ngOnInit(); tick(); expect(service.findAll).toHaveBeenCalled(); expect(comp.appInstances.length).toEqual(3); })
it('should handle error adding identity to wallet', fakeAsync(() => { mockGetConnectionProfile.returns({ type: 'web' }); mockModal.open.returns({ result: Promise.resolve({userID: 'myId', userSecret: 'mySecret'}) }); mockAddIdentityToWallet.rejects(new Error('add identity to wallet error')); mockAlertService.errorStatus$.next.should.not.have.been.called; component.issueNewId(); tick(); mockModal.open.should.have.been.calledOnce; let expectedError = sinon.match(sinon.match.instanceOf(Error).and(sinon.match.has('message', 'add identity to wallet error'))); mockAlertService.errorStatus$.next.should.have.been.calledWith(expectedError); mockLoadAllIdentities.should.have.been.called; }));
it('queryId should be emptied if the cancellation success', fakeAsync(() => { pcapService.cancelQuery = jasmine.createSpy('cancelQuery').and.returnValue( defer(() => Promise.resolve()) ); component.queryRunning = true; component.queryId = 'testid'; fixture.detectChanges(); const cancelBtn = fixture.debugElement.query(By.css('[data-qe-id="pcap-cancel-query-button"]')); const cancelBtnEl = cancelBtn.nativeElement; cancelBtnEl.click(); fixture.detectChanges(); const confirmButton = fixture.debugElement.query(By.css('.pcap-cancel-query-confirm-popover .btn-danger')); const confirmButtonEl = confirmButton.nativeElement; confirmButtonEl.click(); tick(); fixture.detectChanges(); expect(component.queryId).toBeFalsy(); }));
it('should notify on 409 conflict error (might be in trash)', fakeAsync(() => { findSitesSpy.and.returnValue(Promise.resolve(findSitesResponse)); const error = { message: '{ "error": { "statusCode": 409 } }' }; spyOn(alfrescoApi.sitesApi, 'createSite').and.callFake(() => { return new Promise((resolve, reject) => reject(error)); }); spyOn(alfrescoApi.sitesApi, 'getSite').and.callFake(() => { return new Promise((resolve, reject) => reject()); }); fixture.detectChanges(); component.form.controls.title.setValue('test'); tick(500); flush(); fixture.detectChanges(); component.submit(); fixture.detectChanges(); flush(); expect(component.form.controls.id.errors).toEqual({ message: 'LIBRARY.ERRORS.CONFLICT' }); }));
inject([AuthService, MockBackend], fakeAsync((authService:AuthService, mockBackend:MockBackend) => { var result:IJsendResponse; mockBackend.connections.subscribe((c: MockConnection) => { expect(c.request.url).toBe('http://*****:*****@test.com', password: '******' })); let mockResponseBody: IJsendResponse = { status: 'success', data: { 'token': '12345' }, message: '' }; let response = new ResponseOptions({body: JSON.stringify(mockResponseBody)}); c.mockRespond(new Response(response)); }); authService.login('*****@*****.**', '12345').subscribe(response => { result = response; }); tick(); expect(result.data.token).toBe('12345'); expect(result.status).toBe('success'); expect(localStorage.getItem('auth_token')).toBe('12345') }))
it('should insert a watch', fakeAsync(() => { let watch = JSON.parse(jsonUser).watches[0]; watch.id = null; let result: Watch; twAPIService.upsertWatch(watch).then( response => { result = response; }, ); lastConnection.mockRespond(new Response(new ResponseOptions({ body: JSON.stringify(watch), }))); tick(); expect(result.id).toEqual(watch.id); expect(result.brand).toEqual(watch.brand); expect(result.name).toEqual(watch.name); expect(result.yearOfBuy).toEqual(watch.yearOfBuy); expect(result.serial).toEqual(watch.serial); expect(result.caliber).toEqual(watch.caliber); expect(lastConnection.request.url).toEqual(twAPIService.config.getAPIUrl() + "watches", "should be consumed"); }));
it('should handle error', fakeAsync(inject([SampleBusinessNetworkService], (service: SampleBusinessNetworkService) => { let repoMock = { contents: sinon.stub() }; repoMock.contents.returns({ fetch: sinon.stub().returns(Promise.reject('some error')) }); let octoMock = { repos: sinon.stub().returns(repoMock) }; service['octo'] = octoMock; service.getReadme('myOwner', 'myRepository', 'packages/') .then(() => { throw('should not get here'); }) .catch((error) => { error.should.equal('some error'); }); tick(); })));