diff --git a/src/app/workflow-spec-list/workflow-spec-list.component.spec.ts b/src/app/workflow-spec-list/workflow-spec-list.component.spec.ts index 32d2d22..32b3abe 100644 --- a/src/app/workflow-spec-list/workflow-spec-list.component.spec.ts +++ b/src/app/workflow-spec-list/workflow-spec-list.component.spec.ts @@ -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}`); diff --git a/src/app/workflow-spec-list/workflow-spec-list.component.ts b/src/app/workflow-spec-list/workflow-spec-list.component.ts index 2651ad9..2f8b4a5 100644 --- a/src/app/workflow-spec-list/workflow-spec-list.component.ts +++ b/src/app/workflow-spec-list/workflow-spec-list.component.ts @@ -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, - ): Array { - 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(); - } - }); - }); - } - */ - }