Fixes #477 - Libraries not showing as 'selected spec' on page loads

Will load libraries on page loads now. will set master spec correctly. updating some tests
This commit is contained in:
alicia pritchett 2021-10-14 13:21:43 -04:00
parent 97736f824f
commit bed29dcabe
2 changed files with 35 additions and 26 deletions

View File

@ -18,7 +18,7 @@ import {
MockEnvironment, mockWorkflowMeta1,
mockWorkflowSpec0,
mockWorkflowSpec1,
mockWorkflowSpec2,
mockWorkflowSpec2, mockWorkflowSpec3,
mockWorkflowSpecCategories,
mockWorkflowSpecCategory0,
mockWorkflowSpecCategory1,
@ -260,6 +260,14 @@ describe('WorkflowSpecListComponent', () => {
expect(_loadWorkflowLibrariesSpy).toHaveBeenCalled();
});
it('should set a library spec as the selected spec', () => {
const _loadWorkflowLibrariesSpy = spyOn((component as any), '_loadWorkflowLibraries').and.stub();
(component as any)._loadWorkflowLibraries(mockWorkflowSpec3)
component.selectedSpec = mockWorkflowSpec3;
expect(_loadWorkflowLibrariesSpy).toHaveBeenCalled()
expect(component.selectedSpec).toEqual(mockWorkflowSpec3)
})
it('should show a metadata dialog when editing a workflow spec category', () => {
let mockCatData: WorkflowSpecCategoryDialogData = {
id: null,
@ -519,9 +527,6 @@ describe('WorkflowSpecListComponent', () => {
expect(component.workflowSpecs).toEqual(allSpecs);
expect(component.workflowSpecsByCategory).toBeTruthy();
component.workflowSpecsByCategory.forEach(cat => {
expect(cat.workflow_specs).not.toContain(mockMasterSpec);
});
expect(component.masterStatusSpec).toEqual(mockMasterSpec);
});

View File

@ -227,7 +227,7 @@ export class WorkflowSpecListComponent implements OnInit {
editCategoryDisplayOrder(catId: number, direction: string) {
this.api.reorderWorkflowCategory(catId, direction).subscribe(cat_change => {
this.workflowSpecsByCategory = this.workflowSpecsByCategory.map(cat => {
let new_cat = this.ensure(cat_change.find(i2 => i2.id === cat.id));
let new_cat = (cat_change.find(i2 => i2.id === cat.id));
cat.display_order = new_cat.display_order;
return cat;
});
@ -235,14 +235,6 @@ export class WorkflowSpecListComponent implements OnInit {
});
}
// ensure that in array.find, we find what we are expecting. (Ensures TS type safety)
ensure<T>(argument: T | undefined | null, message: string = 'Spec not found!'): T {
if (argument === undefined || argument === null) {
throw new TypeError(message);
}
return argument;
}
editSpecDisplayOrder(cat: WorkflowSpecCategoryGroup, specId: string, direction: string) {
this.api.reorderWorkflowSpecification(specId, direction).subscribe(wfs => {
@ -261,13 +253,24 @@ export class WorkflowSpecListComponent implements OnInit {
this.workflowSpecsByCategory[i].workflow_specs = [];
});
this._loadWorkflowSpecs(selectedSpecName);
this._loadWorkflowLibraries();
this._loadWorkflowLibraries(selectedSpecName);
});
}
private _loadWorkflowLibraries() {
private _loadWorkflowLibraries(selectedSpecName: string = null) {
this.api.getWorkflowSpecificationLibraries().subscribe(wfs => {
this.workflowLibraries = wfs;
// If selected spec is a library, set it.
if (selectedSpecName) {
wfs.forEach(ws => {
if (selectedSpecName && selectedSpecName === ws.id) {
this.selectedSpec = ws;
}
});
} else {
this.selectedSpec = this.masterStatusSpec;
}
});
}
@ -275,23 +278,26 @@ export class WorkflowSpecListComponent implements OnInit {
this.api.getWorkflowSpecList().subscribe(wfs => {
this.workflowSpecs = wfs;
// Populate categories with their specs
this.workflowSpecsByCategory.forEach(cat => {
cat.workflow_specs = this.workflowSpecs
.filter(wf => {
// Find and set master spec
if (wf.is_master_spec) {
this.masterStatusSpec = wf;
if (searchSpecName) {
return (wf.category_id === cat.id) && wf.display_name.toLowerCase().includes(searchSpecName.toLowerCase());
} else {
if (searchSpecName) {
return (wf.category_id === cat.id) && wf.display_name.toLowerCase().includes(searchSpecName.toLowerCase());
} else {
return wf.category_id === cat.id;
}
return wf.category_id === cat.id;
}
})
cat.workflow_specs.sort((x,y) => x.display_order - y.display_order);
});
// Set master spec
wfs.forEach(wf => {
if (wf.is_master_spec){
this.masterStatusSpec = wf;
}
});
// Set the selected workflow to something sensible.
if (!selectedSpecName && this.selectedSpec) {
selectedSpecName = this.selectedSpec.id;
@ -303,8 +309,6 @@ export class WorkflowSpecListComponent implements OnInit {
this.selectedCat = this.selectedSpec.category;
}
});
} else {
this.selectedSpec = this.masterStatusSpec;
}
});
}
@ -361,7 +365,7 @@ export class WorkflowSpecListComponent implements OnInit {
private _addWorkflowSpec(newSpec: WorkflowSpec) {
this.api.addWorkflowSpecification(newSpec).subscribe(_ => {
this._loadWorkflowLibraries();
this._loadWorkflowLibraries(newSpec.id);
this._loadWorkflowSpecs(newSpec.id);
this._displayMessage('Saved new workflow spec.');
});