Skip to content

Commit

Permalink
fix: 주문 날짜 형식 변환
Browse files Browse the repository at this point in the history
  • Loading branch information
kichul7493 committed Oct 12, 2024
1 parent b25e5b8 commit 6a6b320
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
6 changes: 2 additions & 4 deletions src/app/order/_components/OrderCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import { render, screen } from '@testing-library/react'
import OrderCard from './OrderCard'
import { Order } from '@/features/order/types'

// Order 타입을 가져옵니다.

describe('OrderCard', () => {
const mockOrder: Order = {
storeId: 1,
orderId: 1,
storeName: 'Test Store',
orderTime: '2024-09-03',
orderStatus: 'delivered', // 'Delivered'로 정확히 지정합니다.
orderStatus: 'delivered',
menus: [
{ menuName: 'Item 1', menuCount: 2, menuPrice: 10000, optionGroups: [], menuId: 1 },
{ menuName: 'Item 2', menuCount: 1, menuPrice: 10000, optionGroups: [], menuId: 2 },
Expand All @@ -25,7 +23,7 @@ describe('OrderCard', () => {
expect(screen.getByText('Test Store')).toBeInTheDocument()

// 주문 날짜가 올바르게 표시되는지 확인합니다.
expect(screen.getByText('2024. 9. 3.')).toBeInTheDocument()
expect(screen.getByText(/2024\. 9\. 3\./i)).toBeInTheDocument()

// 배달 상태가 올바르게 표시되는지 확인합니다.
expect(screen.getByText('배달 완료')).toBeInTheDocument()
Expand Down
7 changes: 4 additions & 3 deletions src/app/order/_components/OrderCard.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
'use client'
import { Order } from '@/features/order/types'
import { formatDate } from '@/util/formatDate'
import Link from 'next/link'
import * as React from 'react'

export default function OrderCard({ order }: { order: Order }) {
const orderDate = new Date(order.orderTime)

return (
<div className="flex flex-col rounded-lg border p-4">
<h3 className="text-2xl font-bold">{order.storeName}</h3>
<span className="text-xs text-gray-500">
{new Date(order.orderTime).toLocaleDateString()}
</span>
<span className="text-xs text-gray-500">{formatDate(orderDate)}</span>
<div className="mb-2 text-gray-600">
{order.orderStatus === 'delivered' ? '배달 완료' : '배달 중'}
</div>
Expand Down
7 changes: 7 additions & 0 deletions src/util/formatDate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const formatDate = (date: Date) => {
const year = date.getFullYear()
const month = date.getMonth() + 1 // 월은 0부터 시작하므로 1을 더해야 함
const day = date.getDate()

return `${year}. ${month}. ${day}.`
}

0 comments on commit 6a6b320

Please sign in to comment.