Skip to content

Commit

Permalink
[FE] 약속 공유 링크 상수 경로 수정 (#434)
Browse files Browse the repository at this point in the history
* refactor: 링크 경로 상수 수정

* refactor(useCalendar): 상수 훅 내부 이동 및 moveToNextMonth 내부 로직 수정

* test(useCalendar): 테스트 케이스 로직 수정

* test(useCalendar): 변경된 테스트 케이스 주석 추가
  • Loading branch information
Largopie authored Dec 6, 2024
1 parent f31ce5e commit 07bfecd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
18 changes: 10 additions & 8 deletions frontend/src/hooks/useCalendar/useCalendar.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { act } from 'react';
import { act } from '@testing-library/react';

import renderHookWithProvider from '@hooks/__test__/renderHookWithProvider';

Expand Down Expand Up @@ -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',
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/hooks/useCalendar/useCalendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/MeetingLinkSharePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 07bfecd

Please sign in to comment.