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
75 changes: 75 additions & 0 deletions e2e/home.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { test, expect } from '@playwright/test';

test.describe('Homepage E2E Tests', () => {
test.beforeEach(async ({ page }) => {
// 모든 테스트 전에 홈페이지로 이동
await page.goto('/');
});

test('should load the homepage and display the correct title', async ({ page }) => {
// 페이지 타이틀 확인 (Next.js <head>의 <title> 태그 기준)
// 실제 프로젝트의 타이틀로 변경해야 함
await expect(page).toHaveTitle(/3D Blog/i); // 프로젝트 이름에 맞게 수정
});

test('should display a canvas for 3D content', async ({ page }) => {
// react-three-fiber Canvas는 <canvas> 태그를 렌더링함
// HomeCanvas.tsx 또는 유사한 컴포넌트가 <canvas>를 포함한다고 가정
const canvasElement = page.locator('canvas');
await expect(canvasElement).toBeVisible();
// 추가적으로 canvas의 특정 속성 (예: data-testid, class)으로 더 정확히 식별 가능
// 예: const mainCanvas = page.locator('canvas[data-testid="home-canvas"]');
});

test('should have a navigation bar with a "Blog" link and navigate to blog page', async ({ page }) => {
// src/shared/ui/Navbar.tsx의 menuItems 배열과 로그인 상태에 따른 버튼 텍스트 참고
// 데스크톱 네비게이션을 기준으로 테스트 (hidden md:block)
// 모바일 메뉴는 별도의 테스트 케이스나 헬퍼 필요 가능성
const blogLink = page.locator('header nav').getByRole('link', { name: 'Blog' });
await expect(blogLink).toBeVisible();

await blogLink.click();

// URL이 블로그 페이지로 변경되었는지 확인
await expect(page).toHaveURL(/.*\/blog/);
// 블로그 페이지의 특정 제목이나 요소가 로드되었는지 추가로 확인 가능
// 예: await expect(page.getByRole('heading', { name: /All Posts/i })).toBeVisible(); // 실제 블로그 페이지 제목으로 변경
});

test('should have a navigation bar with a "Portfolio" link and handle coming soon', async ({ page }) => {
// "Portfolio" 링크는 isComingSoon: true 이므로 클릭 시 alert가 떠야 함.
const portfolioLink = page.locator('header nav').getByRole('link', { name: 'Portfolio' });
await expect(portfolioLink).toBeVisible();

// alert를 처리하기 위한 핸들러 등록
let alertMessage = '';
page.on('dialog', async dialog => {
alertMessage = dialog.message();
await dialog.dismiss(); // 또는 dialog.accept()
});

await portfolioLink.click();

// Portfolio는 isComingSoon = true 이므로 페이지 이동은 일어나지 않음
await expect(page).toHaveURL('/'); // 현재 페이지 URL 유지 확인
// alert 메시지 확인
expect(alertMessage).toBe('서비스 준비 중입니다...');
});

// 추가: 로그인 페이지로 이동하는 링크/버튼 테스트 (옵션)
test('should navigate to login page from "Log In" link', async ({ page }) => {
// Navbar.tsx에 따르면 로그아웃 상태일 때 "Log In" 링크가 표시됨
const loginLink = page.locator('header').getByRole('link', { name: 'Log In' });
// E2E 테스트는 일반적으로 로그아웃된 상태에서 시작하므로 이 링크가 보여야 함
await expect(loginLink).toBeVisible();

await loginLink.click();
await expect(page).toHaveURL(/.*\/login/);
// 로그인 폼의 특정 요소가 보이는지 확인
await expect(page.getByRole('heading', { name: /로그인/i, level: 1 })).toBeVisible();
} else {
// 로그인 링크가 없다면 테스트 스킵 또는 다른 방식으로 처리
console.log('Login link not found on homepage, skipping navigation to login page test.');
}
});
});
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@eslint/eslintrc": "^3",
"@playwright/test": "^1.53.2",
"@react-three/test-renderer": "^9.0.1",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
Expand Down Expand Up @@ -108,13 +109,15 @@
"openapi-typescript": "^7.6.1",
"postcss": "^8",
"prisma": "^6.1.0",
"resize-observer-polyfill": "^1.5.1",
"tailwindcss": "^3.4.1",
"three-stdlib": "^2.36.0",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typedoc": "^0.27.6",
"typescript": "~5.3.3",
"vitest": "^3.1.4",
"vitest-canvas-mock": "^0.3.3",
"whatwg-fetch": "^3.6.20"
},
"msw": {
Expand Down
77 changes: 77 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { defineConfig, devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './e2e', // E2E 테스트 파일이 위치할 디렉토리 (또는 'tests/e2e')
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: 'http://localhost:3000', // Next.js 개발 서버 주소

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},

{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run dev',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});
Loading