-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapi-test.html
More file actions
148 lines (134 loc) · 4.88 KB
/
Copy pathapi-test.html
File metadata and controls
148 lines (134 loc) · 4.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>API Test - DevMe Dashboard</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background: #1a1a1a;
color: white;
}
.test-section {
background: #2a2a2a;
padding: 20px;
margin: 20px 0;
border-radius: 8px;
}
.status {
padding: 10px;
margin: 10px 0;
border-radius: 4px;
}
.success { background: #28a745; }
.warning { background: #ffc107; color: #000; }
.error { background: #dc3545; }
.info { background: #17a2b8; }
pre {
background: #333;
padding: 10px;
border-radius: 4px;
overflow-x: auto;
max-height: 300px;
}
button {
background: #4d90fe;
color: white;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
margin: 5px;
}
button:hover {
background: #357abd;
}
</style>
</head>
<body>
<h1>API Test - DevMe Dashboard</h1>
<div class="test-section">
<h2>API Tests</h2>
<button onclick="testGitHubAPI()">Test GitHub API</button>
<button onclick="testLeetCodeAPI()">Test LeetCode API</button>
<button onclick="testImageLoading()">Test Image Loading</button>
<div id="api-results"></div>
</div>
<div class="test-section">
<h2>Results</h2>
<div id="results"></div>
</div>
<script>
const apiResults = document.getElementById('api-results');
const results = document.getElementById('results');
function addResult(test, status, message, data = null) {
const resultDiv = document.createElement('div');
resultDiv.className = `status ${status}`;
resultDiv.innerHTML = `<strong>${test}:</strong> ${message}`;
if (data) {
const pre = document.createElement('pre');
pre.textContent = JSON.stringify(data, null, 2);
resultDiv.appendChild(pre);
}
results.appendChild(resultDiv);
}
async function testGitHubAPI() {
addResult('GitHub API', 'info', 'Testing GitHub API...');
try {
const response = await fetch('https://api.github.com/users/codebyNJ');
const data = await response.json();
if (response.ok) {
addResult('GitHub API', 'success', 'GitHub API working', data);
} else {
addResult('GitHub API', 'error', `GitHub API error: ${response.status}`, data);
}
} catch (error) {
addResult('GitHub API', 'error', `GitHub API failed: ${error.message}`);
}
}
async function testLeetCodeAPI() {
addResult('LeetCode API', 'info', 'Testing LeetCode API...');
try {
const response = await fetch('https://leetcode-stats-api.herokuapp.com/Nijeesh_1805');
const data = await response.json();
if (response.ok) {
addResult('LeetCode API', 'success', 'LeetCode API working', data);
} else {
addResult('LeetCode API', 'error', `LeetCode API error: ${response.status}`, data);
}
} catch (error) {
addResult('LeetCode API', 'error', `LeetCode API failed: ${error.message}`);
}
}
function testImageLoading() {
addResult('Image Loading', 'info', 'Testing image loading...');
const images = [
'../src/images/banners/mountain-sunset.png',
'../src/images/avatars/sample.jpg'
];
images.forEach(imagePath => {
const img = new Image();
img.onload = () => {
addResult('Image Loading', 'success', `${imagePath} loaded successfully`);
};
img.onerror = () => {
addResult('Image Loading', 'error', `${imagePath} failed to load`);
};
img.src = imagePath;
});
}
// Auto-run tests on load
document.addEventListener('DOMContentLoaded', () => {
setTimeout(() => {
testGitHubAPI();
testLeetCodeAPI();
testImageLoading();
}, 1000);
});
</script>
</body>
</html>