Skip to content

Commit

Permalink
fix: not work afterRenderEvent ( fix #1327 )
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktoast committed Jan 17, 2023
1 parent 7fb2f20 commit 9fe5954
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
39 changes: 39 additions & 0 deletions apps/calendar/src/components/events/horizontalEvent.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,35 @@ describe('Color values', () => {
});

describe('isReadOnly', () => {
function setup() {
const eventName = 'readonly-event';
const uiModel = new EventUIModel(
new EventModel({
id: '1',
title: eventName,
start: new Date(2020, 0, 1, 10, 0),
end: new Date(2020, 0, 1, 12, 0),
isReadOnly: true,
})
);

const props = {
uiModel,
eventHeight: 30,
headerHeight: 0,
};

return {
props,
};
}

it("should be able to show detail popup even if the model's `isReadOnly` property is `true`", () => {
// Given
const store = initCalendarStore({
useDetailPopup: true,
});

const eventName = 'readonly-event';
const uiModel = new EventUIModel(
new EventModel({
Expand All @@ -322,6 +346,7 @@ describe('isReadOnly', () => {
isReadOnly: true,
})
);

const props = {
uiModel,
eventHeight: 30,
Expand All @@ -341,4 +366,18 @@ describe('isReadOnly', () => {

expect(showDetailPopupSpy).toHaveBeenCalled();
});

it(`should fire 'afterRenderEvent' when it is in readonly mode`, () => {
// Given
const eventBus = new EventBusImpl<ExternalEventTypes>();
const handler = jest.fn();
eventBus.on('afterRenderEvent', handler);
const { props } = setup();

// When (resizingWidth)
render(<HorizontalEvent {...props} />, { eventBus });

// Then
expect(handler).toBeCalled();
});
});
2 changes: 1 addition & 1 deletion apps/calendar/src/components/events/horizontalEvent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export function HorizontalEvent({
});

useEffect(() => {
if (isDraggableEvent) {
if (isNil(resizingWidth) && isNil(movingLeft)) {
eventBus.fire('afterRenderEvent', uiModel.model.toEventObject());
}
// This effect is only for the first render.
Expand Down

0 comments on commit 9fe5954

Please sign in to comment.