Skip to content

Commit

Permalink
Merge pull request #1252 from nhn/fix/hide-form-popup
Browse files Browse the repository at this point in the history
  • Loading branch information
Dohyung Ahn authored Aug 16, 2022
2 parents 9f60468 + 5ea042b commit eb23820
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 19 deletions.
59 changes: 55 additions & 4 deletions apps/calendar/src/components/popup/eventDetailPopup.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import { initCalendarStore, StoreProvider, useDispatch } from '@src/contexts/cal
import { EventBusProvider } from '@src/contexts/eventBus';
import { FloatingLayerProvider } from '@src/contexts/floatingLayer';
import EventModel from '@src/model/eventModel';
import { render, screen } from '@src/test/utils';
import { render, screen, userEvent } from '@src/test/utils';
import TZDate from '@src/time/date';
import { EventBusImpl } from '@src/utils/eventBus';

import type { PropsWithChildren } from '@t/components/common';
import type { Options } from '@t/options';

describe('event detail popup', () => {
const mockCalendarId = 'calendarId';
Expand Down Expand Up @@ -48,7 +49,7 @@ describe('event detail popup', () => {
return <FloatingLayerProvider>{children}</FloatingLayerProvider>;
};

beforeEach(() => {
function setup(options: Options = {}) {
const eventBus = new EventBusImpl();
const store = initCalendarStore({
calendars: [
Expand All @@ -57,9 +58,14 @@ describe('event detail popup', () => {
name: mockCalendarName,
},
],
...options,
});

render(
// Spy should be set before rendering
const showFormPopupSpy = jest.fn();
store.getState().dispatch.popup.showFormPopup = showFormPopupSpy;

const renderResult = render(
<EventBusProvider value={eventBus}>
<StoreProvider store={store}>
<Wrapper>
Expand All @@ -68,23 +74,33 @@ describe('event detail popup', () => {
</StoreProvider>
</EventBusProvider>
);
});

return {
eventBus,
store,
renderResult,
showFormPopupSpy,
};
}

it('should display location when `event.location` is exists', () => {
setup();
const { location } = event;
const locationText = screen.getByText(location).textContent;

expect(locationText).toBe(location);
});

it('should display recurrence rule when `event.recurrenceRule` is exists', () => {
setup();
const { recurrenceRule } = event;
const recurrenceRuleText = screen.getByText(recurrenceRule).textContent;

expect(recurrenceRuleText).toBe(recurrenceRule);
});

it('should display attendees when `event.attendees` is exists', () => {
setup();
const { attendees } = event;
const text = attendees.join(', ');
const attendeesText = screen.getByText(text).textContent;
Expand All @@ -93,30 +109,65 @@ describe('event detail popup', () => {
});

it('should display state when `event.state` is exists', () => {
setup();
const { state } = event;
const stateText = screen.getByText(state).textContent;

expect(stateText).toBe(state);
});

it('should display calendar name when `event.calendarId` and corresponding calendar is exists', () => {
setup();
const calendarName = screen.getByText(mockCalendarName);

expect(calendarName).toBeInTheDocument();
});

it('should display body when `event.body` is exists', () => {
setup();
const { body } = event;
const bodyText = screen.getByText(body).textContent;

expect(bodyText).toBe(body);
});

it('should display edit and delete buttons when event is not read only', () => {
setup();
const editButton = screen.getByText('Edit');
const deleteButton = screen.getByText('Delete');

expect(editButton).not.toBeNull();
expect(deleteButton).not.toBeNull();
});

it('should open the form popup when edit button is clicked, while the `useFormPopup` option is enabled', async () => {
// Given
const { showFormPopupSpy } = setup({ useFormPopup: true });
const user = userEvent.setup();
const editButton = screen.getByText('Edit');

// When
await user.click(editButton);

// Then
expect(showFormPopupSpy).toHaveBeenCalledWith(expect.objectContaining({ event }));
});

it('should only fire the `beforeUpdateEvent` event when edit button is clicked, while the `useFormPopup` option is disabled', async () => {
// Given
const { eventBus } = setup({ useFormPopup: false });
const mockEventHandler = jest.fn();
eventBus.on('beforeUpdateEvent', mockEventHandler);

const user = userEvent.setup();
const editButton = screen.getByText('Edit');

// When
await user.click(editButton);

// Then
expect(mockEventHandler).toHaveBeenCalledWith(
expect.objectContaining({ event: event.toEventObject() })
);
});
});
33 changes: 20 additions & 13 deletions apps/calendar/src/components/popup/eventDetailPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useLayoutContainer } from '@src/contexts/layoutContainer';
import { cls } from '@src/helpers/css';
import { isLeftOutOfLayout, isTopOutOfLayout } from '@src/helpers/popup';
import { useCalendarColor } from '@src/hooks/calendar/useCalendarColor';
import { optionsSelector } from '@src/selectors';
import { eventDetailPopupParamSelector } from '@src/selectors/popup';
import TZDate from '@src/time/date';
import { isNil } from '@src/utils/type';
Expand Down Expand Up @@ -66,6 +67,7 @@ function calculatePopupArrowPosition(eventRect: Rect, layoutRect: Rect, popupRec
}

export function EventDetailPopup() {
const { useFormPopup } = useStore(optionsSelector);
const popupParams = useStore(eventDetailPopupParamSelector);
const { event, eventRect } = popupParams ?? {};

Expand Down Expand Up @@ -128,19 +130,24 @@ export function EventDetailPopup() {
left: eventRect.left + eventRect.width / 2,
};

const onClickEditButton = () =>
showFormPopup({
isCreationPopup: false,
event,
title,
location,
start,
end,
isAllday,
isPrivate,
eventState: state,
popupArrowPointPosition,
});
const onClickEditButton = () => {
if (useFormPopup) {
showFormPopup({
isCreationPopup: false,
event,
title,
location,
start,
end,
isAllday,
isPrivate,
eventState: state,
popupArrowPointPosition,
});
} else {
eventBus.fire('beforeUpdateEvent', { event: event.toEventObject(), changes: {} });
}
};

const onClickDeleteButton = () => {
eventBus.fire('beforeDeleteEvent', event.toEventObject());
Expand Down
3 changes: 2 additions & 1 deletion docs/en/apis/calendar.md
Original file line number Diff line number Diff line change
Expand Up @@ -809,8 +809,9 @@ The `event` property is information of the existing event, and the `changes` pro

In the following cases, `beforeUpdateEvent` is executed.

- `When useFormPopup` and `useDetailPopup` of the calendar instance options are both `true` and the ‘Update’ button is pressed after modifying the event through the event details popup
- When `useFormPopup` and `useDetailPopup` of the calendar instance options are both `true` and the ‘Update’ button is pressed after modifying the event through the event details popup
- ![Event execution through popup](../../assets/before-update-event-1.gif)
- When the `useDetailPopup` option is `true` and the `useFormPopup` is `false`, the 'Edit' button inside the event details popup is pressed.
- When moving or resizing events by drag and drop, while `isReadOnly` is not `true` among calendar instance options and also `isReadOnly` is not `true` in the properties of individual events.
- ![Event execution via drag and drop](../../assets/before-update-event-2.gif)

Expand Down
3 changes: 2 additions & 1 deletion docs/ko/apis/calendar.md
Original file line number Diff line number Diff line change
Expand Up @@ -815,8 +815,9 @@ interface UpdatedEventInfo {

다음의 경우 `beforeUpdateEvent` 가 실행된다.

- 캘린더 인스턴스 옵션 중 `useFormPopup``useDetailPopup` 가 모두 `true` 이고, 이벤트 상세 팝업을 통해 이벤트를 수정 후 Update 버튼을 누를 때
- 캘린더 인스턴스 옵션 중 `useFormPopup``useDetailPopup` 가 모두 `true` 이고, 이벤트 상세 팝업에서 Edit 버튼을 누른 후 표시되는 이벤트 폼 팝업에서 Update 버튼을 누를 때
- ![팝업을 통한 이벤트 실행](../../assets/before-update-event-1.gif)
- 캘린더의 인스턴스 옵션 중 `useDetailPopup``true` 이고, `useFormPopup``false` 일 때, 이벤트 상세 팝업에서 Edit 버튼을 누른 경우
- 캘린더 인스턴스 옵션 중 `isReadOnly``true` 가 아니며, 개별 이벤트의 속성에 `isReadOnly``true` 가 아닌 상태에서 드래그 앤 드랍으로 일정을 이동하거나 리사이징할 때
- ![드래그 앤 드랍을 통한 이벤트 실행](../../assets/before-update-event-2.gif)

Expand Down

0 comments on commit eb23820

Please sign in to comment.