Merge pull request #115 from sartography/bug/fix-bpmn-tests

Potential fix for the bpmn tests
This commit is contained in:
Dan Funk 2021-10-19 11:20:03 -04:00 committed by GitHub
commit be64fbe29c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 153 deletions

View File

@ -402,93 +402,27 @@ describe('WorkflowSpecListComponent', () => {
});
/**
* Deprecated - removed reorder and ability to directly edit display order
*
it('should edit category display order', () => {
// const _reorderSpy = spyOn((component as any), '_reorder').and.stub();
const _updateCatDisplayOrdersSpy = spyOn((component as any), '_updateCatDisplayOrders').and.stub();
component.editCategoryDisplayOrder(2, -1, mockWorkflowSpecCategories);
// expect(_reorderSpy).toHaveBeenCalled();
expect(_updateCatDisplayOrdersSpy).toHaveBeenCalled();
});
it('should edit workflow spec display order', () => {
// const _reorderSpy = spyOn((component as any), '_reorder').and.stub();
const _updateSpecDisplayOrdersSpy = spyOn((component as any), '_updateSpecDisplayOrders').and.stub();
component.editSpecDisplayOrder('few_things', -1, mockWorkflowSpecs);
// expect(_reorderSpy).toHaveBeenCalled();
expect(_updateSpecDisplayOrdersSpy).toHaveBeenCalled();
});
it('should reorder categories', () => {
const snackBarSpy = spyOn((component as any).snackBar, 'open').and.stub();
const moveUpSpy = spyOn(component, 'moveUp').and.callThrough();
const moveDownSpy = spyOn(component, 'moveDown').and.callThrough();
const expectedCatsAfter = [mockWorkflowSpecCategory1, mockWorkflowSpecCategory0, mockWorkflowSpecCategory2];
expect((component as any)._reorder(99, 1, mockWorkflowSpecCategories)).toEqual([]);
expect(snackBarSpy).toHaveBeenCalled();
expect(moveUpSpy).not.toHaveBeenCalled();
expect(moveDownSpy).not.toHaveBeenCalled();
snackBarSpy.calls.reset();
moveUpSpy.calls.reset();
moveDownSpy.calls.reset();
expect((component as any)._reorder(1, -1, mockWorkflowSpecCategories)).toEqual(expectedCatsAfter);
expect(snackBarSpy).not.toHaveBeenCalled();
expect(moveUpSpy).toHaveBeenCalled();
expect(moveDownSpy).not.toHaveBeenCalled();
snackBarSpy.calls.reset();
moveUpSpy.calls.reset();
moveDownSpy.calls.reset();
expect((component as any)._reorder(0, 1, mockWorkflowSpecCategories)).toEqual(expectedCatsAfter);
expect(snackBarSpy).not.toHaveBeenCalled();
expect(moveUpSpy).not.toHaveBeenCalled();
expect(moveDownSpy).toHaveBeenCalled();
});
it('should reorder specs', () => {
const snackBarSpy = spyOn((component as any).snackBar, 'open').and.stub();
const moveUpSpy = spyOn(component, 'moveUp').and.callThrough();
const moveDownSpy = spyOn(component, 'moveDown').and.callThrough();
const specsAfter = [
mockWorkflowSpec1,
mockWorkflowSpec0,
mockWorkflowSpec2,
];
expect((component as any)._reorder('nonexistent_id', 1, mockWorkflowSpecs)).toEqual([]);
expect(snackBarSpy).toHaveBeenCalled();
expect(moveUpSpy).not.toHaveBeenCalled();
expect(moveDownSpy).not.toHaveBeenCalled();
snackBarSpy.calls.reset();
moveUpSpy.calls.reset();
moveDownSpy.calls.reset();
expect((component as any)._reorder(mockWorkflowSpec1.id, -1, mockWorkflowSpecs)).toEqual(specsAfter);
expect(snackBarSpy).not.toHaveBeenCalled();
expect(moveUpSpy).toHaveBeenCalled();
expect(moveDownSpy).not.toHaveBeenCalled();
snackBarSpy.calls.reset();
moveUpSpy.calls.reset();
moveDownSpy.calls.reset();
expect((component as any)._reorder(mockWorkflowSpec0.id, 1, mockWorkflowSpecs)).toEqual(specsAfter);
expect(snackBarSpy).not.toHaveBeenCalled();
expect(moveUpSpy).not.toHaveBeenCalled();
expect(moveDownSpy).toHaveBeenCalled();
});
*/
it('should update a single category display order', () => {
mockWorkflowSpecCategory1.id = 5;
// Intermittently, Jasmine does not find the array prototype function, causing errors.
// This defines the 'find' function in case it doesn't find it.
if (typeof Array.prototype.find !== 'function') {
Array.prototype.find = function(iterator) {
let list = Object(this);
let length = list.length >>> 0;
let thisArg = arguments[1];
let value;
for (let i = 0; i < length; i++) {
value = list[i];
if (iterator.call(thisArg, value, i, list)) {
return value;
}
}
return undefined;
};
}
(component as any).editCategoryDisplayOrder(mockWorkflowSpecCategory1.id, 'down');
let results = { param: 'direction', value: 'down' };
const req = httpMock.expectOne(`apiRoot/workflow-specification-category/${mockWorkflowSpecCategory1.id}/reorder?${results.param}=${results.value}`);

View File

@ -391,73 +391,5 @@ export class WorkflowSpecListComponent implements OnInit {
this.snackBar.open(message, 'Ok', {duration: 3000});
}
/**
* Deprecated - backend now reorders
*
private _reorder(
id: number | string, direction: number,
list: Array<WorkflowSpecCategoryGroup | WorkflowSpec>,
): Array<WorkflowSpecCategoryGroup | WorkflowSpec> {
const listClone = cloneDeep(list);
const reorderedList = listClone.filter(item => item.id !== null && item.id !== undefined);
const i = reorderedList.findIndex(spec => spec.id === id);
if (i !== -1) {
if (direction === 1) {
this.moveDown(reorderedList, i);
} else if (direction === -1) {
this.moveUp(reorderedList, i);
}
return reorderedList;
} else {
this.snackBar.open('Item not found. Reload the page and try again.');
return [];
}
}
**/
/**
* Deprecated - backend updates display_order
*
private _updateCatDisplayOrders(cats: WorkflowSpecCategory[]) {
let numUpdated = 0;
cats.forEach((cat, j) => {
if (isNumberDefined(cat.id)) {
const newCat: WorkflowSpecCategoryGroup = cloneDeep(cat);
delete newCat.workflow_specs;
newCat.display_order = j;
this.api.updateWorkflowSpecCategory(cat.id, newCat as WorkflowSpecCategory).subscribe(() => {
numUpdated++;
if (numUpdated === cats.length) {
this._loadWorkflowSpecCategories();
}
});
}
});
}
private _updateSpecDisplayOrders(specs: WorkflowSpec[]) {
if (this.selectedCat && this.selectedSpec.category) {
if (this.selectedCat.id !== this.selectedSpec.category.id) {
this.selectedSpec = specs[0];
}
}
let numUpdated = 0;
specs.forEach((spec, j) => {
const newSpec = cloneDeep(spec);
newSpec.display_order = j;
this.api.updateWorkflowSpecification(newSpec.id, newSpec).subscribe(() => {
numUpdated++;
if (numUpdated === specs.length) {
this._loadWorkflowSpecCategories();
}
});
});
}
*/
}