fix this last test - dont delete libraries referenced elsewhere

This commit is contained in:
alicia pritchett 2022-02-10 15:11:47 -05:00
parent 8f5d87935c
commit d40e2bc176
2 changed files with 12 additions and 10 deletions

View File

@ -495,10 +495,7 @@ describe('WorkflowSpecListComponent', () => {
it('should not delete a library if it is being used', () => { it('should not delete a library if it is being used', () => {
const badWorkflowSpec = cloneDeep(mockWorkflowSpec0); const badWorkflowSpec = cloneDeep(mockWorkflowSpec0);
badWorkflowSpec.parents=[ mockWorkflowSpec1.libraries = ['all_things']
{ id: 1234,
display_name: 'test parent',
}]
badWorkflowSpec.library=true; badWorkflowSpec.library=true;
const mockConfirmDeleteData: DeleteWorkflowSpecDialogData = { const mockConfirmDeleteData: DeleteWorkflowSpecDialogData = {
confirm: false, confirm: false,
@ -508,12 +505,10 @@ describe('WorkflowSpecListComponent', () => {
const _deleteWorkflowSpecSpy = spyOn((component as any), '_deleteWorkflowSpec').and.stub(); const _deleteWorkflowSpecSpy = spyOn((component as any), '_deleteWorkflowSpec').and.stub();
const openDialogSpy = spyOn(component.dialog, 'open') const openDialogSpy = spyOn(component.dialog, 'open')
.and.returnValue({afterClosed: () => of(mockConfirmDeleteData)} as any); .and.returnValue({afterClosed: () => of(mockConfirmDeleteData)} as any);
const snackBarSpy = spyOn((component as any).snackBar, 'open').and.stub();
mockConfirmDeleteData.confirm = true; mockConfirmDeleteData.confirm = true;
component.confirmDeleteWorkflowSpec(badWorkflowSpec); component.confirmDeleteWorkflowSpec(badWorkflowSpec);
expect(openDialogSpy).toHaveBeenCalled(); expect(openDialogSpy).toHaveBeenCalled();
expect(_deleteWorkflowSpecSpy).not.toHaveBeenCalled(); expect(_deleteWorkflowSpecSpy).not.toHaveBeenCalled();
expect(snackBarSpy).toHaveBeenCalled();
}); });

View File

@ -191,10 +191,15 @@ export class WorkflowSpecListComponent implements OnInit {
canDeleteWorkflowSpec(wfs){ canDeleteWorkflowSpec(wfs){
// TODO: move this to the backend // TODO: put the popup back in for this
// Find if library is still being referenced somewhere. If so, return a message about where let references = []
if (wfs.library){ if (wfs.library){
// return false; this.workflowSpecs.forEach(spec => {
if (spec.libraries.indexOf(wfs.id) >= 0 ) {
references.push(wfs.id);
}
});
return false; // and later return and deal with references
} }
return true; return true;
} }
@ -210,10 +215,12 @@ export class WorkflowSpecListComponent implements OnInit {
dialogRef.afterClosed().subscribe((data: DeleteWorkflowSpecDialogData) => { dialogRef.afterClosed().subscribe((data: DeleteWorkflowSpecDialogData) => {
if (data && data.confirm && data.workflowSpec && this.canDeleteWorkflowSpec(data.workflowSpec)) { if (data && data.confirm && data.workflowSpec && this.canDeleteWorkflowSpec(data.workflowSpec)) {
this._deleteWorkflowSpec(data.workflowSpec); 7 this._deleteWorkflowSpec(data.workflowSpec);
if (typeof this.masterStatusSpec !== 'undefined') { if (typeof this.masterStatusSpec !== 'undefined') {
this.selectSpec(this.masterStatusSpec); this.selectSpec(this.masterStatusSpec);
} }
} else {
// TODO: the library is being referenced elsewhere still
} }
}); });
} }