Skip to content

Commit

Permalink
added esc key check for import modal, plus tests (hyperledger-archive…
Browse files Browse the repository at this point in the history
…s#3396)

Signed-off-by: Erin Hughes <[email protected]>
  • Loading branch information
erin-hughes authored and nklincoln committed Feb 14, 2018
1 parent a8276de commit 47a4e5a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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<any>(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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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');
Expand Down
10 changes: 7 additions & 3 deletions packages/composer-playground/src/app/import/update.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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});
}
});
}

Expand Down

0 comments on commit 47a4e5a

Please sign in to comment.