Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 1 addition & 64 deletions src/__mocks__/response/realEvents.json
Original file line number Diff line number Diff line change
@@ -1,64 +1 @@
{
"events": [
{
"id": "2b7545a6-ebee-426c-b906-2329bc8d62bd",
"title": "팀 회의",
"date": "2025-08-20",
"startTime": "10:00",
"endTime": "11:00",
"description": "주간 팀 미팅",
"location": "회의실 A",
"category": "업무",
"repeat": { "type": "none", "interval": 0 },
"notificationTime": 1
},
{
"id": "09702fb3-a478-40b3-905e-9ab3c8849dcd",
"title": "점심 약속",
"date": "2025-08-21",
"startTime": "12:30",
"endTime": "13:30",
"description": "동료와 점심 식사",
"location": "회사 근처 식당",
"category": "개인",
"repeat": { "type": "none", "interval": 0 },
"notificationTime": 1
},
{
"id": "da3ca408-836a-4d98-b67a-ca389d07552b",
"title": "프로젝트 마감",
"date": "2025-08-25",
"startTime": "09:00",
"endTime": "18:00",
"description": "분기별 프로젝트 마감",
"location": "사무실",
"category": "업무",
"repeat": { "type": "none", "interval": 0 },
"notificationTime": 1
},
{
"id": "dac62941-69e5-4ec0-98cc-24c2a79a7f81",
"title": "생일 파티",
"date": "2025-08-28",
"startTime": "19:00",
"endTime": "22:00",
"description": "친구 생일 축하",
"location": "친구 집",
"category": "개인",
"repeat": { "type": "none", "interval": 0 },
"notificationTime": 1
},
{
"id": "80d85368-b4a4-47b3-b959-25171d49371f",
"title": "운동",
"date": "2025-08-22",
"startTime": "18:00",
"endTime": "19:00",
"description": "주간 운동",
"location": "헬스장",
"category": "개인",
"repeat": { "type": "none", "interval": 0 },
"notificationTime": 1
}
]
}
{"events":[{"id":"09702fb3-a478-40b3-905e-9ab3c8849dcd","title":"점심 약속","date":"2025-08-21","startTime":"12:30","endTime":"13:30","description":"동료와 점심 식사","location":"회사 근처 식당","category":"개인","repeat":{"type":"none","interval":0},"notificationTime":1},{"id":"da3ca408-836a-4d98-b67a-ca389d07552b","title":"프로젝트 마감","date":"2025-08-25","startTime":"09:00","endTime":"18:00","description":"분기별 프로젝트 마감","location":"사무실","category":"업무","repeat":{"type":"none","interval":0},"notificationTime":1},{"id":"dac62941-69e5-4ec0-98cc-24c2a79a7f81","title":"생일 파티","date":"2025-08-28","startTime":"19:00","endTime":"22:00","description":"친구 생일 축하","location":"친구 집","category":"개인","repeat":{"type":"none","interval":0},"notificationTime":1},{"id":"80d85368-b4a4-47b3-b959-25171d49371f","title":"운동","date":"2025-08-22","startTime":"18:00","endTime":"19:00","description":"주간 운동","location":"헬스장","category":"개인","repeat":{"type":"none","interval":0},"notificationTime":1}]}
109 changes: 105 additions & 4 deletions src/__tests__/hooks/medium.useNotifications.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,111 @@ import { Event } from '../../types.ts';
import { formatDate } from '../../utils/dateUtils.ts';
import { parseHM } from '../utils.ts';

it('초기 상태에서는 알림이 없어야 한다', () => {});
// 각 테스트 전후에 타이머 완전히 리셋
beforeEach(() => {
vi.useRealTimers();
});

it('지정된 시간이 된 경우 알림이 새롭게 생성되어 추가된다', () => {});
afterEach(() => {
vi.useRealTimers();
});

it('index를 기준으로 알림을 적절하게 제거할 수 있다', () => {});
it('초기 상태에서는 알림이 없어야 한다', () => {
const { result } = renderHook(() => useNotifications([] as Event[]));
expect(result.current.notifications).toEqual([]);
expect(result.current.notifications.length).toBe(0);
expect(result.current.notifiedEvents).toEqual([]);
});

it('이미 알림이 발생한 이벤트에 대해서는 중복 알림이 발생하지 않아야 한다', () => {});
it('지정된 시간이 된 경우 알림이 새롭게 생성되어 추가된다', () => {
vi.useFakeTimers();
const fixedNow = new Date('2025-08-20T09:55:00');
vi.setSystemTime(fixedNow);

const events: Event[] = [
{
id: '1',
title: '회의',
date: formatDate(fixedNow),
startTime: parseHM(fixedNow.getTime() + 5 * 60 * 1000),
notificationTime: 5,
},
] as Event[];

const { result } = renderHook(() => useNotifications(events));
expect(result.current.notifications).toEqual([]);

act(() => {
vi.advanceTimersByTime(1000);
});

expect(result.current.notifications.length).toBe(1);
expect(result.current.notifications[0].message).toContain('5분');
expect(result.current.notifications[0].id).toEqual('1');
});

it('index를 기준으로 알림을 적절하게 제거할 수 있다', () => {
vi.useFakeTimers();
const fixedNow = new Date('2025-08-20T10:00:00');
vi.setSystemTime(fixedNow);

const events: Event[] = [
{
id: '1',
title: '테스트',
date: formatDate(fixedNow),
startTime: parseHM(fixedNow.getTime() + 5 * 60 * 1000),
notificationTime: 5,
},
] as Event[];

const { result } = renderHook(() => useNotifications(events));

expect(result.current.notifications).toEqual([]);

act(() => {
vi.advanceTimersByTime(1000);
});

expect(result.current.notifications.length).toBe(1);

act(() => {
result.current.removeNotification(0);
});

expect(result.current.notifications.length).toEqual(0);
});

it('이미 알림이 발생한 이벤트에 대해서는 중복 알림이 발생하지 않아야 한다', () => {
vi.useFakeTimers();
const fixedNow = new Date('2025-08-20T11:00:00');
vi.setSystemTime(fixedNow);

const events: Event[] = [
{
id: '1',
title: '중복 테스트',
date: formatDate(fixedNow),
startTime: parseHM(fixedNow.getTime() + 5 * 60 * 1000),
notificationTime: 5,
},
] as Event[];

const { result } = renderHook(() => useNotifications(events));

expect(result.current.notifications).toEqual([]);

act(() => {
vi.advanceTimersByTime(1000);
});

expect(result.current.notifications.length).toBe(1);
expect(result.current.notifiedEvents.length).toBe(1);

act(() => {
vi.advanceTimersByTime(2000);
});

expect(result.current.notifications.length).toBe(1);
expect(result.current.notifiedEvents.length).toBe(1);
});
Loading
Loading