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
4 changes: 3 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
"preview": "vite preview",
"test": "vitest"
},
"dependencies": {
"axios": "^1.9.0",
Expand Down Expand Up @@ -39,6 +40,8 @@
"tailwindcss": "^3.4.17",
"typescript": "~5.7.2",
"typescript-eslint": "^8.26.1",
"vite": "^6.3.5"
"vite": "^6.3.5",
"@testing-library/react": "^16.0.0",
"vitest": "^1.6.0"
}
}
55 changes: 55 additions & 0 deletions src/components/orders/__tests__/TableCard.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { render, screen } from '@testing-library/react';
import { describe, it, expect, vi } from 'vitest';
import TableCard from '../TableCard';

vi.mock('@/stores/booths/tableDetail', () => ({
useTableDetail: () => ({
getCustomTableNum: (num: number) => num,
}),
}));

vi.mock('@/stores/orders/tableVisualization', () => ({
useTableVisualizationDetail: () => ({
openTableVisualDetail: vi.fn(),
}),
}));

describe('TableCard', () => {
const base = { tableNumIndex: 1 };

it('renders ready table with correct label and style', () => {
const table = { ...base, type: 'ready', orderInfo: { totalPrice: 1000 } as any };
render(<TableCard table={table} />);
const status = screen.getByText('입금대기');
expect(status.className).toContain('text-danger-800');
const container = status.parentElement?.parentElement as HTMLElement;
expect(container.className).toContain('bg-danger-50');
});

it('renders cooking table with correct label and style', () => {
const table = { ...base, type: 'cooking', orderInfo: { totalPrice: 1000 } as any };
render(<TableCard table={table} />);
const status = screen.getByText('조리중');
expect(status.className).toContain('text-primary-800');
const container = status.parentElement?.parentElement as HTMLElement;
expect(container.className).toContain('bg-primary-300');
});

it('renders complete table with correct label and style', () => {
const table = { ...base, type: 'complete', orderInfo: { totalPrice: 1000 } as any };
render(<TableCard table={table} />);
const status = screen.getByText('조리완료');
expect(status.className).toContain('text-success-900');
const container = status.parentElement?.parentElement as HTMLElement;
expect(container.className).toContain('bg-success-50');
});

it('renders table with no order info', () => {
const table = { ...base, type: 'complete', orderInfo: null };
render(<TableCard table={table} />);
const status = screen.getByText('주문 건 없음');
expect(status.className).toContain('text-secondary-600');
const container = status.parentElement?.parentElement as HTMLElement;
expect(container.className).toContain('bg-gray-200');
});
});
15 changes: 15 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { defineConfig } from 'vitest/config';
import react from '@vitejs/plugin-react';
import path from 'node:path';

export default defineConfig({
plugins: [react()],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
test: {
environment: 'jsdom',
},
});