Fix empty object causes error new workflow
This commit is contained in:
parent
627b01f971
commit
cc4eca40ab
@ -34,7 +34,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div ngbAccordion [closeOthers]="true">
|
<div ngbAccordion [closeOthers]="true">
|
||||||
@for (trigger of object.triggers; track trigger; let i = $index){
|
@for (trigger of object?.triggers; track trigger; let i = $index){
|
||||||
<div ngbAccordionItem>
|
<div ngbAccordionItem>
|
||||||
<div ngbAccordionHeader>
|
<div ngbAccordionHeader>
|
||||||
<button ngbAccordionButton>{{i + 1}}. {{getTriggerTypeOptionName(triggerFields.controls[i].value.type)}}
|
<button ngbAccordionButton>{{i + 1}}. {{getTriggerTypeOptionName(triggerFields.controls[i].value.type)}}
|
||||||
@ -76,7 +76,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div ngbAccordion [closeOthers]="true" cdkDropList (cdkDropListDropped)="onActionDrop($event)">
|
<div ngbAccordion [closeOthers]="true" cdkDropList (cdkDropListDropped)="onActionDrop($event)">
|
||||||
@for (action of object.actions; track action; let i = $index){
|
@for (action of object?.actions; track action; let i = $index){
|
||||||
<div ngbAccordionItem cdkDrag [formGroup]="actionFields.controls[i]">
|
<div ngbAccordionItem cdkDrag [formGroup]="actionFields.controls[i]">
|
||||||
<div ngbAccordionHeader>
|
<div ngbAccordionHeader>
|
||||||
<button ngbAccordionButton><ng-container i18n>Action</ng-container> {{i + 1}}
|
<button ngbAccordionButton><ng-container i18n>Action</ng-container> {{i + 1}}
|
||||||
|
@ -166,13 +166,22 @@ describe('ConsumptionTemplateEditDialogComponent', () => {
|
|||||||
fixture.detectChanges()
|
fixture.detectChanges()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should support create and edit modes', () => {
|
it('should support create and edit modes, support adding triggers and actions on new workflow', () => {
|
||||||
component.dialogMode = EditDialogMode.CREATE
|
component.dialogMode = EditDialogMode.CREATE
|
||||||
const createTitleSpy = jest.spyOn(component, 'getCreateTitle')
|
const createTitleSpy = jest.spyOn(component, 'getCreateTitle')
|
||||||
const editTitleSpy = jest.spyOn(component, 'getEditTitle')
|
const editTitleSpy = jest.spyOn(component, 'getEditTitle')
|
||||||
fixture.detectChanges()
|
fixture.detectChanges()
|
||||||
expect(createTitleSpy).toHaveBeenCalled()
|
expect(createTitleSpy).toHaveBeenCalled()
|
||||||
expect(editTitleSpy).not.toHaveBeenCalled()
|
expect(editTitleSpy).not.toHaveBeenCalled()
|
||||||
|
expect(component.object).toBeUndefined()
|
||||||
|
component.addAction()
|
||||||
|
expect(component.object).not.toBeUndefined()
|
||||||
|
expect(component.object.actions).toHaveLength(1)
|
||||||
|
component.object = undefined
|
||||||
|
component.addTrigger()
|
||||||
|
expect(component.object).not.toBeUndefined()
|
||||||
|
expect(component.object.triggers).toHaveLength(1)
|
||||||
|
|
||||||
component.dialogMode = EditDialogMode.EDIT
|
component.dialogMode = EditDialogMode.EDIT
|
||||||
fixture.detectChanges()
|
fixture.detectChanges()
|
||||||
expect(editTitleSpy).toHaveBeenCalled()
|
expect(editTitleSpy).toHaveBeenCalled()
|
||||||
|
@ -230,6 +230,9 @@ export class WorkflowEditDialogComponent
|
|||||||
}
|
}
|
||||||
|
|
||||||
addTrigger() {
|
addTrigger() {
|
||||||
|
if (!this.object) {
|
||||||
|
this.object = Object.assign({}, this.objectForm.value)
|
||||||
|
}
|
||||||
this.object.triggers.push({
|
this.object.triggers.push({
|
||||||
type: WorkflowTriggerType.Consumption,
|
type: WorkflowTriggerType.Consumption,
|
||||||
sources: [],
|
sources: [],
|
||||||
@ -253,6 +256,9 @@ export class WorkflowEditDialogComponent
|
|||||||
}
|
}
|
||||||
|
|
||||||
addAction() {
|
addAction() {
|
||||||
|
if (!this.object) {
|
||||||
|
this.object = Object.assign({}, this.objectForm.value)
|
||||||
|
}
|
||||||
this.object.actions.push({
|
this.object.actions.push({
|
||||||
type: WorkflowActionType.Assignment,
|
type: WorkflowActionType.Assignment,
|
||||||
assign_title: null,
|
assign_title: null,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user