Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX : 클라이언트 페스를 상수로 관리 #13

Merged
Merged
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
10 changes: 10 additions & 0 deletions client/src/__test__/post/createPostDetailPath.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {POST_DETAIL} from "@/const/clientPath";

describe("createPostDetailPath 함수 테스트", () => {
it("postId=1 userId=thisUser 가 입력되었을 때 ", () => {
expect(POST_DETAIL("thisUser", "1")).toEqual("/post/@thisUser/1");
});
it("공백을 자동으로 Trim 하는지 여부", () => {
expect(POST_DETAIL(" thisUser", "1 ")).toEqual("/post/@thisUser/1");
});
});
jobkaeHenry marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 3 additions & 2 deletions client/src/components/post/PostCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";
import { POST_DETAIL } from "@/const/clientPath";
import { PostInterface } from "@/types/post/PostInterface";
import createPostDetailPath from "@/utils/createPostDetailPath";

import { MoreVertOutlined } from "@mui/icons-material";
import {
Avatar,
Expand All @@ -25,7 +26,7 @@ const PostCard = ({
id,
}: PostInterface) => {
return (
<Link href={createPostDetailPath(userId, id)}>
<Link href={`${POST_DETAIL(userId, id)}`}>
<Card sx={{ display: "flex", gap: 2, p: 2 }}>
<Avatar
sx={{ bgcolor: "secondary.main" }}
jobkaeHenry marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
14 changes: 14 additions & 0 deletions client/src/const/clientPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,18 @@ export const MY_PROFILE = "/user" as const
*/
export const WIKI = "/wiki" as const

/**
* 유저아이디와 게시글 아이디를 입력받아 /post/@userId/postId 형태의 path를 리턴
* @param userId 유저ID
* @param postId 게시글ID
* @returns
*/
export const POST_DETAIL = (userId: string, postId: string) => {
const trimmedUserId = userId.trim();
const trimmedPostId = postId.trim();

return `/post/@${trimmedUserId}/${trimmedPostId}`;
};


export default HOME;
jobkaeHenry marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 0 additions & 10 deletions client/src/utils/createPostDetailPath.test.ts

This file was deleted.

14 changes: 0 additions & 14 deletions client/src/utils/createPostDetailPath.ts

This file was deleted.