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 
 
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
# Testing Guide πŸ§ͺ

Complete guide to test all features of the Graph RAG Chatbot.

## Prerequisites

- Application running (local or Docker)
- Groq API Key configured
- Test documents prepared

## Test Documents

### 1. Sample CSV (test_data.csv)

Create this file for testing:

```csv
Name,Role,Department,Salary
Alice Johnson,Senior Engineer,Engineering,120000
Bob Smith,Product Manager,Product,110000
Carol White,Designer,Design,100000
David Lee,Engineer,Engineering,95000
Emma Davis,Analyst,Data,90000
```

**Save as**: `test_data.csv`

### 2. Sample PDF

Use any PDF document about:
- Technology
- Business
- Science
- General knowledge

**Recommended**: Download a sample PDF from https://www.w3.org/WAI/test-evaluate/

### 3. Sample TXT

Create `sample.txt` with text like:

```
Natural Language Processing (NLP) is a subfield of linguistics, 
computer science, and artificial intelligence concerned with the 
interactions between computers and human language.

Machine learning is a method of data analysis that automates analytical 
model building. It is a branch of artificial intelligence based on the 
idea that systems can learn from data.

Graph databases are specialized databases designed to store and retrieve 
relational data. They are particularly useful for managing large, 
interconnected datasets where relationships are as important as the data itself.
```

**Save as**: `sample.txt`

## Test Cases

### Test 1: Upload Single Document

**Objective**: Verify basic file upload functionality

**Steps**:
1. Navigate to "πŸ“€ Upload Documents" section
2. Click on upload zone or drag `test_data.csv`
3. Observe the file appears in "Uploaded Documents"
4. Status should change: queued β†’ processing β†’ ready

**Expected Results**:
- βœ… File appears immediately
- βœ… Progress bar fills to 100%
- βœ… Status changes to "ready"
- βœ… Shows chunk count (e.g., "~1 chunks")
- βœ… Shows entity count (e.g., "~12 entities")
- βœ… "View Full Graph" link appears

**Time**: ~3-5 seconds

---

### Test 2: Upload Multiple Documents

**Objective**: Test concurrent document processing

**Steps**:
1. Prepare 3 test files: `test_data.csv`, `sample.txt`, and a PDF
2. Click upload zone
3. Select all 3 files at once
4. Hold Ctrl/Cmd and select all files

**Expected Results**:
- βœ… All 3 files queued simultaneously
- βœ… Each processes independently
- βœ… UI remains responsive
- βœ… All reach "ready" status

**Time**: ~10-15 seconds total

---

### Test 3: View Knowledge Graph

**Objective**: Verify graph visualization

**Steps**:
1. Ensure a document has "ready" status
2. Click "πŸ“ˆ View Full Graph" link
3. Switch to "Knowledge Graph" tab
4. Select document from dropdown

**Expected Results**:
- βœ… Image loads without errors
- βœ… Graph shows nodes (blue = chunks, green = entities)
- βœ… Edges show relationships
- βœ… Layout is readable and clear

**Image Properties**:
- Resolution: 150 DPI
- Format: PNG
- Size: 800x600px (approximately)

---

### Test 4: Simple Query

**Objective**: Test RAG functionality with CSV data

**Steps**:
1. Upload `test_data.csv`
2. Wait for "ready" status
3. In chat section:
   - Select document from dropdown
   - Type query: "Who is the senior engineer?"
   - Click "Send"

**Expected Results**:
- βœ… Chat message appears
- βœ… Loading indicator shows
- βœ… Bot responds with answer
- βœ… Response references Alice Johnson
- βœ… Response appears in 2-5 seconds

**Example Expected Answer**:
```
Based on the provided data, Alice Johnson is the Senior Engineer 
in the Engineering Department with a salary of $120,000.
```

---

### Test 5: Knowledge-based Query

**Objective**: Test with text document

**Steps**:
1. Upload `sample.txt` (NLP/ML content)
2. Wait for "ready" status
3. Query: "What is machine learning?"

**Expected Results**:
- βœ… Bot provides accurate explanation
- βœ… Answer comes from the document context
- βœ… Response is relevant and coherent

**Example Expected Answer**:
```
Machine learning is a method of data analysis that automates 
analytical model building. It is a branch of artificial 
intelligence based on the idea that systems can learn from data.
```

---

### Test 6: Multi-chunk Context

**Objective**: Test queries that require context from multiple chunks

**Steps**:
1. Upload `sample.txt`
2. Query: "What are the relationships between NLP, machine learning, and graph databases?"

**Expected Results**:
- βœ… Answer synthesizes information across multiple chunks
- βœ… Shows understanding of relationships
- βœ… Confidence score is shown

---

### Test 7: Out-of-context Query

**Objective**: Test handling of irrelevant queries

**Steps**:
1. Upload `test_data.csv` (employee data)
2. Query: "What is quantum physics?"

**Expected Results**:
- βœ… Bot responds: "No relevant information found in the document"
- βœ… No incorrect information is generated
- βœ… Error is handled gracefully

---

### Test 8: Document Deletion

**Objective**: Verify document removal

**Steps**:
1. Upload `test_data.csv`
2. Wait for "ready" status
3. Click "Delete" button
4. Confirm deletion

**Expected Results**:
- βœ… Document disappears from list
- βœ… Graph image is removed
- βœ… Cannot query deleted document
- βœ… Dropdown option removed

---

### Test 9: Error Handling - Invalid File

**Objective**: Test upload of unsupported format

**Steps**:
1. Try to upload file with unsupported extension (.exe, .jpg, etc.)
2. Observe UI response

**Expected Results**:
- βœ… File is accepted (upload endpoint)
- βœ… Processing fails with meaningful error
- βœ… Status shows "error"
- βœ… Error message visible: "Unsupported file type"

---

### Test 10: Error Handling - Large File

**Objective**: Test max file size limit

**Steps**:
1. Create a file > 50MB
2. Try to upload

**Expected Results**:
- βœ… Upload is rejected
- βœ… Error message: "File too large"
- βœ… File not added to list

---

### Test 11: UI Responsiveness

**Objective**: Verify UI doesn't freeze during processing

**Steps**:
1. Upload a large PDF
2. While processing, try:
   - Typing in chat box ← Should work
   - Clicking buttons ← Should respond
   - Switching tabs ← Should work smoothly
   - Scrolling document list ← Should scroll

**Expected Results**:
- βœ… All interactions responsive
- βœ… No UI freezing
- βœ… Processing continues in background

---

### Test 12: Document List Auto-refresh

**Objective**: Verify real-time status updates

**Steps**:
1. Upload document
2. Watch the status bar update
3. Monitor without manual refresh

**Expected Results**:
- βœ… Status updates every 1.5 seconds
- βœ… Progress bar moves smoothly
- βœ… No manual refresh needed
- βœ… Final status appears automatically

---

### Test 13: Browser Compatibility

**Test on**: Chrome, Firefox, Safari, Edge

**Steps for each browser**:
1. Load application homepage
2. Test file upload
3. Test chat functionality
4. Check graph visualization

**Expected Results**:
- βœ… UI loads correctly
- βœ… All features work
- βœ… No console errors
- βœ… Styling renders properly

---

### Test 14: Mobile Responsiveness

**Steps**:
1. Open on mobile device (or DevTools)
2. Set viewport to 375Γ—667 (iPhone)
3. Test all features:
   - Upload
   - Chat
   - Graph viewing
   - Navigation

**Expected Results**:
- βœ… Layout adapts to mobile
- βœ… Single column layout
- βœ… Touch interactions work
- βœ… Text is readable

---

### Test 15: API Endpoints Directly

**Tool**: curl, Postman, or Python requests

#### Upload Request
```bash
curl -X POST \
  -F "files=@test_data.csv" \
  http://localhost:7860/api/upload
```

**Expected Response**:
```json
{
  "success": true,
  "message": "βœ… 1 file(s) queued for processing",
  "successful": 1,
  "failed": 0,
  "files": ["test_data.csv"]
}
```

#### Get Documents
```bash
curl http://localhost:7860/api/documents
```

**Expected Response**:
```json
{
  "documents": {
    "test_data.csv": {
      "status": "ready",
      "chunks": 1,
      "entities": 10,
      "graph_image": "/graph-image/test_data.csv"
    }
  },
  "api_key_set": true,
  "timestamp": "2024-01-15T10:30:00"
}
```

#### Query
```bash
curl -X POST \
  -H "Content-Type: application/json" \
  -d '{"query": "Who is the senior engineer?", "document": "test_data.csv"}' \
  http://localhost:7860/api/query
```

**Expected Response**:
```json
{
  "answer": "Based on the data, Alice Johnson is the Senior Engineer...",
  "sources": ["Chunk 1"],
  "confidence": 0.85
}
```

---

## Performance Benchmarks

### Expected Processing Times

| Document Type | Size | Processing Time |
|---|---|---|
| CSV (5 rows) | ~1KB | 2-3s |
| Small TXT | ~5KB | 3-5s |
| Medium PDF | 20 pages | 10-15s |
| Large PDF | 50+ pages | 30-60s |

### Query Response Times

- Simple query (1-2 words): 1-2s
- Complex query (5+ words): 2-4s
- Graph visualization load: <100ms

---

## Load Testing

### Single User
- 10 queries: Should complete in ~20-30s
- 5 uploads: Should complete in ~30-45s

### Concurrent Users (Docker)
- 3 simultaneous uploads: Should handle smoothly
- 5 concurrent queries: Should not block

---

## Checklist Summary

- [ ] Single document upload works
- [ ] Multiple document upload works
- [ ] Document shows processing status
- [ ] Graph visualization loads
- [ ] Simple query works
- [ ] Multi-context query works
- [ ] Out-of-context query handled
- [ ] Document deletion works
- [ ] Error messages appear for errors
- [ ] UI remains responsive
- [ ] Status updates automatically
- [ ] Works in multiple browsers
- [ ] Mobile responsive layout
- [ ] API endpoints work
- [ ] Performance acceptable

---

## Debugging Tips

### Check Logs
```bash
# Docker
docker-compose logs -f

# Local
python app.py  # Watch console output
```

### Common Issues

**Issue**: Graph doesn't load
- Check: `data/graph_data/` folder exists
- Check: Matplotlib installed
- Check: file permissions

**Issue**: Chat unresponsive
- Check: GROQ_API_KEY set
- Check: Document status is "ready"
- Check: Network connectivity

**Issue**: Slow processing
- Check: File size
- Check: System RAM/CPU
- Check: Model download complete

**Issue**: Files disappear
- Note: HF Spaces ephemeral storage
- Solution: Use persistent storage option

---

## Test Report Template

```
Test Run Date: ____
Tester Name: ____
Environment: (Local/Docker/HF Spaces)
OS: ____
Browser: ____

PASS/FAIL | Test Case | Notes
---|---|---
 | Test 1 |
 | Test 2 |
 | Test 3 |
...

Issues Found:
1. 
2.
3.

Overall Result: PASS/FAIL
```

---

**Happy Testing! πŸŽ‰**

If you find issues, report them with:
- Steps to reproduce
- Expected vs actual behavior
- Browser/OS information
- Relevant logs