diff --git a/packages/composer-playground/src/app/editor/editor.component.spec.ts b/packages/composer-playground/src/app/editor/editor.component.spec.ts index 476f3053c7..d2c29b9e55 100644 --- a/packages/composer-playground/src/app/editor/editor.component.spec.ts +++ b/packages/composer-playground/src/app/editor/editor.component.spec.ts @@ -37,7 +37,7 @@ import * as chai from 'chai'; import 'rxjs/add/operator/takeWhile'; import * as fileSaver from 'file-saver'; -import { DrawerService } from '../common/drawer/drawer.service'; +import { DrawerService, DrawerDismissReasons } from '../common/drawer'; let should = chai.should(); @@ -1143,6 +1143,29 @@ describe('EditorComponent', () => { drawerItem.close.should.have.been.called; mockAlertService.errorStatus$.next.should.not.have.been.called; })); + + it('should open the import modal, and handle cancel by escape without throwing an error', fakeAsync(() => { + let mockUpdatePackage = sinon.stub(component, 'updatePackageInfo'); + + let finishedImport = new BehaviorSubject(true); + + let drawerItem = { + componentInstance: { + finishedSampleImport: finishedImport + }, + close: sinon.stub() + }; + mockDrawer.open = sinon.stub().returns(drawerItem); + + component.openImportModal(); + + finishedImport.next({deployed: false, error: DrawerDismissReasons.ESC}); + + mockUpdatePackage.should.not.have.been.called; + mockFileService.loadFiles.should.not.have.been.called; + drawerItem.close.should.have.been.called; + mockAlertService.errorStatus$.next.should.not.have.been.called; + })); }); describe('exportBNA', () => { diff --git a/packages/composer-playground/src/app/editor/editor.component.ts b/packages/composer-playground/src/app/editor/editor.component.ts index 22c0829eb7..16a9c0e2cc 100644 --- a/packages/composer-playground/src/app/editor/editor.component.ts +++ b/packages/composer-playground/src/app/editor/editor.component.ts @@ -18,7 +18,7 @@ import { UpdateComponent } from '../import/update.component'; import { AddFileComponent } from './add-file/add-file.component'; import { DeleteComponent } from '../basic-modals/delete-confirm/delete-confirm.component'; import { ReplaceComponent } from '../basic-modals/replace-confirm'; -import { DrawerService } from '../common/drawer/drawer.service'; +import { DrawerService, DrawerDismissReasons } from '../common/drawer'; import { AdminService } from '../services/admin.service'; import { ClientService } from '../services/client.service'; @@ -379,7 +379,7 @@ export class EditorComponent implements OnInit, OnDestroy { } } else { importModalRef.close(); - if (result.error) { + if (result.error && result.error !== DrawerDismissReasons.ESC) { this.alertService.errorStatus$.next(result.error); } } diff --git a/packages/composer-playground/src/app/import/update.component.spec.ts b/packages/composer-playground/src/app/import/update.component.spec.ts index dbee7eb298..ec96cb6787 100644 --- a/packages/composer-playground/src/app/import/update.component.spec.ts +++ b/packages/composer-playground/src/app/import/update.component.spec.ts @@ -27,7 +27,7 @@ import { SampleBusinessNetworkService } from '../services/samplebusinessnetwork. import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { AlertService } from '../basic-modals/alert.service'; import { UpdateComponent } from './update.component'; -import { ActiveDrawer } from '../common/drawer'; +import { ActiveDrawer, DrawerDismissReasons } from '../common/drawer'; import { ModelManager, BusinessNetworkDefinition, @@ -489,6 +489,24 @@ describe('UpdateComponent', () => { mockAlertService.errorStatus$.next.should.have.been.calledWith('some error'); })); + it('should handle dismiss by esc key by without showing an error modal', fakeAsync(() => { + component['currentBusinessNetwork'] = {network: 'my network'}; + mockBusinessNetworkService.updateBusinessNetwork.returns(Promise.reject(DrawerDismissReasons.ESC)); + + component.finishedSampleImport.subscribe((result) => { + result.should.deep.equal({deployed: false}); + }); + + let deployPromise = component.deploy(); + + tick(); + + mockBusinessNetworkService.updateBusinessNetwork.should.have.been.calledWith({network: 'my network'}); + component['deployInProgress'].should.equal(false); + finishedSampleImportSpy.should.have.been.calledWith({deployed: false}); + mockAlertService.errorStatus$.next.should.not.have.been.called; + })); + it('should close the tray', fakeAsync(() => { component['currentBusinessNetwork'] = {network: 'my network'}; let traySpy = sinon.spy(component['activeDrawer'], 'close'); diff --git a/packages/composer-playground/src/app/import/update.component.ts b/packages/composer-playground/src/app/import/update.component.ts index 5db91196bc..13ced279b6 100644 --- a/packages/composer-playground/src/app/import/update.component.ts +++ b/packages/composer-playground/src/app/import/update.component.ts @@ -19,7 +19,7 @@ import { SampleBusinessNetworkService } from '../services/samplebusinessnetwork. import { AlertService } from '../basic-modals/alert.service'; import { ImportComponent } from './import.component'; import { ReplaceComponent } from '../basic-modals/replace-confirm'; -import { ActiveDrawer } from '../common/drawer'; +import { ActiveDrawer, DrawerDismissReasons } from '../common/drawer'; @Component({ selector: 'update-business-network', @@ -64,8 +64,12 @@ export class UpdateComponent extends ImportComponent { }) .catch((error) => { this.deployInProgress = false; - this.alertService.errorStatus$.next(error); - this.finishedSampleImport.emit({deployed: false, error: error}); + if (error === DrawerDismissReasons.ESC ) { + this.finishedSampleImport.emit({deployed: false}); + } else { + this.alertService.errorStatus$.next(error); + this.finishedSampleImport.emit({deployed: false, error: error}); + } }); }