diff --git a/packages/composer-playground/src/app/test/test.component.html b/packages/composer-playground/src/app/test/test.component.html
index e980ed5230..83acc10f58 100644
--- a/packages/composer-playground/src/app/test/test.component.html
+++ b/packages/composer-playground/src/app/test/test.component.html
@@ -36,7 +36,7 @@
All Transactions
-
diff --git a/packages/composer-playground/src/app/test/test.component.spec.ts b/packages/composer-playground/src/app/test/test.component.spec.ts
index 12c681b997..2f4223383a 100644
--- a/packages/composer-playground/src/app/test/test.component.spec.ts
+++ b/packages/composer-playground/src/app/test/test.component.spec.ts
@@ -17,6 +17,9 @@ import * as sinon from 'sinon';
import * as chai from 'chai';
import { BusinessNetworkConnection } from 'composer-client';
+import { Introspector,
+ BusinessNetworkDefinition,
+ TransactionDeclaration } from 'composer-common';
let should = chai.should();
@@ -48,8 +51,16 @@ describe('TestComponent', () => {
let mockAlertService;
let mockTransactionService;
let mockModal;
-
+ let mockIntrospector;
+ let mockBusinessNetwork;
let mockBusinessNetworkConnection;
+ let mockTransaction;
+
+ class MockModelClass {
+ isAbstract(): boolean {
+ return true;
+ }
+ }
let sandbox;
@@ -61,6 +72,12 @@ describe('TestComponent', () => {
mockAlertService = sinon.createStubInstance(AlertService);
mockModal = sinon.createStubInstance(NgbModal);
mockBusinessNetworkConnection = sinon.createStubInstance(BusinessNetworkConnection);
+ mockBusinessNetwork = sinon.createStubInstance(BusinessNetworkDefinition);
+ mockIntrospector = sinon.createStubInstance(Introspector);
+ mockTransaction = sinon.createStubInstance(TransactionDeclaration);
+
+ mockClientService.getBusinessNetwork.returns(mockBusinessNetwork);
+ mockBusinessNetwork.getIntrospector.returns(mockIntrospector);
mockTransactionService = sinon.createStubInstance(TransactionService);
mockBusinessNetworkConnection.listenerCount.returns(0);
mockBusinessNetworkConnection.on = sinon.stub();
@@ -87,7 +104,9 @@ describe('TestComponent', () => {
});
describe('ngOnInit', () => {
+
beforeEach(() => {
+ mockIntrospector.getClassDeclarations.returns([mockTransaction]);
mockAlertService.errorStatus$ = {next: sinon.stub()};
});
@@ -95,13 +114,52 @@ describe('TestComponent', () => {
component.should.be.ok;
});
- it('should load all the registries', fakeAsync(() => {
+ it('should load all the registries and hasTransactions should be true', fakeAsync(() => {
+ mockInitializationService.initialize.returns(Promise.resolve());
+
+ mockBusinessNetworkConnection.getAllAssetRegistries.returns(Promise.resolve([{id: 'asset.fred'}, {id: 'asset.bob'}]));
+ mockBusinessNetworkConnection.getAllParticipantRegistries.returns(Promise.resolve([{id: 'participant.fred'}, {id: 'participant.bob'}]));
+ mockBusinessNetworkConnection.getTransactionRegistry.returns(Promise.resolve('transactionRegistry'));
+ mockClientService.getBusinessNetworkConnection.returns(mockBusinessNetworkConnection);
+
+ component.ngOnInit();
+ tick();
+
+ mockClientService.getBusinessNetworkConnection.should.have.been.called;
+ mockBusinessNetworkConnection.getAllAssetRegistries.should.have.been.called;
+
+ component['assetRegistries'].length.should.equal(2);
+
+ component['assetRegistries'][0].should.deep.equal({id: 'asset.bob', displayName: 'bob'});
+ component['assetRegistries'][1].should.deep.equal({id: 'asset.fred', displayName: 'fred'});
+
+ mockBusinessNetworkConnection.getAllParticipantRegistries.should.have.been.called;
+
+ component['participantRegistries'].length.should.equal(2);
+
+ component['participantRegistries'][0].should.deep.equal({id: 'participant.bob', displayName: 'bob'});
+ component['participantRegistries'][1].should.deep.equal({id: 'participant.fred', displayName: 'fred'});
+
+ mockBusinessNetworkConnection.getTransactionRegistry.should.have.been.called;
+
+ component['transactionRegistry'].should.equal('transactionRegistry');
+
+ component['chosenRegistry'].should.deep.equal({id: 'participant.bob', displayName: 'bob'});
+
+ mockClientService.getBusinessNetwork.should.have.been.called;
+ mockBusinessNetwork.getIntrospector.should.have.been.called;
+ mockIntrospector.getClassDeclarations.should.have.been.called;
+ component.hasTransactions.should.be.true;
+ }));
+
+ it('should load all the registries and hasTransactions should be false', fakeAsync(() => {
mockInitializationService.initialize.returns(Promise.resolve());
mockBusinessNetworkConnection.getAllAssetRegistries.returns(Promise.resolve([{id: 'asset.fred'}, {id: 'asset.bob'}]));
mockBusinessNetworkConnection.getAllParticipantRegistries.returns(Promise.resolve([{id: 'participant.fred'}, {id: 'participant.bob'}]));
mockBusinessNetworkConnection.getTransactionRegistry.returns(Promise.resolve('transactionRegistry'));
mockClientService.getBusinessNetworkConnection.returns(mockBusinessNetworkConnection);
+ mockIntrospector.getClassDeclarations.returns([new MockModelClass()]);
component.ngOnInit();
@@ -127,6 +185,11 @@ describe('TestComponent', () => {
component['transactionRegistry'].should.equal('transactionRegistry');
component['chosenRegistry'].should.deep.equal({id: 'participant.bob', displayName: 'bob'});
+
+ mockClientService.getBusinessNetwork.should.have.been.called;
+ mockBusinessNetwork.getIntrospector.should.have.been.called;
+ mockIntrospector.getClassDeclarations.should.have.been.called;
+ component.hasTransactions.should.be.false;
}));
it('should set chosen registry to first asset one if no participant registries', fakeAsync(() => {
@@ -218,7 +281,6 @@ describe('TestComponent', () => {
});
describe('submitTransaction', () => {
- let mockTransaction;
beforeEach(() => {
mockTransaction = sinon.createStubInstance(Resource);
mockTransaction.getIdentifier.returns(1);
diff --git a/packages/composer-playground/src/app/test/test.component.ts b/packages/composer-playground/src/app/test/test.component.ts
index 9a8bcd1e34..b41c2fda27 100644
--- a/packages/composer-playground/src/app/test/test.component.ts
+++ b/packages/composer-playground/src/app/test/test.component.ts
@@ -5,6 +5,7 @@ import { ClientService } from '../services/client.service';
import { InitializationService } from '../services/initialization.service';
import { AlertService } from '../basic-modals/alert.service';
import { TransactionComponent } from './transaction/transaction.component';
+import { TransactionDeclaration } from 'composer-common';
import { TransactionService } from '../services/transaction.service';
@Component({
@@ -17,6 +18,7 @@ import { TransactionService } from '../services/transaction.service';
export class TestComponent implements OnInit, OnDestroy {
+ hasTransactions = false;
private assetRegistries = [];
private participantRegistries = [];
private transactionRegistry = null;
@@ -34,9 +36,18 @@ export class TestComponent implements OnInit, OnDestroy {
ngOnInit(): Promise
{
this.initializeEventListener();
return this.initializationService.initialize()
- .then(() => {
- return this.clientService.getBusinessNetworkConnection().getAllAssetRegistries();
- })
+ .then(() => {
+
+ let introspector = this.clientService.getBusinessNetwork().getIntrospector();
+ let modelClassDeclarations = introspector.getClassDeclarations();
+ modelClassDeclarations.forEach((modelClassDeclaration) => {
+ // Generate list of all known (non-abstract) transaction types
+ if (!modelClassDeclaration.isAbstract() && modelClassDeclaration instanceof TransactionDeclaration) {
+ this.hasTransactions = true;
+ }
+ });
+
+ return this.clientService.getBusinessNetworkConnection().getAllAssetRegistries()
.then((assetRegistries) => {
assetRegistries.forEach((assetRegistry) => {
let index = assetRegistry.id.lastIndexOf('.');
@@ -78,6 +89,10 @@ export class TestComponent implements OnInit, OnDestroy {
.catch((error) => {
this.alertService.errorStatus$.next(error);
});
+ })
+ .catch((error) => {
+ this.alertService.errorStatus$.next(error);
+ });
}
ngOnDestroy() {