initial project
هذا الالتزام موجود في:
24
.gitignore
مباع
Normal file
24
.gitignore
مباع
Normal file
@@ -0,0 +1,24 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
0
.history/src/App_20251001202451.tsx
Normal file
0
.history/src/App_20251001202451.tsx
Normal file
599
.history/src/App_20251001202454.tsx
Normal file
599
.history/src/App_20251001202454.tsx
Normal file
@@ -0,0 +1,599 @@
|
||||
import React, { useState, useMemo } from 'react';
|
||||
import { ChevronDown, ChevronRight, CheckCircle, XCircle, AlertCircle, Code, FileText } from 'lucide-react';
|
||||
|
||||
// ============================================================================
|
||||
// TYPES & INTERFACES - Centralized type definitions for type safety
|
||||
// ============================================================================
|
||||
|
||||
// Main data structure interface matching backend JSON
|
||||
interface APITestData {
|
||||
url: string;
|
||||
api: APIEndpoint[];
|
||||
}
|
||||
|
||||
interface APIEndpoint {
|
||||
title: string;
|
||||
method: string;
|
||||
endpoint: string;
|
||||
description: string;
|
||||
urlParams: Parameter[];
|
||||
query: Parameter[];
|
||||
headers: Header[];
|
||||
body: BodySchema;
|
||||
testCases: TestCase[];
|
||||
}
|
||||
|
||||
interface Parameter {
|
||||
name: string;
|
||||
type: string;
|
||||
example: any;
|
||||
required: boolean;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
interface Header {
|
||||
name: string;
|
||||
type: string;
|
||||
example: string;
|
||||
required: boolean;
|
||||
}
|
||||
|
||||
interface BodySchema {
|
||||
required: boolean;
|
||||
fields: any[];
|
||||
}
|
||||
|
||||
interface TestCase {
|
||||
id: number;
|
||||
title: string;
|
||||
input: TestInput;
|
||||
expectedResponse: Response;
|
||||
actualResponse: Response;
|
||||
status: 'passed' | 'failed';
|
||||
}
|
||||
|
||||
interface TestInput {
|
||||
urlParams: Record<string, any>;
|
||||
query: Record<string, any>;
|
||||
headers: Record<string, any>;
|
||||
body: Record<string, any>;
|
||||
}
|
||||
|
||||
interface Response {
|
||||
statusCode: number;
|
||||
body: Record<string, any>;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// MOCK DATA - Replace with props from backend
|
||||
// ============================================================================
|
||||
|
||||
const mockData: APITestData = {
|
||||
"url": "https://jsonplaceholder.typicode.com",
|
||||
"api": [
|
||||
{
|
||||
"title": "Get User Details",
|
||||
"method": "GET",
|
||||
"endpoint": "/users/{userId}",
|
||||
"description": "Fetch user details by ID",
|
||||
"urlParams": [
|
||||
{
|
||||
"name": "userId",
|
||||
"type": "integer",
|
||||
"example": 123,
|
||||
"required": true,
|
||||
"description": "Unique identifier of the user"
|
||||
}
|
||||
],
|
||||
"query": [
|
||||
{
|
||||
"name": "includePosts",
|
||||
"type": "boolean",
|
||||
"example": true,
|
||||
"required": false,
|
||||
"description": "Whether to include user posts"
|
||||
}
|
||||
],
|
||||
"headers": [
|
||||
{
|
||||
"name": "Authorization",
|
||||
"type": "string",
|
||||
"example": "Bearer <token>",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"required": false,
|
||||
"fields": []
|
||||
},
|
||||
"testCases": [
|
||||
{
|
||||
"id": 1,
|
||||
"title": "Valid userId with includePosts=true",
|
||||
"input": {
|
||||
"urlParams": {
|
||||
"userId": 123
|
||||
},
|
||||
"query": {
|
||||
"includePosts": true
|
||||
},
|
||||
"headers": {
|
||||
"Authorization": "Bearer valid_token"
|
||||
},
|
||||
"body": {}
|
||||
},
|
||||
"expectedResponse": {
|
||||
"statusCode": 200,
|
||||
"body": {
|
||||
"id": 123,
|
||||
"name": "John Doe",
|
||||
"posts": []
|
||||
}
|
||||
},
|
||||
"actualResponse": {
|
||||
"statusCode": 200,
|
||||
"body": {
|
||||
"id": 123,
|
||||
"name": "John Doe",
|
||||
"posts": []
|
||||
}
|
||||
},
|
||||
"status": "passed"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"title": "Invalid userId",
|
||||
"input": {
|
||||
"urlParams": {
|
||||
"userId": 9999
|
||||
},
|
||||
"query": {
|
||||
"includePosts": false
|
||||
},
|
||||
"headers": {
|
||||
"Authorization": "Bearer valid_token"
|
||||
},
|
||||
"body": {}
|
||||
},
|
||||
"expectedResponse": {
|
||||
"statusCode": 404,
|
||||
"body": {
|
||||
"error": "User not found"
|
||||
}
|
||||
},
|
||||
"actualResponse": {
|
||||
"statusCode": 404,
|
||||
"body": {
|
||||
"error": "User not found"
|
||||
}
|
||||
},
|
||||
"status": "passed"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"title": "Missing authorization header",
|
||||
"input": {
|
||||
"urlParams": {
|
||||
"userId": 123
|
||||
},
|
||||
"query": {
|
||||
"includePosts": true
|
||||
},
|
||||
"headers": {},
|
||||
"body": {}
|
||||
},
|
||||
"expectedResponse": {
|
||||
"statusCode": 401,
|
||||
"body": {
|
||||
"error": "Unauthorized"
|
||||
}
|
||||
},
|
||||
"actualResponse": {
|
||||
"statusCode": 403,
|
||||
"body": {
|
||||
"error": "Forbidden"
|
||||
}
|
||||
},
|
||||
"status": "failed"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// UTILITY FUNCTIONS - Pure helper functions
|
||||
// ============================================================================
|
||||
|
||||
// Calculate test statistics for an API endpoint
|
||||
const calculateStats = (testCases: TestCase[]) => {
|
||||
const total = testCases.length;
|
||||
const passed = testCases.filter(tc => tc.status === 'passed').length;
|
||||
const failed = testCases.filter(tc => tc.status === 'failed').length;
|
||||
const passRate = total > 0 ? ((passed / total) * 100).toFixed(1) : '0';
|
||||
|
||||
return { total, passed, failed, passRate };
|
||||
};
|
||||
|
||||
// Get HTTP method badge color
|
||||
const getMethodColor = (method: string) => {
|
||||
const colors: Record<string, string> = {
|
||||
GET: 'bg-green-600',
|
||||
POST: 'bg-blue-600',
|
||||
PUT: 'bg-yellow-600',
|
||||
PATCH: 'bg-orange-600',
|
||||
DELETE: 'bg-red-600'
|
||||
};
|
||||
return colors[method.toUpperCase()] || 'bg-gray-600';
|
||||
};
|
||||
|
||||
// Format JSON with proper indentation
|
||||
const formatJSON = (obj: any) => JSON.stringify(obj, null, 2);
|
||||
|
||||
// ============================================================================
|
||||
// COMPONENT: JsonViewer - Displays formatted JSON with syntax highlighting
|
||||
// ============================================================================
|
||||
|
||||
const JsonViewer: React.FC<{ data: any; title: string }> = ({ data, title }) => {
|
||||
return (
|
||||
<div className="flex-1">
|
||||
<div className="text-xs font-semibold text-gray-400 mb-2">{title}</div>
|
||||
<pre className="bg-gray-900 rounded-lg p-4 overflow-x-auto text-xs">
|
||||
<code className="text-gray-300">{formatJSON(data)}</code>
|
||||
</pre>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// COMPONENT: StatusBadge - Visual indicator for test status
|
||||
// ============================================================================
|
||||
|
||||
const StatusBadge: React.FC<{ status: 'passed' | 'failed' }> = ({ status }) => {
|
||||
const isPassed = status === 'passed';
|
||||
|
||||
return (
|
||||
<span className={`inline-flex items-center gap-1 px-3 py-1 rounded-full text-xs font-semibold ${
|
||||
isPassed ? 'bg-green-600/20 text-green-400' : 'bg-red-600/20 text-red-400'
|
||||
}`}>
|
||||
{isPassed ? <CheckCircle size={14} /> : <XCircle size={14} />}
|
||||
{status.toUpperCase()}
|
||||
</span>
|
||||
);
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// COMPONENT: ParameterTable - Displays API parameters in table format
|
||||
// ============================================================================
|
||||
|
||||
const ParameterTable: React.FC<{
|
||||
params: Parameter[] | Header[];
|
||||
title: string;
|
||||
icon: React.ReactNode;
|
||||
}> = ({ params, title, icon }) => {
|
||||
if (params.length === 0) return null;
|
||||
|
||||
return (
|
||||
<div className="mb-4">
|
||||
<div className="flex items-center gap-2 mb-3">
|
||||
{icon}
|
||||
<h4 className="text-sm font-semibold text-gray-300">{title}</h4>
|
||||
</div>
|
||||
<div className="bg-gray-800/50 rounded-lg overflow-hidden">
|
||||
<table className="w-full text-xs">
|
||||
<thead className="bg-gray-700/50">
|
||||
<tr>
|
||||
<th className="text-left p-3 text-gray-400 font-semibold">Name</th>
|
||||
<th className="text-left p-3 text-gray-400 font-semibold">Type</th>
|
||||
<th className="text-left p-3 text-gray-400 font-semibold">Required</th>
|
||||
<th className="text-left p-3 text-gray-400 font-semibold">Example</th>
|
||||
{'description' in params[0] && (
|
||||
<th className="text-left p-3 text-gray-400 font-semibold">Description</th>
|
||||
)}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{params.map((param, idx) => (
|
||||
<tr key={idx} className="border-t border-gray-700/50">
|
||||
<td className="p-3 text-gray-300 font-mono">{param.name}</td>
|
||||
<td className="p-3 text-blue-400 font-mono">{param.type}</td>
|
||||
<td className="p-3">
|
||||
<span className={`px-2 py-1 rounded text-xs ${
|
||||
param.required ? 'bg-red-600/20 text-red-400' : 'bg-gray-600/20 text-gray-400'
|
||||
}`}>
|
||||
{param.required ? 'Yes' : 'No'}
|
||||
</span>
|
||||
</td>
|
||||
<td className="p-3 text-gray-400 font-mono">{String(param.example)}</td>
|
||||
{'description' in param && (
|
||||
<td className="p-3 text-gray-400">{param.description}</td>
|
||||
)}
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// COMPONENT: TestCaseCard - Individual test case with expand/collapse
|
||||
// ============================================================================
|
||||
|
||||
const TestCaseCard: React.FC<{ testCase: TestCase }> = ({ testCase }) => {
|
||||
const [isExpanded, setIsExpanded] = useState(false);
|
||||
const isPassed = testCase.status === 'passed';
|
||||
|
||||
// Compare expected vs actual to highlight differences
|
||||
const statusCodeMatch = testCase.expectedResponse.statusCode === testCase.actualResponse.statusCode;
|
||||
|
||||
return (
|
||||
<div className={`bg-gray-800 rounded-lg border-2 ${
|
||||
isPassed ? 'border-green-600/30' : 'border-red-600/30'
|
||||
} overflow-hidden transition-all duration-200 hover:shadow-lg`}>
|
||||
{/* Test case header - Always visible */}
|
||||
<div
|
||||
className="p-4 cursor-pointer flex items-center justify-between"
|
||||
onClick={() => setIsExpanded(!isExpanded)}
|
||||
>
|
||||
<div className="flex items-center gap-3 flex-1">
|
||||
{isExpanded ? <ChevronDown size={20} /> : <ChevronRight size={20} />}
|
||||
<div className="flex-1">
|
||||
<div className="flex items-center gap-3 mb-1">
|
||||
<h4 className="text-sm font-semibold text-gray-200">{testCase.title}</h4>
|
||||
<StatusBadge status={testCase.status} />
|
||||
</div>
|
||||
<div className="text-xs text-gray-500">Test Case #{testCase.id}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Status code comparison */}
|
||||
<div className="flex items-center gap-4 mr-4">
|
||||
<div className="text-right">
|
||||
<div className="text-xs text-gray-500">Expected</div>
|
||||
<div className={`text-sm font-mono font-bold ${statusCodeMatch ? 'text-green-400' : 'text-yellow-400'}`}>
|
||||
{testCase.expectedResponse.statusCode}
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-gray-600">→</div>
|
||||
<div className="text-right">
|
||||
<div className="text-xs text-gray-500">Actual</div>
|
||||
<div className={`text-sm font-mono font-bold ${statusCodeMatch ? 'text-green-400' : 'text-red-400'}`}>
|
||||
{testCase.actualResponse.statusCode}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Expanded details */}
|
||||
{isExpanded && (
|
||||
<div className="border-t border-gray-700 p-4 space-y-4">
|
||||
{/* Test Input Section */}
|
||||
<div>
|
||||
<h5 className="text-sm font-semibold text-gray-300 mb-3 flex items-center gap-2">
|
||||
<Code size={16} />
|
||||
Test Input
|
||||
</h5>
|
||||
<div className="grid grid-cols-2 gap-4 mb-4">
|
||||
{Object.keys(testCase.input.urlParams).length > 0 && (
|
||||
<div className="bg-gray-900/50 rounded p-3">
|
||||
<div className="text-xs font-semibold text-gray-400 mb-2">URL Parameters</div>
|
||||
<pre className="text-xs text-gray-300 font-mono">
|
||||
{formatJSON(testCase.input.urlParams)}
|
||||
</pre>
|
||||
</div>
|
||||
)}
|
||||
{Object.keys(testCase.input.query).length > 0 && (
|
||||
<div className="bg-gray-900/50 rounded p-3">
|
||||
<div className="text-xs font-semibold text-gray-400 mb-2">Query Parameters</div>
|
||||
<pre className="text-xs text-gray-300 font-mono">
|
||||
{formatJSON(testCase.input.query)}
|
||||
</pre>
|
||||
</div>
|
||||
)}
|
||||
{Object.keys(testCase.input.headers).length > 0 && (
|
||||
<div className="bg-gray-900/50 rounded p-3">
|
||||
<div className="text-xs font-semibold text-gray-400 mb-2">Headers</div>
|
||||
<pre className="text-xs text-gray-300 font-mono">
|
||||
{formatJSON(testCase.input.headers)}
|
||||
</pre>
|
||||
</div>
|
||||
)}
|
||||
{Object.keys(testCase.input.body).length > 0 && (
|
||||
<div className="bg-gray-900/50 rounded p-3">
|
||||
<div className="text-xs font-semibold text-gray-400 mb-2">Body</div>
|
||||
<pre className="text-xs text-gray-300 font-mono">
|
||||
{formatJSON(testCase.input.body)}
|
||||
</pre>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Response Comparison - Side by Side */}
|
||||
<div>
|
||||
<h5 className="text-sm font-semibold text-gray-300 mb-3 flex items-center gap-2">
|
||||
<FileText size={16} />
|
||||
Response Comparison
|
||||
</h5>
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<JsonViewer
|
||||
data={testCase.expectedResponse.body}
|
||||
title="Expected Response Body"
|
||||
/>
|
||||
<JsonViewer
|
||||
data={testCase.actualResponse.body}
|
||||
title="Actual Response Body"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// COMPONENT: APIEndpointCard - Main API endpoint display with test cases
|
||||
// ============================================================================
|
||||
|
||||
const APIEndpointCard: React.FC<{ api: APIEndpoint }> = ({ api }) => {
|
||||
const [isExpanded, setIsExpanded] = useState(true);
|
||||
const stats = useMemo(() => calculateStats(api.testCases), [api.testCases]);
|
||||
|
||||
return (
|
||||
<div className="bg-gray-800/50 rounded-xl border border-gray-700 overflow-hidden">
|
||||
{/* API Header */}
|
||||
<div
|
||||
className="p-6 cursor-pointer hover:bg-gray-800/70 transition-colors"
|
||||
onClick={() => setIsExpanded(!isExpanded)}
|
||||
>
|
||||
<div className="flex items-start justify-between">
|
||||
<div className="flex items-start gap-4 flex-1">
|
||||
{isExpanded ? <ChevronDown size={24} /> : <ChevronRight size={24} />}
|
||||
<div className="flex-1">
|
||||
<div className="flex items-center gap-3 mb-2">
|
||||
<span className={`${getMethodColor(api.method)} text-white text-xs font-bold px-3 py-1 rounded`}>
|
||||
{api.method}
|
||||
</span>
|
||||
<h3 className="text-lg font-bold text-gray-100">{api.title}</h3>
|
||||
</div>
|
||||
<code className="text-sm text-blue-400 bg-gray-900/50 px-3 py-1 rounded font-mono">
|
||||
{api.endpoint}
|
||||
</code>
|
||||
<p className="text-sm text-gray-400 mt-2">{api.description}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Statistics */}
|
||||
<div className="flex items-center gap-6 ml-6">
|
||||
<div className="text-center">
|
||||
<div className="text-2xl font-bold text-gray-200">{stats.total}</div>
|
||||
<div className="text-xs text-gray-500">Total Tests</div>
|
||||
</div>
|
||||
<div className="text-center">
|
||||
<div className="text-2xl font-bold text-green-400">{stats.passed}</div>
|
||||
<div className="text-xs text-gray-500">Passed</div>
|
||||
</div>
|
||||
<div className="text-center">
|
||||
<div className="text-2xl font-bold text-red-400">{stats.failed}</div>
|
||||
<div className="text-xs text-gray-500">Failed</div>
|
||||
</div>
|
||||
<div className="text-center">
|
||||
<div className="text-2xl font-bold text-blue-400">{stats.passRate}%</div>
|
||||
<div className="text-xs text-gray-500">Pass Rate</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Expanded Content */}
|
||||
{isExpanded && (
|
||||
<div className="border-t border-gray-700 p-6 space-y-6">
|
||||
{/* API Schema Information */}
|
||||
<div className="space-y-4">
|
||||
<ParameterTable
|
||||
params={api.urlParams}
|
||||
title="URL Parameters"
|
||||
icon={<Code size={16} className="text-blue-400" />}
|
||||
/>
|
||||
<ParameterTable
|
||||
params={api.query}
|
||||
title="Query Parameters"
|
||||
icon={<AlertCircle size={16} className="text-yellow-400" />}
|
||||
/>
|
||||
<ParameterTable
|
||||
params={api.headers}
|
||||
title="Headers"
|
||||
icon={<FileText size={16} className="text-green-400" />}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Test Cases */}
|
||||
<div>
|
||||
<h4 className="text-lg font-semibold text-gray-200 mb-4">Test Cases</h4>
|
||||
<div className="space-y-3">
|
||||
{api.testCases.map(testCase => (
|
||||
<TestCaseCard key={testCase.id} testCase={testCase} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// MAIN COMPONENT: Dashboard - Root component with state management
|
||||
// ============================================================================
|
||||
|
||||
const APITestDashboard: React.FC = () => {
|
||||
// State management - In production, this would come from props or context
|
||||
const [data] = useState<APITestData>(mockData);
|
||||
|
||||
// Calculate overall statistics using memoization for performance
|
||||
const overallStats = useMemo(() => {
|
||||
const allTestCases = data.api.flatMap(api => api.testCases);
|
||||
return calculateStats(allTestCases);
|
||||
}, [data.api]);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gradient-to-br from-gray-900 via-gray-800 to-gray-900 text-gray-100 p-8">
|
||||
<div className="max-w-7xl mx-auto">
|
||||
{/* Dashboard Header */}
|
||||
<div className="mb-8">
|
||||
<h1 className="text-4xl font-bold mb-2 bg-gradient-to-r from-blue-400 to-purple-400 bg-clip-text text-transparent">
|
||||
API Test Results Dashboard
|
||||
</h1>
|
||||
<p className="text-gray-400">Base URL: <code className="text-blue-400 bg-gray-800 px-2 py-1 rounded">{data.url}</code></p>
|
||||
</div>
|
||||
|
||||
{/* Overall Statistics Card */}
|
||||
<div className="bg-gradient-to-r from-gray-800 to-gray-700 rounded-xl p-6 mb-8 border border-gray-600 shadow-xl">
|
||||
<h2 className="text-xl font-semibold mb-4 text-gray-200">Overall Statistics</h2>
|
||||
<div className="grid grid-cols-4 gap-6">
|
||||
<div className="bg-gray-900/50 rounded-lg p-4 text-center">
|
||||
<div className="text-3xl font-bold text-blue-400 mb-1">{data.api.length}</div>
|
||||
<div className="text-sm text-gray-400">API Endpoints</div>
|
||||
</div>
|
||||
<div className="bg-gray-900/50 rounded-lg p-4 text-center">
|
||||
<div className="text-3xl font-bold text-gray-200 mb-1">{overallStats.total}</div>
|
||||
<div className="text-sm text-gray-400">Total Tests</div>
|
||||
</div>
|
||||
<div className="bg-gray-900/50 rounded-lg p-4 text-center">
|
||||
<div className="text-3xl font-bold text-green-400 mb-1">{overallStats.passed}</div>
|
||||
<div className="text-sm text-gray-400">Passed Tests</div>
|
||||
</div>
|
||||
<div className="bg-gray-900/50 rounded-lg p-4 text-center">
|
||||
<div className="text-3xl font-bold text-red-400 mb-1">{overallStats.failed}</div>
|
||||
<div className="text-sm text-gray-400">Failed Tests</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-4 bg-gray-900/50 rounded-lg p-4">
|
||||
<div className="flex items-center justify-between mb-2">
|
||||
<span className="text-sm text-gray-400">Overall Pass Rate</span>
|
||||
<span className="text-lg font-bold text-blue-400">{overallStats.passRate}%</span>
|
||||
</div>
|
||||
<div className="w-full bg-gray-700 rounded-full h-3 overflow-hidden">
|
||||
<div
|
||||
className="bg-gradient-to-r from-green-500 to-green-400 h-full rounded-full transition-all duration-500"
|
||||
style={{ width: `${overallStats.passRate}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* API Endpoints List */}
|
||||
<div className="space-y-6">
|
||||
{data.api.map((api, idx) => (
|
||||
<APIEndpointCard key={idx} api={api} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default APITestDashboard;
|
0
.history/src/index_20251001222257.css
Normal file
0
.history/src/index_20251001222257.css
Normal file
10
.history/src/index_20251001222259.css
Normal file
10
.history/src/index_20251001222259.css
Normal file
@@ -0,0 +1,10 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
html, body {
|
||||
@apply bg-gray-900 text-gray-100;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-family: 'Inter', sans-serif;
|
||||
}
|
18
.history/src/index_20251001222833.css
Normal file
18
.history/src/index_20251001222833.css
Normal file
@@ -0,0 +1,18 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
15
.history/src/index_20251001223549.css
Normal file
15
.history/src/index_20251001223549.css
Normal file
@@ -0,0 +1,15 @@
|
||||
@import "tailwindcss";
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
15
.history/src/index_20251001223742.css
Normal file
15
.history/src/index_20251001223742.css
Normal file
@@ -0,0 +1,15 @@
|
||||
@import "tailwindcss";
|
||||
/* * {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
} */
|
10
.history/src/main_20251001195155.tsx
Normal file
10
.history/src/main_20251001195155.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import './index.css'
|
||||
import App from './App.tsx'
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
)
|
10
.history/src/main_20251001202602.tsx
Normal file
10
.history/src/main_20251001202602.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import './index.css'
|
||||
import App from './app.tsx'
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
)
|
10
.history/src/main_20251001202642.tsx
Normal file
10
.history/src/main_20251001202642.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import './index.css'
|
||||
import App from '/app.tsx'
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
)
|
10
.history/src/main_20251001202646.tsx
Normal file
10
.history/src/main_20251001202646.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import './index.css'
|
||||
import App from './app.tsx'
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
)
|
10
.history/src/main_20251001202709.tsx
Normal file
10
.history/src/main_20251001202709.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import './index.css'
|
||||
import App from './App.tsx'
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
)
|
10
.history/src/main_20251001222352.tsx
Normal file
10
.history/src/main_20251001222352.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import React from "react";
|
||||
import ReactDOM from "react-dom/client";
|
||||
import App from "./App";
|
||||
import "./index.css";
|
||||
|
||||
ReactDOM.createRoot(document.getElementById("root")!).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
);
|
10
.history/src/main_20251001222809.tsx
Normal file
10
.history/src/main_20251001222809.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import App from './App.tsx'
|
||||
import './index.css'
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>,
|
||||
)
|
10
.history/src/main_20251001222811.tsx
Normal file
10
.history/src/main_20251001222811.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import App from './App.tsx'
|
||||
import './index.css'
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>,
|
||||
)
|
10
.history/src/main_20251001222813.tsx
Normal file
10
.history/src/main_20251001222813.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import App from './App.tsx'
|
||||
import './index.css'
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>,
|
||||
)
|
10
.history/src/main_20251001222814.tsx
Normal file
10
.history/src/main_20251001222814.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import React from "react";
|
||||
import ReactDOM from "react-dom/client";
|
||||
import App from "./App";
|
||||
import "./index.css";
|
||||
|
||||
ReactDOM.createRoot(document.getElementById("root")!).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
);
|
10
.history/src/main_20251001222816.tsx
Normal file
10
.history/src/main_20251001222816.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import App from './App.tsx'
|
||||
import './index.css'
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>,
|
||||
)
|
0
.history/vit_20251001223456
Normal file
0
.history/vit_20251001223456
Normal file
1
.history/vit_20251001223501
Normal file
1
.history/vit_20251001223501
Normal file
@@ -0,0 +1 @@
|
||||
e
|
7
.history/vite.config_20251001195155.ts
Normal file
7
.history/vite.config_20251001195155.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
})
|
8
.history/vite.config_20251001223533.ts
Normal file
8
.history/vite.config_20251001223533.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { defineConfig } from "vite";
|
||||
import react from "@vitejs/plugin-react";
|
||||
import tailwindcss from "@tailwindcss/vite";
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react(), tailwindcss()],
|
||||
});
|
7
.history/vite.config_20251001223537.ts
Normal file
7
.history/vite.config_20251001223537.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
})
|
8
.history/vite.config_20251001223538.ts
Normal file
8
.history/vite.config_20251001223538.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { defineConfig } from "vite";
|
||||
import react from "@vitejs/plugin-react";
|
||||
import tailwindcss from "@tailwindcss/vite";
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react(), tailwindcss()],
|
||||
});
|
73
README.md
Normal file
73
README.md
Normal file
@@ -0,0 +1,73 @@
|
||||
# React + TypeScript + Vite
|
||||
|
||||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
||||
|
||||
Currently, two official plugins are available:
|
||||
|
||||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) for Fast Refresh
|
||||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
||||
|
||||
## React Compiler
|
||||
|
||||
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
|
||||
|
||||
## Expanding the ESLint configuration
|
||||
|
||||
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
||||
|
||||
```js
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
// Other configs...
|
||||
|
||||
// Remove tseslint.configs.recommended and replace with this
|
||||
tseslint.configs.recommendedTypeChecked,
|
||||
// Alternatively, use this for stricter rules
|
||||
tseslint.configs.strictTypeChecked,
|
||||
// Optionally, add this for stylistic rules
|
||||
tseslint.configs.stylisticTypeChecked,
|
||||
|
||||
// Other configs...
|
||||
],
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
// other options...
|
||||
},
|
||||
},
|
||||
])
|
||||
```
|
||||
|
||||
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
||||
|
||||
```js
|
||||
// eslint.config.js
|
||||
import reactX from 'eslint-plugin-react-x'
|
||||
import reactDom from 'eslint-plugin-react-dom'
|
||||
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
// Other configs...
|
||||
// Enable lint rules for React
|
||||
reactX.configs['recommended-typescript'],
|
||||
// Enable lint rules for React DOM
|
||||
reactDom.configs.recommended,
|
||||
],
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
// other options...
|
||||
},
|
||||
},
|
||||
])
|
||||
```
|
23
eslint.config.js
Normal file
23
eslint.config.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import js from '@eslint/js'
|
||||
import globals from 'globals'
|
||||
import reactHooks from 'eslint-plugin-react-hooks'
|
||||
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||
import tseslint from 'typescript-eslint'
|
||||
import { defineConfig, globalIgnores } from 'eslint/config'
|
||||
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
js.configs.recommended,
|
||||
tseslint.configs.recommended,
|
||||
reactHooks.configs['recommended-latest'],
|
||||
reactRefresh.configs.vite,
|
||||
],
|
||||
languageOptions: {
|
||||
ecmaVersion: 2020,
|
||||
globals: globals.browser,
|
||||
},
|
||||
},
|
||||
])
|
13
index.html
Normal file
13
index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>my-dashboard</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
4043
package-lock.json
مولّد
Normal file
4043
package-lock.json
مولّد
Normal file
تم حذف اختلاف الملف لأن الملف كبير جداً
تحميل الاختلاف
34
package.json
Normal file
34
package.json
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "my-dashboard",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc -b && vite build",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tailwindcss/vite": "^4.1.14",
|
||||
"lucide-react": "^0.544.0",
|
||||
"react": "^19.1.1",
|
||||
"react-dom": "^19.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.36.0",
|
||||
"@types/react": "^19.1.13",
|
||||
"@types/react-dom": "^19.1.9",
|
||||
"@vitejs/plugin-react": "^5.0.3",
|
||||
"autoprefixer": "^10.4.21",
|
||||
"eslint": "^9.36.0",
|
||||
"eslint-plugin-react-hooks": "^5.2.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.20",
|
||||
"globals": "^16.4.0",
|
||||
"postcss": "^8.5.6",
|
||||
"tailwindcss": "^4.1.14",
|
||||
"typescript": "~5.8.3",
|
||||
"typescript-eslint": "^8.44.0",
|
||||
"vite": "^7.1.7"
|
||||
}
|
||||
}
|
1
public/vite.svg
Normal file
1
public/vite.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
بعد العرض: | الارتفاع: | الحجم: 1.5 KiB |
599
src/App.tsx
Normal file
599
src/App.tsx
Normal file
@@ -0,0 +1,599 @@
|
||||
import React, { useState, useMemo } from 'react';
|
||||
import { ChevronDown, ChevronRight, CheckCircle, XCircle, AlertCircle, Code, FileText } from 'lucide-react';
|
||||
|
||||
// ============================================================================
|
||||
// TYPES & INTERFACES - Centralized type definitions for type safety
|
||||
// ============================================================================
|
||||
|
||||
// Main data structure interface matching backend JSON
|
||||
interface APITestData {
|
||||
url: string;
|
||||
api: APIEndpoint[];
|
||||
}
|
||||
|
||||
interface APIEndpoint {
|
||||
title: string;
|
||||
method: string;
|
||||
endpoint: string;
|
||||
description: string;
|
||||
urlParams: Parameter[];
|
||||
query: Parameter[];
|
||||
headers: Header[];
|
||||
body: BodySchema;
|
||||
testCases: TestCase[];
|
||||
}
|
||||
|
||||
interface Parameter {
|
||||
name: string;
|
||||
type: string;
|
||||
example: any;
|
||||
required: boolean;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
interface Header {
|
||||
name: string;
|
||||
type: string;
|
||||
example: string;
|
||||
required: boolean;
|
||||
}
|
||||
|
||||
interface BodySchema {
|
||||
required: boolean;
|
||||
fields: any[];
|
||||
}
|
||||
|
||||
interface TestCase {
|
||||
id: number;
|
||||
title: string;
|
||||
input: TestInput;
|
||||
expectedResponse: Response;
|
||||
actualResponse: Response;
|
||||
status: 'passed' | 'failed';
|
||||
}
|
||||
|
||||
interface TestInput {
|
||||
urlParams: Record<string, any>;
|
||||
query: Record<string, any>;
|
||||
headers: Record<string, any>;
|
||||
body: Record<string, any>;
|
||||
}
|
||||
|
||||
interface Response {
|
||||
statusCode: number;
|
||||
body: Record<string, any>;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// MOCK DATA - Replace with props from backend
|
||||
// ============================================================================
|
||||
|
||||
const mockData: APITestData = {
|
||||
"url": "https://jsonplaceholder.typicode.com",
|
||||
"api": [
|
||||
{
|
||||
"title": "Get User Details",
|
||||
"method": "GET",
|
||||
"endpoint": "/users/{userId}",
|
||||
"description": "Fetch user details by ID",
|
||||
"urlParams": [
|
||||
{
|
||||
"name": "userId",
|
||||
"type": "integer",
|
||||
"example": 123,
|
||||
"required": true,
|
||||
"description": "Unique identifier of the user"
|
||||
}
|
||||
],
|
||||
"query": [
|
||||
{
|
||||
"name": "includePosts",
|
||||
"type": "boolean",
|
||||
"example": true,
|
||||
"required": false,
|
||||
"description": "Whether to include user posts"
|
||||
}
|
||||
],
|
||||
"headers": [
|
||||
{
|
||||
"name": "Authorization",
|
||||
"type": "string",
|
||||
"example": "Bearer <token>",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"required": false,
|
||||
"fields": []
|
||||
},
|
||||
"testCases": [
|
||||
{
|
||||
"id": 1,
|
||||
"title": "Valid userId with includePosts=true",
|
||||
"input": {
|
||||
"urlParams": {
|
||||
"userId": 123
|
||||
},
|
||||
"query": {
|
||||
"includePosts": true
|
||||
},
|
||||
"headers": {
|
||||
"Authorization": "Bearer valid_token"
|
||||
},
|
||||
"body": {}
|
||||
},
|
||||
"expectedResponse": {
|
||||
"statusCode": 200,
|
||||
"body": {
|
||||
"id": 123,
|
||||
"name": "John Doe",
|
||||
"posts": []
|
||||
}
|
||||
},
|
||||
"actualResponse": {
|
||||
"statusCode": 200,
|
||||
"body": {
|
||||
"id": 123,
|
||||
"name": "John Doe",
|
||||
"posts": []
|
||||
}
|
||||
},
|
||||
"status": "passed"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"title": "Invalid userId",
|
||||
"input": {
|
||||
"urlParams": {
|
||||
"userId": 9999
|
||||
},
|
||||
"query": {
|
||||
"includePosts": false
|
||||
},
|
||||
"headers": {
|
||||
"Authorization": "Bearer valid_token"
|
||||
},
|
||||
"body": {}
|
||||
},
|
||||
"expectedResponse": {
|
||||
"statusCode": 404,
|
||||
"body": {
|
||||
"error": "User not found"
|
||||
}
|
||||
},
|
||||
"actualResponse": {
|
||||
"statusCode": 404,
|
||||
"body": {
|
||||
"error": "User not found"
|
||||
}
|
||||
},
|
||||
"status": "passed"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"title": "Missing authorization header",
|
||||
"input": {
|
||||
"urlParams": {
|
||||
"userId": 123
|
||||
},
|
||||
"query": {
|
||||
"includePosts": true
|
||||
},
|
||||
"headers": {},
|
||||
"body": {}
|
||||
},
|
||||
"expectedResponse": {
|
||||
"statusCode": 401,
|
||||
"body": {
|
||||
"error": "Unauthorized"
|
||||
}
|
||||
},
|
||||
"actualResponse": {
|
||||
"statusCode": 403,
|
||||
"body": {
|
||||
"error": "Forbidden"
|
||||
}
|
||||
},
|
||||
"status": "failed"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// UTILITY FUNCTIONS - Pure helper functions
|
||||
// ============================================================================
|
||||
|
||||
// Calculate test statistics for an API endpoint
|
||||
const calculateStats = (testCases: TestCase[]) => {
|
||||
const total = testCases.length;
|
||||
const passed = testCases.filter(tc => tc.status === 'passed').length;
|
||||
const failed = testCases.filter(tc => tc.status === 'failed').length;
|
||||
const passRate = total > 0 ? ((passed / total) * 100).toFixed(1) : '0';
|
||||
|
||||
return { total, passed, failed, passRate };
|
||||
};
|
||||
|
||||
// Get HTTP method badge color
|
||||
const getMethodColor = (method: string) => {
|
||||
const colors: Record<string, string> = {
|
||||
GET: 'bg-green-600',
|
||||
POST: 'bg-blue-600',
|
||||
PUT: 'bg-yellow-600',
|
||||
PATCH: 'bg-orange-600',
|
||||
DELETE: 'bg-red-600'
|
||||
};
|
||||
return colors[method.toUpperCase()] || 'bg-gray-600';
|
||||
};
|
||||
|
||||
// Format JSON with proper indentation
|
||||
const formatJSON = (obj: any) => JSON.stringify(obj, null, 2);
|
||||
|
||||
// ============================================================================
|
||||
// COMPONENT: JsonViewer - Displays formatted JSON with syntax highlighting
|
||||
// ============================================================================
|
||||
|
||||
const JsonViewer: React.FC<{ data: any; title: string }> = ({ data, title }) => {
|
||||
return (
|
||||
<div className="flex-1">
|
||||
<div className="text-xs font-semibold text-gray-400 mb-2">{title}</div>
|
||||
<pre className="bg-gray-900 rounded-lg p-4 overflow-x-auto text-xs">
|
||||
<code className="text-gray-300">{formatJSON(data)}</code>
|
||||
</pre>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// COMPONENT: StatusBadge - Visual indicator for test status
|
||||
// ============================================================================
|
||||
|
||||
const StatusBadge: React.FC<{ status: 'passed' | 'failed' }> = ({ status }) => {
|
||||
const isPassed = status === 'passed';
|
||||
|
||||
return (
|
||||
<span className={`inline-flex items-center gap-1 px-3 py-1 rounded-full text-xs font-semibold ${
|
||||
isPassed ? 'bg-green-600/20 text-green-400' : 'bg-red-600/20 text-red-400'
|
||||
}`}>
|
||||
{isPassed ? <CheckCircle size={14} /> : <XCircle size={14} />}
|
||||
{status.toUpperCase()}
|
||||
</span>
|
||||
);
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// COMPONENT: ParameterTable - Displays API parameters in table format
|
||||
// ============================================================================
|
||||
|
||||
const ParameterTable: React.FC<{
|
||||
params: Parameter[] | Header[];
|
||||
title: string;
|
||||
icon: React.ReactNode;
|
||||
}> = ({ params, title, icon }) => {
|
||||
if (params.length === 0) return null;
|
||||
|
||||
return (
|
||||
<div className="mb-4">
|
||||
<div className="flex items-center gap-2 mb-3">
|
||||
{icon}
|
||||
<h4 className="text-sm font-semibold text-gray-300">{title}</h4>
|
||||
</div>
|
||||
<div className="bg-gray-800/50 rounded-lg overflow-hidden">
|
||||
<table className="w-full text-xs">
|
||||
<thead className="bg-gray-700/50">
|
||||
<tr>
|
||||
<th className="text-left p-3 text-gray-400 font-semibold">Name</th>
|
||||
<th className="text-left p-3 text-gray-400 font-semibold">Type</th>
|
||||
<th className="text-left p-3 text-gray-400 font-semibold">Required</th>
|
||||
<th className="text-left p-3 text-gray-400 font-semibold">Example</th>
|
||||
{'description' in params[0] && (
|
||||
<th className="text-left p-3 text-gray-400 font-semibold">Description</th>
|
||||
)}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{params.map((param, idx) => (
|
||||
<tr key={idx} className="border-t border-gray-700/50">
|
||||
<td className="p-3 text-gray-300 font-mono">{param.name}</td>
|
||||
<td className="p-3 text-blue-400 font-mono">{param.type}</td>
|
||||
<td className="p-3">
|
||||
<span className={`px-2 py-1 rounded text-xs ${
|
||||
param.required ? 'bg-red-600/20 text-red-400' : 'bg-gray-600/20 text-gray-400'
|
||||
}`}>
|
||||
{param.required ? 'Yes' : 'No'}
|
||||
</span>
|
||||
</td>
|
||||
<td className="p-3 text-gray-400 font-mono">{String(param.example)}</td>
|
||||
{'description' in param && (
|
||||
<td className="p-3 text-gray-400">{param.description}</td>
|
||||
)}
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// COMPONENT: TestCaseCard - Individual test case with expand/collapse
|
||||
// ============================================================================
|
||||
|
||||
const TestCaseCard: React.FC<{ testCase: TestCase }> = ({ testCase }) => {
|
||||
const [isExpanded, setIsExpanded] = useState(false);
|
||||
const isPassed = testCase.status === 'passed';
|
||||
|
||||
// Compare expected vs actual to highlight differences
|
||||
const statusCodeMatch = testCase.expectedResponse.statusCode === testCase.actualResponse.statusCode;
|
||||
|
||||
return (
|
||||
<div className={`bg-gray-800 rounded-lg border-2 ${
|
||||
isPassed ? 'border-green-600/30' : 'border-red-600/30'
|
||||
} overflow-hidden transition-all duration-200 hover:shadow-lg`}>
|
||||
{/* Test case header - Always visible */}
|
||||
<div
|
||||
className="p-4 cursor-pointer flex items-center justify-between"
|
||||
onClick={() => setIsExpanded(!isExpanded)}
|
||||
>
|
||||
<div className="flex items-center gap-3 flex-1">
|
||||
{isExpanded ? <ChevronDown size={20} /> : <ChevronRight size={20} />}
|
||||
<div className="flex-1">
|
||||
<div className="flex items-center gap-3 mb-1">
|
||||
<h4 className="text-sm font-semibold text-gray-200">{testCase.title}</h4>
|
||||
<StatusBadge status={testCase.status} />
|
||||
</div>
|
||||
<div className="text-xs text-gray-500">Test Case #{testCase.id}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Status code comparison */}
|
||||
<div className="flex items-center gap-4 mr-4">
|
||||
<div className="text-right">
|
||||
<div className="text-xs text-gray-500">Expected</div>
|
||||
<div className={`text-sm font-mono font-bold ${statusCodeMatch ? 'text-green-400' : 'text-yellow-400'}`}>
|
||||
{testCase.expectedResponse.statusCode}
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-gray-600">→</div>
|
||||
<div className="text-right">
|
||||
<div className="text-xs text-gray-500">Actual</div>
|
||||
<div className={`text-sm font-mono font-bold ${statusCodeMatch ? 'text-green-400' : 'text-red-400'}`}>
|
||||
{testCase.actualResponse.statusCode}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Expanded details */}
|
||||
{isExpanded && (
|
||||
<div className="border-t border-gray-700 p-4 space-y-4">
|
||||
{/* Test Input Section */}
|
||||
<div>
|
||||
<h5 className="text-sm font-semibold text-gray-300 mb-3 flex items-center gap-2">
|
||||
<Code size={16} />
|
||||
Test Input
|
||||
</h5>
|
||||
<div className="grid grid-cols-2 gap-4 mb-4">
|
||||
{Object.keys(testCase.input.urlParams).length > 0 && (
|
||||
<div className="bg-gray-900/50 rounded p-3">
|
||||
<div className="text-xs font-semibold text-gray-400 mb-2">URL Parameters</div>
|
||||
<pre className="text-xs text-gray-300 font-mono">
|
||||
{formatJSON(testCase.input.urlParams)}
|
||||
</pre>
|
||||
</div>
|
||||
)}
|
||||
{Object.keys(testCase.input.query).length > 0 && (
|
||||
<div className="bg-gray-900/50 rounded p-3">
|
||||
<div className="text-xs font-semibold text-gray-400 mb-2">Query Parameters</div>
|
||||
<pre className="text-xs text-gray-300 font-mono">
|
||||
{formatJSON(testCase.input.query)}
|
||||
</pre>
|
||||
</div>
|
||||
)}
|
||||
{Object.keys(testCase.input.headers).length > 0 && (
|
||||
<div className="bg-gray-900/50 rounded p-3">
|
||||
<div className="text-xs font-semibold text-gray-400 mb-2">Headers</div>
|
||||
<pre className="text-xs text-gray-300 font-mono">
|
||||
{formatJSON(testCase.input.headers)}
|
||||
</pre>
|
||||
</div>
|
||||
)}
|
||||
{Object.keys(testCase.input.body).length > 0 && (
|
||||
<div className="bg-gray-900/50 rounded p-3">
|
||||
<div className="text-xs font-semibold text-gray-400 mb-2">Body</div>
|
||||
<pre className="text-xs text-gray-300 font-mono">
|
||||
{formatJSON(testCase.input.body)}
|
||||
</pre>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Response Comparison - Side by Side */}
|
||||
<div>
|
||||
<h5 className="text-sm font-semibold text-gray-300 mb-3 flex items-center gap-2">
|
||||
<FileText size={16} />
|
||||
Response Comparison
|
||||
</h5>
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<JsonViewer
|
||||
data={testCase.expectedResponse.body}
|
||||
title="Expected Response Body"
|
||||
/>
|
||||
<JsonViewer
|
||||
data={testCase.actualResponse.body}
|
||||
title="Actual Response Body"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// COMPONENT: APIEndpointCard - Main API endpoint display with test cases
|
||||
// ============================================================================
|
||||
|
||||
const APIEndpointCard: React.FC<{ api: APIEndpoint }> = ({ api }) => {
|
||||
const [isExpanded, setIsExpanded] = useState(true);
|
||||
const stats = useMemo(() => calculateStats(api.testCases), [api.testCases]);
|
||||
|
||||
return (
|
||||
<div className="bg-gray-800/50 rounded-xl border border-gray-700 overflow-hidden">
|
||||
{/* API Header */}
|
||||
<div
|
||||
className="p-6 cursor-pointer hover:bg-gray-800/70 transition-colors"
|
||||
onClick={() => setIsExpanded(!isExpanded)}
|
||||
>
|
||||
<div className="flex items-start justify-between">
|
||||
<div className="flex items-start gap-4 flex-1">
|
||||
{isExpanded ? <ChevronDown size={24} /> : <ChevronRight size={24} />}
|
||||
<div className="flex-1">
|
||||
<div className="flex items-center gap-3 mb-2">
|
||||
<span className={`${getMethodColor(api.method)} text-white text-xs font-bold px-3 py-1 rounded`}>
|
||||
{api.method}
|
||||
</span>
|
||||
<h3 className="text-lg font-bold text-gray-100">{api.title}</h3>
|
||||
</div>
|
||||
<code className="text-sm text-blue-400 bg-gray-900/50 px-3 py-1 rounded font-mono">
|
||||
{api.endpoint}
|
||||
</code>
|
||||
<p className="text-sm text-gray-400 mt-2">{api.description}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Statistics */}
|
||||
<div className="flex items-center gap-6 ml-6">
|
||||
<div className="text-center">
|
||||
<div className="text-2xl font-bold text-gray-200">{stats.total}</div>
|
||||
<div className="text-xs text-gray-500">Total Tests</div>
|
||||
</div>
|
||||
<div className="text-center">
|
||||
<div className="text-2xl font-bold text-green-400">{stats.passed}</div>
|
||||
<div className="text-xs text-gray-500">Passed</div>
|
||||
</div>
|
||||
<div className="text-center">
|
||||
<div className="text-2xl font-bold text-red-400">{stats.failed}</div>
|
||||
<div className="text-xs text-gray-500">Failed</div>
|
||||
</div>
|
||||
<div className="text-center">
|
||||
<div className="text-2xl font-bold text-blue-400">{stats.passRate}%</div>
|
||||
<div className="text-xs text-gray-500">Pass Rate</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Expanded Content */}
|
||||
{isExpanded && (
|
||||
<div className="border-t border-gray-700 p-6 space-y-6">
|
||||
{/* API Schema Information */}
|
||||
<div className="space-y-4">
|
||||
<ParameterTable
|
||||
params={api.urlParams}
|
||||
title="URL Parameters"
|
||||
icon={<Code size={16} className="text-blue-400" />}
|
||||
/>
|
||||
<ParameterTable
|
||||
params={api.query}
|
||||
title="Query Parameters"
|
||||
icon={<AlertCircle size={16} className="text-yellow-400" />}
|
||||
/>
|
||||
<ParameterTable
|
||||
params={api.headers}
|
||||
title="Headers"
|
||||
icon={<FileText size={16} className="text-green-400" />}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Test Cases */}
|
||||
<div>
|
||||
<h4 className="text-lg font-semibold text-gray-200 mb-4">Test Cases</h4>
|
||||
<div className="space-y-3">
|
||||
{api.testCases.map(testCase => (
|
||||
<TestCaseCard key={testCase.id} testCase={testCase} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// MAIN COMPONENT: Dashboard - Root component with state management
|
||||
// ============================================================================
|
||||
|
||||
const APITestDashboard: React.FC = () => {
|
||||
// State management - In production, this would come from props or context
|
||||
const [data] = useState<APITestData>(mockData);
|
||||
|
||||
// Calculate overall statistics using memoization for performance
|
||||
const overallStats = useMemo(() => {
|
||||
const allTestCases = data.api.flatMap(api => api.testCases);
|
||||
return calculateStats(allTestCases);
|
||||
}, [data.api]);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gradient-to-br from-gray-900 via-gray-800 to-gray-900 text-gray-100 p-8">
|
||||
<div className="max-w-7xl mx-auto">
|
||||
{/* Dashboard Header */}
|
||||
<div className="mb-8">
|
||||
<h1 className="text-4xl font-bold mb-2 bg-gradient-to-r from-blue-400 to-purple-400 bg-clip-text text-transparent">
|
||||
API Test Results Dashboard
|
||||
</h1>
|
||||
<p className="text-gray-400">Base URL: <code className="text-blue-400 bg-gray-800 px-2 py-1 rounded">{data.url}</code></p>
|
||||
</div>
|
||||
|
||||
{/* Overall Statistics Card */}
|
||||
<div className="bg-gradient-to-r from-gray-800 to-gray-700 rounded-xl p-6 mb-8 border border-gray-600 shadow-xl">
|
||||
<h2 className="text-xl font-semibold mb-4 text-gray-200">Overall Statistics</h2>
|
||||
<div className="grid grid-cols-4 gap-6">
|
||||
<div className="bg-gray-900/50 rounded-lg p-4 text-center">
|
||||
<div className="text-3xl font-bold text-blue-400 mb-1">{data.api.length}</div>
|
||||
<div className="text-sm text-gray-400">API Endpoints</div>
|
||||
</div>
|
||||
<div className="bg-gray-900/50 rounded-lg p-4 text-center">
|
||||
<div className="text-3xl font-bold text-gray-200 mb-1">{overallStats.total}</div>
|
||||
<div className="text-sm text-gray-400">Total Tests</div>
|
||||
</div>
|
||||
<div className="bg-gray-900/50 rounded-lg p-4 text-center">
|
||||
<div className="text-3xl font-bold text-green-400 mb-1">{overallStats.passed}</div>
|
||||
<div className="text-sm text-gray-400">Passed Tests</div>
|
||||
</div>
|
||||
<div className="bg-gray-900/50 rounded-lg p-4 text-center">
|
||||
<div className="text-3xl font-bold text-red-400 mb-1">{overallStats.failed}</div>
|
||||
<div className="text-sm text-gray-400">Failed Tests</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-4 bg-gray-900/50 rounded-lg p-4">
|
||||
<div className="flex items-center justify-between mb-2">
|
||||
<span className="text-sm text-gray-400">Overall Pass Rate</span>
|
||||
<span className="text-lg font-bold text-blue-400">{overallStats.passRate}%</span>
|
||||
</div>
|
||||
<div className="w-full bg-gray-700 rounded-full h-3 overflow-hidden">
|
||||
<div
|
||||
className="bg-gradient-to-r from-green-500 to-green-400 h-full rounded-full transition-all duration-500"
|
||||
style={{ width: `${overallStats.passRate}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* API Endpoints List */}
|
||||
<div className="space-y-6">
|
||||
{data.api.map((api, idx) => (
|
||||
<APIEndpointCard key={idx} api={api} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default APITestDashboard;
|
15
src/index.css
Normal file
15
src/index.css
Normal file
@@ -0,0 +1,15 @@
|
||||
@import "tailwindcss";
|
||||
/* * {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
} */
|
10
src/main.tsx
Normal file
10
src/main.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import App from './App.tsx'
|
||||
import './index.css'
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>,
|
||||
)
|
28
tsconfig.app.json
Normal file
28
tsconfig.app.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||
"target": "ES2022",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
||||
"module": "ESNext",
|
||||
"types": ["vite/client"],
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
7
tsconfig.json
Normal file
7
tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./tsconfig.app.json" },
|
||||
{ "path": "./tsconfig.node.json" }
|
||||
]
|
||||
}
|
26
tsconfig.node.json
Normal file
26
tsconfig.node.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||
"target": "ES2023",
|
||||
"lib": ["ES2023"],
|
||||
"module": "ESNext",
|
||||
"types": [],
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
8
vite.config.ts
Normal file
8
vite.config.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { defineConfig } from "vite";
|
||||
import react from "@vitejs/plugin-react";
|
||||
import tailwindcss from "@tailwindcss/vite";
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react(), tailwindcss()],
|
||||
});
|
المرجع في مشكلة جديدة
حظر مستخدم