Skip to content

Commit

Permalink
fix(prop): emit event when delete prop
Browse files Browse the repository at this point in the history
  • Loading branch information
liujuping committed Jan 30, 2024
1 parent ed7befb commit 59fb319
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/designer/src/document/node/props/prop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ export class Prop implements IProp, IPropParent {
@action
remove() {
this.parent.delete(this);
this.unset();
}

/**
Expand Down
29 changes: 29 additions & 0 deletions packages/designer/tests/document/node/props/prop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ const mockOwner = {
},
isInited: true,
emitPropChange: jest.fn(),
delete() {},
};

const mockPropsInst = {
owner: mockOwner,
delete() {},
};

mockPropsInst.props = mockPropsInst;

describe('Prop 类测试', () => {
Expand Down Expand Up @@ -595,6 +598,7 @@ describe('setValue with event', () => {
},
},
emitPropChange: jest.fn(),
delete() {},
};
mockEventBusEmit = jest.spyOn(propInstance.owner.document.designer.editor.eventBus, 'emit');
mockEmitPropChange = jest.spyOn(propInstance.owner, 'emitPropChange');
Expand Down Expand Up @@ -665,4 +669,29 @@ describe('setValue with event', () => {
propInstance.unset();
expect(mockEmitChange).toHaveBeenCalledTimes(1);
});

// remove
it('should has event when remove call', () => {
const oldValue = propInstance._value;

propInstance.remove();

const expectedPartialPropsInfo = expect.objectContaining({
key: propInstance.key,
newValue: undefined, // You can specifically test only certain keys
oldValue,
});

expect(propInstance.getValue()).toEqual(undefined);
// expect(propInstance.type).toBe('unset');
expect(mockEmitChange).toHaveBeenCalledWith({
oldValue,
newValue: undefined,
});
expect(mockEventBusEmit).toHaveBeenCalledWith(GlobalEvent.Node.Prop.InnerChange, expectedPartialPropsInfo);
expect(mockEmitPropChange).toHaveBeenCalledWith(expectedPartialPropsInfo);

propInstance.remove();
expect(mockEmitChange).toHaveBeenCalledTimes(1);
});
});

0 comments on commit 59fb319

Please sign in to comment.