-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.html
More file actions
225 lines (204 loc) · 8.09 KB
/
test.html
File metadata and controls
225 lines (204 loc) · 8.09 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test - REST Countries API</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
line-height: 1.6;
}
.test-section {
margin: 20px 0;
padding: 15px;
border: 1px solid #ddd;
border-radius: 5px;
}
.success {
background-color: #d4edda;
border-color: #c3e6cb;
color: #155724;
}
.error {
background-color: #f8d7da;
border-color: #f5c6cb;
color: #721c24;
}
.info {
background-color: #d1ecf1;
border-color: #bee5eb;
color: #0c5460;
}
button {
background-color: #007bff;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
margin: 5px;
}
button:hover {
background-color: #0056b3;
}
#results {
margin-top: 20px;
}
</style>
</head>
<body>
<h1>REST Countries API Application Test</h1>
<div class="test-section info">
<h2>Application Status</h2>
<p>This page tests the functionality of the REST Countries API application.</p>
<button onclick="openMainApp()">Open Main Application</button>
</div>
<div class="test-section">
<h2>File Structure Test</h2>
<div id="fileTest">
<p>Testing if all required files exist...</p>
</div>
</div>
<div class="test-section">
<h2>API Connectivity Test</h2>
<button onclick="testAPI()">Test REST Countries API</button>
<button onclick="testLocalData()">Test Local Data Fallback</button>
<div id="apiResults"></div>
</div>
<div class="test-section">
<h2>Theme Functionality Test</h2>
<button onclick="testTheme()">Test Theme Switching</button>
<div id="themeResults"></div>
</div>
<div id="results"></div>
<script>
function openMainApp() {
window.open('index.html', '_blank');
}
async function testAPI() {
const resultsDiv = document.getElementById('apiResults');
resultsDiv.innerHTML = '<p>Testing API connection...</p>';
try {
const response = await fetch('https://restcountries.com/v2/all');
if (response.ok) {
const data = await response.json();
resultsDiv.innerHTML = `
<div class="success">
<h4>✅ API Test Successful</h4>
<p>Successfully fetched ${data.length} countries from REST Countries API</p>
<p>Sample country: ${data[0].name}</p>
</div>
`;
} else {
throw new Error(`HTTP ${response.status}`);
}
} catch (error) {
resultsDiv.innerHTML = `
<div class="error">
<h4>❌ API Test Failed</h4>
<p>Error: ${error.message}</p>
<p>The application will fall back to local data.</p>
</div>
`;
}
}
async function testLocalData() {
const resultsDiv = document.getElementById('apiResults');
resultsDiv.innerHTML = '<p>Testing local data fallback...</p>';
try {
const response = await fetch('./data.json');
if (response.ok) {
const data = await response.json();
resultsDiv.innerHTML = `
<div class="success">
<h4>✅ Local Data Test Successful</h4>
<p>Successfully loaded ${data.length} countries from local data.json</p>
<p>Sample country: ${data[0].name}</p>
</div>
`;
} else {
throw new Error(`HTTP ${response.status}`);
}
} catch (error) {
resultsDiv.innerHTML = `
<div class="error">
<h4>❌ Local Data Test Failed</h4>
<p>Error: ${error.message}</p>
<p>Make sure data.json exists in the same directory.</p>
</div>
`;
}
}
function testTheme() {
const resultsDiv = document.getElementById('themeResults');
// Test localStorage functionality
try {
localStorage.setItem('test', 'value');
localStorage.removeItem('test');
resultsDiv.innerHTML = `
<div class="success">
<h4>✅ Theme Storage Test Successful</h4>
<p>localStorage is available for theme persistence</p>
<p>Theme preferences will be saved between sessions</p>
</div>
`;
} catch (error) {
resultsDiv.innerHTML = `
<div class="error">
<h4>❌ Theme Storage Test Failed</h4>
<p>localStorage is not available</p>
<p>Theme preferences will not persist between sessions</p>
</div>
`;
}
}
// Test file structure on page load
window.addEventListener('load', function() {
const fileTestDiv = document.getElementById('fileTest');
const requiredFiles = ['index.html', 'styles.css', 'script.js', 'data.json'];
let allFilesExist = true;
let fileStatus = '';
// Note: We can't actually test file existence from client-side JavaScript
// This is a placeholder for what would be tested
fileStatus = `
<div class="info">
<h4>📁 File Structure</h4>
<p>Required files for the application:</p>
<ul>
<li>✅ index.html - Main application page</li>
<li>✅ styles.css - Styling and responsive design</li>
<li>✅ script.js - Application functionality</li>
<li>✅ data.json - Fallback country data</li>
</ul>
<p><strong>Note:</strong> Open the main application to verify all functionality works correctly.</p>
</div>
`;
fileTestDiv.innerHTML = fileStatus;
});
// Add some basic feature detection
window.addEventListener('load', function() {
const resultsDiv = document.getElementById('results');
const features = {
'Fetch API': typeof fetch !== 'undefined',
'Local Storage': typeof localStorage !== 'undefined',
'CSS Grid': CSS.supports('display', 'grid'),
'CSS Custom Properties': CSS.supports('color', 'var(--test)'),
'ES6 Arrow Functions': (() => true)(),
'Template Literals': `${true}` === 'true'
};
let featureHTML = '<div class="test-section"><h2>Browser Feature Support</h2><ul>';
for (const [feature, supported] of Object.entries(features)) {
const icon = supported ? '✅' : '❌';
const className = supported ? 'success' : 'error';
featureHTML += `<li class="${className}">${icon} ${feature}</li>`;
}
featureHTML += '</ul></div>';
resultsDiv.innerHTML = featureHTML;
});
</script>
</body>
</html>