From 8bb311d9109ee56e968286e9623b159dd5326205 Mon Sep 17 00:00:00 2001 From: Caroline Church Date: Thu, 15 Jun 2017 13:44:05 +0100 Subject: [PATCH] Add Various Tests Added tests to add-connection-profile Updated tests for connection-profile Updated tests for connection-profile-data Updated tests for basic models --- packages/composer-playground/.istanbul.yml | 2 +- .../add-connection-profile.component.spec.ts | 115 ++++++++++++++++-- .../confirm/confirm.component.spec.ts | 13 +- .../error/error.component.spec.ts | 44 ++++--- .../replace-confirm.component.spec.ts | 6 +- .../success/success.component.spec.ts | 2 - .../connection-profile-data.component.spec.ts | 2 + .../connection-profile.component.spec.ts | 5 +- 8 files changed, 146 insertions(+), 43 deletions(-) diff --git a/packages/composer-playground/.istanbul.yml b/packages/composer-playground/.istanbul.yml index 6552b9186e..b2fb3432c1 100644 --- a/packages/composer-playground/.istanbul.yml +++ b/packages/composer-playground/.istanbul.yml @@ -7,6 +7,6 @@ instrumentation: check: global: statements: 98 - branches: 91 + branches: 93 functions: 96 lines: 98 diff --git a/packages/composer-playground/src/app/add-connection-profile/add-connection-profile.component.spec.ts b/packages/composer-playground/src/app/add-connection-profile/add-connection-profile.component.spec.ts index 6d0e5c5653..96e4cb73bb 100644 --- a/packages/composer-playground/src/app/add-connection-profile/add-connection-profile.component.spec.ts +++ b/packages/composer-playground/src/app/add-connection-profile/add-connection-profile.component.spec.ts @@ -504,8 +504,6 @@ describe('AddConnectionProfileComponent', () => { }); describe('#addConnectionProfile', () => { - - let mockModal; let mockModalSpy; beforeEach(inject([NgbActiveModal], (activeModal: NgbActiveModal) => { @@ -529,8 +527,7 @@ describe('AddConnectionProfileComponent', () => { component['addConnectionProfileTimeout'] = TIMEOUT; })); - it('should deal with the version being 0.6 and a certificate', fakeAsync(() => { - let mockUpdate = sandbox.stub(component, 'updateConnectionProfiles').returns(Promise.resolve()); + it('should deal with the version being 0.6 and a certificate', () => { let EXP = { default: false, name: 'New Profile', @@ -551,10 +548,34 @@ describe('AddConnectionProfileComponent', () => { component['version'] = 'v06'; component.addConnectionProfile(); mockModalSpy.should.have.been.calledWith(EXP); - })); + }); - it('should deal with the version being 1', fakeAsync(() => { - let mockUpdate = sandbox.stub(component, 'updateConnectionProfiles').returns(Promise.resolve()); + it('should deal with the version being 0.6 and without a certificate', () => { + component['addConnectionProfileCertificate'] = null; + + let EXP = { + default: false, + name: 'New Profile', + profile: { + certificate: null, + certificatePath: CERT_PATH, + deployWaitTime: DEPLOY_TIME, + description: DESC, + eventHubURL: EH_URL, + invokeWaitTime: WAIT_TIME, + keyValStore: KEY_VAL_STORE, + membershipServicesURL: MS_URL, + peerURL: PEER_URL, + type: 'hlf' + } + }; + + component['version'] = 'v06'; + component.addConnectionProfile(); + mockModalSpy.should.have.been.calledWith(EXP); + }); + + it('should deal with the version being 1', () => { let EXP = { default: false, name: 'New Profile', @@ -574,15 +595,89 @@ describe('AddConnectionProfileComponent', () => { component['version'] = 'v1'; component.addConnectionProfile(); mockModalSpy.should.have.been.calledWith(EXP); - })); + }); + + it('should deal with the version being 0.6 and with a certificate just whitespace', () => { + component['addConnectionProfileCertificate'] = ' '; + + let EXP = { + default: false, + name: 'New Profile', + profile: { + certificate: ' ', + certificatePath: CERT_PATH, + deployWaitTime: DEPLOY_TIME, + description: DESC, + eventHubURL: EH_URL, + invokeWaitTime: WAIT_TIME, + keyValStore: KEY_VAL_STORE, + membershipServicesURL: MS_URL, + peerURL: PEER_URL, + type: 'hlf' + } + }; + + component['version'] = 'v06'; + component.addConnectionProfile(); + mockModalSpy.should.have.been.calledWith(EXP); + }); + + it('should deal with the version being 0.6 and with a certificate with new line char', () => { + component['addConnectionProfileCertificate'] = 'bob \n'; + + let EXP = { + default: false, + name: 'New Profile', + profile: { + certificate: 'bob \n', + certificatePath: CERT_PATH, + deployWaitTime: DEPLOY_TIME, + description: DESC, + eventHubURL: EH_URL, + invokeWaitTime: WAIT_TIME, + keyValStore: KEY_VAL_STORE, + membershipServicesURL: MS_URL, + peerURL: PEER_URL, + type: 'hlf' + } + }; + + component['version'] = 'v06'; + component.addConnectionProfile(); + mockModalSpy.should.have.been.calledWith(EXP); + }); + + it('should deal with the version being 1 with object orderers', () => { + component['addConnectionProfileOrderers'] = [{url: 'http://localhost', cert: 'bob', hostnameOverride: ''}]; + + let EXP = { + default: false, + name: 'New Profile', + profile: { + ca: CA, + channel: CHANNEL, + timeout: TIMEOUT, + description: DESC, + keyValStore: KEY_VAL_STORE, + mspID: MSPID, + orderers: [{url: 'http://localhost', cert: 'bob', hostnameOverride: ''}], + peers: PEERS, + type: 'hlfv1' + } + }; + + component['version'] = 'v1'; + component.addConnectionProfile(); + mockModalSpy.should.have.been.calledWith(EXP); + }); - it('should deal with an invalid version', fakeAsync(() => { + it('should deal with an invalid version', () => { try { component['version'] = 'badversion'; component.addConnectionProfile(); } catch (e) { e.message.should.contain('Unknown connection profile version selected'); } - })); + }); }); }); diff --git a/packages/composer-playground/src/app/basic-modals/confirm/confirm.component.spec.ts b/packages/composer-playground/src/app/basic-modals/confirm/confirm.component.spec.ts index 35a47c8372..c63f2ace75 100644 --- a/packages/composer-playground/src/app/basic-modals/confirm/confirm.component.spec.ts +++ b/packages/composer-playground/src/app/basic-modals/confirm/confirm.component.spec.ts @@ -2,20 +2,25 @@ /* tslint:disable:no-unused-expression */ /* tslint:disable:no-var-requires */ /* tslint:disable:max-classes-per-file */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { By } from '@angular/platform-browser'; -import { DebugElement } from '@angular/core'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ConfirmComponent } from './confirm.component'; import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; +import * as sinon from 'sinon'; +import * as chai from 'chai'; + +let should = chai.should(); + describe('ConfirmComponent', () => { let component: ConfirmComponent; let fixture: ComponentFixture; + let mockActiveModal = sinon.createStubInstance(NgbActiveModal); + beforeEach(() => { TestBed.configureTestingModule({ declarations: [ConfirmComponent], - providers: [NgbActiveModal] + providers: [{provide: NgbActiveModal, useValue: mockActiveModal}] }); fixture = TestBed.createComponent(ConfirmComponent); component = fixture.componentInstance; diff --git a/packages/composer-playground/src/app/basic-modals/error/error.component.spec.ts b/packages/composer-playground/src/app/basic-modals/error/error.component.spec.ts index 503c2cac04..af10fdeb5e 100644 --- a/packages/composer-playground/src/app/basic-modals/error/error.component.spec.ts +++ b/packages/composer-playground/src/app/basic-modals/error/error.component.spec.ts @@ -1,28 +1,32 @@ /* tslint:disable:no-unused-variable */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { By } from '@angular/platform-browser'; -import { DebugElement } from '@angular/core'; - +/* tslint:disable:no-unused-expression */ +/* tslint:disable:no-var-requires */ +/* tslint:disable:max-classes-per-file */ +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ErrorComponent } from './error.component'; +import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; + +import * as sinon from 'sinon'; +import * as chai from 'chai'; + +let should = chai.should(); describe('ErrorComponent', () => { - // let component: ErrorComponent; - // let fixture: ComponentFixture; + let component: ErrorComponent; + let fixture: ComponentFixture; - // beforeEach(async(() => { - // TestBed.configureTestingModule({ - // declarations: [ ErrorComponent ] - // }) - // .compileComponents(); - // })); + let mockActiveModal = sinon.createStubInstance(NgbActiveModal); - // beforeEach(() => { - // fixture = TestBed.createComponent(ErrorComponent); - // component = fixture.componentInstance; - // fixture.detectChanges(); - // }); + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ErrorComponent], + providers: [{provide: NgbActiveModal, useValue: mockActiveModal}] + }); + fixture = TestBed.createComponent(ErrorComponent); + component = fixture.componentInstance; + }); - // it('should create', () => { - // expect(component).toBeTruthy(); - // }); + it('should create', () => { + component.should.be.ok; + }); }); diff --git a/packages/composer-playground/src/app/basic-modals/replace-confirm/replace-confirm.component.spec.ts b/packages/composer-playground/src/app/basic-modals/replace-confirm/replace-confirm.component.spec.ts index 12612cb5e7..feb2448792 100644 --- a/packages/composer-playground/src/app/basic-modals/replace-confirm/replace-confirm.component.spec.ts +++ b/packages/composer-playground/src/app/basic-modals/replace-confirm/replace-confirm.component.spec.ts @@ -2,9 +2,7 @@ /* tslint:disable:no-unused-expression */ /* tslint:disable:no-var-requires */ /* tslint:disable:max-classes-per-file */ -import { async, ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing'; -import { By } from '@angular/platform-browser'; -import { DebugElement } from '@angular/core'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ReplaceComponent } from './replace-confirm.component'; import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; @@ -22,7 +20,7 @@ describe('ReplaceComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ declarations: [ReplaceComponent], - providers: [ {provide: NgbActiveModal, useValue: mockActiveModal} ] + providers: [{provide: NgbActiveModal, useValue: mockActiveModal}] }); fixture = TestBed.createComponent(ReplaceComponent); component = fixture.componentInstance; diff --git a/packages/composer-playground/src/app/basic-modals/success/success.component.spec.ts b/packages/composer-playground/src/app/basic-modals/success/success.component.spec.ts index 40c79a4c87..c40c2f8102 100644 --- a/packages/composer-playground/src/app/basic-modals/success/success.component.spec.ts +++ b/packages/composer-playground/src/app/basic-modals/success/success.component.spec.ts @@ -1,6 +1,5 @@ /* tslint:disable:no-unused-expression */ import { ComponentFixture, TestBed, inject, fakeAsync, tick } from '@angular/core/testing'; -import { Directive, EventEmitter, Output, Input } from '@angular/core'; import { SuccessComponent } from './success.component'; import { AlertService } from '../../services/alert.service'; @@ -11,7 +10,6 @@ let should = chai.should(); describe('SuccessComponent', () => { let component: SuccessComponent; let fixture: ComponentFixture; - let mockAlertConfig; let messageTimeout = 4000; diff --git a/packages/composer-playground/src/app/connection-profile-data/connection-profile-data.component.spec.ts b/packages/composer-playground/src/app/connection-profile-data/connection-profile-data.component.spec.ts index 367a9a94e8..4162d1f363 100644 --- a/packages/composer-playground/src/app/connection-profile-data/connection-profile-data.component.spec.ts +++ b/packages/composer-playground/src/app/connection-profile-data/connection-profile-data.component.spec.ts @@ -257,6 +257,8 @@ describe('ConnectionProfileDataComponent', () => { (() => { component.startEditing(); }).should.throw('Unknown connection profile type'); + + mockOnValueChanged.should.not.have.been.called; }); }); diff --git a/packages/composer-playground/src/app/connection-profile/connection-profile.component.spec.ts b/packages/composer-playground/src/app/connection-profile/connection-profile.component.spec.ts index 5ed16bfdaf..ea273cf6b9 100644 --- a/packages/composer-playground/src/app/connection-profile/connection-profile.component.spec.ts +++ b/packages/composer-playground/src/app/connection-profile/connection-profile.component.spec.ts @@ -228,12 +228,13 @@ describe('ConnectionProfileComponent', () => { component['previousConnectionProfile'] = {name : 'New Connection Profile'}; mockConnectionProfileService.getCurrentConnectionProfile.returns('bob'); - component['connectionProfiles'] = [{name : 'bob'}]; + component['connectionProfiles'] = [{name : 'fred'}, {name : 'bob'}]; let mockUpdateConnectionProfiles = sinon.stub(component, 'updateConnectionProfiles'); let mockSetCurrentProfile = sinon.stub(component, 'setCurrentProfile'); - component.profileUpdated({updated: true, connectionProfile: {name : 'bob'}}); + component.profileUpdated(null); mockUpdateConnectionProfiles.should.not.have.been.called; + mockSetCurrentProfile.should.have.been.calledOnce; mockSetCurrentProfile.should.have.been.calledWith({name : 'bob'}); }); });