diff --git a/frontend/src/hooks/useCalendar/useCalendar.test.ts b/frontend/src/hooks/useCalendar/useCalendar.test.ts index 33f616e1a..b2cc0011e 100644 --- a/frontend/src/hooks/useCalendar/useCalendar.test.ts +++ b/frontend/src/hooks/useCalendar/useCalendar.test.ts @@ -1,4 +1,4 @@ -import { act } from 'react'; +import { act } from '@testing-library/react'; import renderHookWithProvider from '@hooks/__test__/renderHookWithProvider'; @@ -191,18 +191,20 @@ describe('useCalendar', () => { const TEST_DATE = 4; beforeEach(() => { - jest.setSystemTime(new Date(TEST_YEAR + 1, TEST_MONTH, TEST_DATE)); + jest.setSystemTime(new Date(TEST_YEAR, TEST_MONTH, TEST_DATE)); }); - it('현재 월 기준, 약속 날짜 범위가 1년을 벗어나면 토스트 UI를 활용하여 사용자에게 예외 피드백을 전달한다', () => { + it('현재 월 기준, 약속 날짜 범위가 1년을 벗어나면 토스트 UI를 활용하여 사용자에게 예외 피드백을 전달한다', async () => { const { result } = renderHookWithProvider(useCalendar); - const { view } = result.current; - const { moveToNextMonth } = view; - act(() => { - moveToNextMonth(); - }); + // 1년이 12달이므로 moveToNextMonth() 함수를 13반 호출하면 범위를 초과합니다. + for (let i = 0; i < 13; i++) { + await act(async () => { + result.current.view.moveToNextMonth(); + }); + } + // 1년의 범위가 초과되었을 때, 토스트 메시지가 정상적으로 출력되는지 확인합니다. expect(mockAddToast).toHaveBeenCalledWith({ message: TOAST_MESSAGES.OUT_OF_ONE_YEAR_RANGE, type: 'warning', diff --git a/frontend/src/hooks/useCalendar/useCalendar.ts b/frontend/src/hooks/useCalendar/useCalendar.ts index 6e03e1def..5f1665d44 100644 --- a/frontend/src/hooks/useCalendar/useCalendar.ts +++ b/frontend/src/hooks/useCalendar/useCalendar.ts @@ -27,12 +27,12 @@ interface useCalendarReturn { isCurrentMonth: boolean; } -const TODAY = new Date(); -const ONE_YEAR_LATER = getFullDate(new Date(getYear(TODAY) + 1, getMonth(TODAY))); - type MonthDelta = -1 | 1; const useCalendar = (): useCalendarReturn => { + const TODAY = new Date(); + const ONE_YEAR_LATER = getFullDate(new Date(getYear(TODAY) + 1, getMonth(TODAY))); + const [currentFullDate, setCurrentFullDate] = useState(new Date()); const { addToast } = useToast(); @@ -51,7 +51,7 @@ const useCalendar = (): useCalendarReturn => { const moveToNextMonth = () => { const fullDate = getFullDate(currentFullDate); - if (fullDate >= ONE_YEAR_LATER) { + if (new Date(fullDate).getTime() >= new Date(ONE_YEAR_LATER).getTime()) { addToast({ message: TOAST_MESSAGES.OUT_OF_ONE_YEAR_RANGE, type: 'warning', diff --git a/frontend/src/pages/MeetingLinkSharePage/index.tsx b/frontend/src/pages/MeetingLinkSharePage/index.tsx index 52138ddc6..2e6e1556c 100644 --- a/frontend/src/pages/MeetingLinkSharePage/index.tsx +++ b/frontend/src/pages/MeetingLinkSharePage/index.tsx @@ -39,7 +39,7 @@ export default function MeetingLinkSharePage() { state: { meetingInfo }, } = useLocation() as RouteState; - const LINK = `${window.location.protocol}/${window.location.host}/meeting/${uuid}`; + const LINK = `${window.location.origin}/meeting/${uuid}`; const { handleKakaoTalkShare } = useKakaoTalkShare();