Skip to content

Commit

Permalink
refactor: utils 함수 테스트 케이스의 이름을 명확하게 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
agaxe committed Oct 1, 2024
1 parent 4bfa77b commit 1d7dd6a
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 31 deletions.
7 changes: 3 additions & 4 deletions utils/__test__/convertPascalCase.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { describe, expect, it } from '@jest/globals';
import { convertPascalCase } from '../convertPascalCase';

describe('convertPascalCase', () => {
it('lower case', () => {
describe('utils/convertPascalCase', () => {
it('lower case 텍스트를 pascal case 로 변환시킨다.', () => {
expect(convertPascalCase('example text')).toBe('Example Text');
});

it('upper case', () => {
it('upper case 텍스트를 pascal case 로 변환시킨다.', () => {
expect(convertPascalCase('EXAMPLE TEXT')).toBe('Example Text');
});
});
5 changes: 2 additions & 3 deletions utils/__test__/convertUuidToPostId.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { describe, expect, it } from '@jest/globals';
import { convertUuidToPostId } from '../convertUuidToPostId';

describe('convertUuidToPostId', () => {
it('default', () => {
describe('utils/convertUuidToPostId', () => {
it('UUID 를 받으면 하이픈(-) 을 제거한다.', () => {
const uuid = '84fd1842-99ac-454f-b917-730b587ddbdd';

expect(convertUuidToPostId(uuid)).toBe('84fd184299ac454fb917730b587ddbdd');
Expand Down
15 changes: 7 additions & 8 deletions utils/__test__/formatDate.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import { describe, expect, it } from '@jest/globals';
import { formatDate } from '../formatDate';

describe('formatDate', () => {
it('date type', () => {
describe('utils/formatDate', () => {
it('Date 타입을 특정 format 의 날짜로 변환시킨다.', () => {
const date = new Date('1995-10-05');

expect(formatDate(date)).toBe('1995년 10월 5일');
expect(formatDate(date, 'yyyy년 M월 d일')).toBe('1995년 10월 5일');
});

it('timestamp type', () => {
it('timestamp 를 특정 format 의 날짜로 변환시킨다.', () => {
const date = new Date('1995-10-05').getTime();

expect(formatDate(date)).toBe('1995년 10월 5일');
expect(formatDate(date, 'yyyy년 M월 d일')).toBe('1995년 10월 5일');
});

it('ISO type', () => {
it('ISO 형식을 특정 format 의 날짜로 변환시킨다.', () => {
const iso = new Date('1995-08-25').toISOString();

expect(formatDate(iso)).toBe('1995년 8월 25일');
expect(formatDate(iso, 'yyyy년 M월 d일')).toBe('1995년 8월 25일');
});
});
13 changes: 6 additions & 7 deletions utils/__test__/getPaginationItems.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { beforeAll, describe, expect, it, jest } from '@jest/globals';
import mockItems from '@/mocks/parsePageItems';
import { getPaginationItems } from '../getPaginationItems';

jest.mock('@/shared/variable', () => ({
pageSize: 3
pageSize: 3 // 페이지 최대 아이템 개수
}));

describe('getPaginationItems', () => {
describe('utils/getPaginationItems', () => {
let getPaginationItemsFn: typeof getPaginationItems;

beforeAll(async () => {
Expand All @@ -15,27 +14,27 @@ describe('getPaginationItems', () => {
);
});

it('아이템 갯수', () => {
it('현재 페이지가 1페이지면 아이템이 총 3개 반환된다.', () => {
const items = getPaginationItemsFn(mockItems, 1);

expect(items.length).toBe(3);
});

it('1 페이지', () => {
it('현재 페이지가 1페이지인 경우, 1~3번째의 아이템이 반환된다.', () => {
const items = getPaginationItemsFn(mockItems, 1);

expect(items[0].title).toBe('포스트 제목_1');
expect(items.at(-1)?.title).toBe('포스트 제목_3');
});

it('2 페이지', () => {
it('현재 페이지가 2페이지인 경우, 4~6번째의 아이템이 반환된다.', () => {
const items = getPaginationItemsFn(mockItems, 2);

expect(items[0].title).toBe('포스트 제목_4');
expect(items.at(-1)?.title).toBe('포스트 제목_6');
});

it('마지막 페이지', () => {
it('마지막 페이지인 경우 나머지 아이템이 반환된다.', () => {
const pageLength = Math.ceil(mockItems.length / 3);
const items = getPaginationItemsFn(mockItems, pageLength);

Expand Down
9 changes: 4 additions & 5 deletions utils/__test__/getPaginationLength.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { beforeAll, describe, expect, it, jest } from '@jest/globals';
import mockPageItems from '@/mocks/parsePageItems';
import { getPaginationLength } from '../getPaginationLength';

jest.mock('@/shared/variable', () => ({
pageSize: 3
pageSize: 3 // 페이지 최대 아이템 개수
}));

describe('getPaginationLength', () => {
describe('utils/getPaginationLength', () => {
let getPaginationLengthFn: typeof getPaginationLength;

beforeAll(async () => {
Expand All @@ -15,13 +14,13 @@ describe('getPaginationLength', () => {
);
});

it('총 페이지 수 (아이템 10개, 3개씩)', () => {
it('아이템의 개수가 10개면 페이지는 4페이지 존재한다.', () => {
const pageLength = getPaginationLengthFn(mockPageItems);

expect(pageLength).toBe(4);
});

it('총 페이지 수 (아이템 5개, 3개씩)', () => {
it('아이템의 개수가 5개면 페이지는 2페이지 존재한다.', () => {
const items = mockPageItems.filter((_, i) => i > 5);
const pageLength = getPaginationLengthFn(items);

Expand Down
37 changes: 33 additions & 4 deletions utils/__test__/parseDatabaseItems.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,52 @@
import { describe, expect, it } from '@jest/globals';
import mockItems from '@/mocks/notionPageItems';
import { parseDatabaseItems } from '../parseDatabaseItems';

describe('parseDatabaseItems', () => {
it('포스팅 수', () => {
describe('utils/parseDatabaseItems', () => {
it('아이템 수를 받은 만큼 반환한다.', () => {
const items = parseDatabaseItems(mockItems);

expect(items.length).toBe(10);
});

it('포스팅 아이템', () => {
it(`반환된 리스트의 아이템에 'koId' 값이 존재한다.`, () => {
const items = parseDatabaseItems(mockItems);
const item = items[0];

expect(item.hasOwnProperty('koId')).toBe(true);
});

it(`반환된 리스트의 아이템에 'id'(포스트 아이디) 값이 존재한다.`, () => {
const items = parseDatabaseItems(mockItems);
const item = items[0];

expect(item.hasOwnProperty('id')).toBe(true);
});

it(`반환된 리스트의 아이템에 'title'(포스트 제목) 값이 존재한다.`, () => {
const items = parseDatabaseItems(mockItems);
const item = items[0];

expect(item.title).toBe('포스트 제목_1');
});

it(`반환된 리스트의 아이템에 'tags'(포스트 태그 리스트) 값이 존재한다.`, () => {
const items = parseDatabaseItems(mockItems);
const item = items[0];

expect(item.hasOwnProperty('tags')).toBe(true);
});

it(`반환된 리스트의 아이템에 'createdAt'(포스트 작성일) 값이 존재한다.`, () => {
const items = parseDatabaseItems(mockItems);
const item = items[0];

expect(item.createdAt).toBe('2024-04-29T11:33:00.000Z');
});

it(`반환된 리스트의 아이템에 'isCompleted'(작성 완료 여부) 값이 존재한다.`, () => {
const items = parseDatabaseItems(mockItems);
const item = items[0];

expect(item.hasOwnProperty('isCompleted')).toBe(true);
});
});

0 comments on commit 1d7dd6a

Please sign in to comment.