283 lines
7.3 KiB
Markdown
283 lines
7.3 KiB
Markdown
# 🧪 Location Testing Guide - Mock Location Feature
|
|
|
|
**Last Updated**: 14 Januari 2026
|
|
**Version**: 1.0
|
|
|
|
---
|
|
|
|
## 📌 Ringkasan
|
|
|
|
Aplikasi sekarang memiliki **Location Testing Feature** yang memungkinkan developer melakukan testing lokasi tanpa harus secara fisik berada di kampus. Fitur ini sangat berguna untuk testing dan development.
|
|
|
|
---
|
|
|
|
## 🎯 Lokasi Testing yang Tersedia
|
|
|
|
### **1. 🏢 Kampus (Exact Location)**
|
|
- **Koordinat**: Lat: -6.8961, Lon: 107.6100
|
|
- **Jarak dari kampus**: 0 meter
|
|
- **Status**: ✓ Dalam area (tepat di lokasi kampus)
|
|
- **Absensi**: ✅ **DITERIMA**
|
|
|
|
### **2. ✓ Dalam Area (85m)**
|
|
- **Koordinat**: Lat: -6.8955, Lon: 107.6105
|
|
- **Jarak dari kampus**: 85 meter
|
|
- **Status**: ✓ Dalam area utama
|
|
- **Absensi**: ✅ **DITERIMA**
|
|
|
|
### **3. ⚠️ Tepi Area (125m)**
|
|
- **Koordinat**: Lat: -6.8948, Lon: 107.6110
|
|
- **Jarak dari kampus**: 125 meter
|
|
- **Status**: ✓ Dalam area (toleransi/tepi)
|
|
- **Absensi**: ✅ **DITERIMA** (dengan warning)
|
|
|
|
### **4. ✗ Luar Area (200m)**
|
|
- **Koordinat**: Lat: -6.8930, Lon: 107.6120
|
|
- **Jarak dari kampus**: 200 meter
|
|
- **Status**: ✗ Di luar area
|
|
- **Absensi**: ❌ **DITOLAK**
|
|
|
|
### **5. ❌ Jauh di Luar (400m)**
|
|
- **Koordinat**: Lat: -6.8900, Lon: 107.6150
|
|
- **Jarak dari kampus**: 400 meter
|
|
- **Status**: ✗ Jauh di luar area
|
|
- **Absensi**: ❌ **DITOLAK**
|
|
|
|
---
|
|
|
|
## 🚀 Cara Menggunakan
|
|
|
|
### **Step 1: Buka Attendance Screen**
|
|
1. Login dengan NPM dan Nama
|
|
2. Masuk ke Attendance Screen
|
|
|
|
### **Step 2: Buka Debug Menu**
|
|
Klik icon **⚙️ Settings** di TopAppBar
|
|
|
|
```
|
|
┌────────────────────────────────┐
|
|
│ Absensi Akademik ⚙️ ✕ │
|
|
└────────────────────────────────┘
|
|
```
|
|
|
|
### **Step 3: Aktifkan Mock Location**
|
|
1. Di debug menu, toggle **"Mock Location"** ke ON
|
|
2. Warna akan berubah menjadi hijau saat aktif
|
|
|
|
### **Step 4: Pilih Lokasi Testing**
|
|
Klik salah satu dari 5 opsi lokasi testing yang tersedia:
|
|
- 🏢 Kampus (Exact)
|
|
- ✓ Dalam Area (85m)
|
|
- ⚠️ Tepi Area (125m)
|
|
- ✗ Luar Area (200m)
|
|
- ❌ Jauh di Luar (400m)
|
|
|
|
### **Step 5: Lihat Hasilnya**
|
|
Lokasi di **Status Lokasi** card akan berubah ke lokasi yang dipilih dengan indicator:
|
|
```
|
|
🧪 MOCK LOCATION (Testing Mode)
|
|
```
|
|
|
|
---
|
|
|
|
## 📂 File-File Terkait
|
|
|
|
### **1. `utils/LocationTestUtils.kt`**
|
|
Utility class untuk manage mock location
|
|
- `isMockLocationEnabled`: Flag untuk enable/disable mock location
|
|
- `mockLatitude` / `mockLongitude`: Koordinat mock yang sedang digunakan
|
|
- `setMockLocation()`: Set custom mock location
|
|
- `setMockLocationByType()`: Set mock location by predefined type
|
|
- `getMockLocationIfEnabled()`: Get mock location jika enabled
|
|
|
|
### **2. `presentation/screens/LocationDebugMenu.kt`**
|
|
UI untuk debug menu
|
|
- `LocationDebugMenu()`: Main debug dialog
|
|
- `LocationOptionButton()`: Individual location option button
|
|
|
|
### **3. `presentation/screens/AttendanceScreen.kt`** (Updated)
|
|
- Terintegrasi dengan LocationTestUtils
|
|
- Menampilkan indicator "🧪 MOCK LOCATION" saat mock aktif
|
|
- Menggunakan mock location jika diaktifkan
|
|
|
|
---
|
|
|
|
## 🔧 Cara Kerja Teknis
|
|
|
|
### **Flow Pengambilan Lokasi**
|
|
|
|
```
|
|
User klik "Perbarui Lokasi"
|
|
↓
|
|
locationPermissionLauncher triggered
|
|
↓
|
|
Check: isMockLocationEnabled?
|
|
├─ YES → Gunakan mock location dari LocationTestUtils
|
|
└─ NO → Gunakan GPS asli (getCurrentLocation)
|
|
↓
|
|
Update UI dengan lokasi
|
|
├─ Validasi dengan LocationValidator
|
|
└─ Tampilkan status (✓ atau ✗)
|
|
```
|
|
|
|
### **Code Example**
|
|
|
|
```kotlin
|
|
// Di AttendanceScreen.kt
|
|
val mockLocation = LocationTestUtils.getMockLocationIfEnabled()
|
|
|
|
if (mockLocation != null) {
|
|
// Gunakan mock location
|
|
latitude = mockLocation.first
|
|
longitude = mockLocation.second
|
|
// ... validasi lokasi
|
|
} else {
|
|
// Gunakan GPS asli
|
|
// ... get location from FusedLocationClient
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## ⚠️ **PENTING: Production Safety**
|
|
|
|
### **⛔ JANGAN Gunakan Mock Location di Production**
|
|
|
|
Mock location hanya untuk **testing dan development** di debug mode.
|
|
|
|
**Checklist sebelum release:**
|
|
- [ ] `LocationTestUtils.isMockLocationEnabled = false`
|
|
- [ ] Debug menu button di remove atau disable
|
|
- [ ] Semua testing dengan GPS asli
|
|
- [ ] Test di device fisik di lokasi kampus
|
|
|
|
### **Cara Disable Mock Location untuk Production**
|
|
|
|
Di `LocationTestUtils.kt`:
|
|
```kotlin
|
|
// Sebelum build production, ensure:
|
|
isMockLocationEnabled = false // Default false
|
|
```
|
|
|
|
---
|
|
|
|
## 🧪 Testing Scenarios
|
|
|
|
### **Scenario 1: User Berhasil Absen (Inside Area)**
|
|
1. Buka app
|
|
2. Login
|
|
3. Buka Debug Menu
|
|
4. Aktifkan Mock Location
|
|
5. Pilih "✓ Dalam Area (85m)"
|
|
6. Klik "Perbarui Lokasi"
|
|
7. Lihat status: **✓ Berada dalam area absensi**
|
|
8. Absensi berhasil ✅
|
|
|
|
### **Scenario 2: User di Tepi Area (Warning)**
|
|
1. Buka app
|
|
2. Login
|
|
3. Buka Debug Menu
|
|
4. Aktifkan Mock Location
|
|
5. Pilih "⚠️ Tepi Area (125m)"
|
|
6. Klik "Perbarui Lokasi"
|
|
7. Lihat status: **✓ Berada dalam area absensi (toleransi)**
|
|
8. Lihat warning: **⚠️ Berada di tepi area (25m dari batas)**
|
|
9. Absensi berhasil ✅ (dengan warning)
|
|
|
|
### **Scenario 3: User Di Luar Area (Ditolak)**
|
|
1. Buka app
|
|
2. Login
|
|
3. Buka Debug Menu
|
|
4. Aktifkan Mock Location
|
|
5. Pilih "✗ Luar Area (200m)"
|
|
6. Klik "Perbarui Lokasi"
|
|
7. Lihat status: **✗ Berada di luar area absensi**
|
|
8. Absensi ditolak ❌
|
|
|
|
---
|
|
|
|
## 🔍 Debugging Tips
|
|
|
|
### **Mock Location Tidak Muncul?**
|
|
- Pastikan icon ⚙️ Settings diklik
|
|
- Pastikan toggle "Mock Location" dalam posisi ON
|
|
- Pastikan salah satu lokasi testing dipilih
|
|
|
|
### **Lokasi Tidak Update?**
|
|
- Klik "Perbarui Lokasi" button
|
|
- Tunggu beberapa detik
|
|
- Check di console apakah LocationTestUtils enabled
|
|
|
|
### **Setelah Disable Mock, GPS Asli Masih Tidak Terdeteksi?**
|
|
- Pastikan device memiliki GPS
|
|
- Pastikan permission LOCATION diberikan
|
|
- Keluar dari ruangan untuk signal yang lebih baik
|
|
- Tunggu beberapa detik agar GPS akurat
|
|
|
|
---
|
|
|
|
## 📱 UI Indicators
|
|
|
|
### **Saat Mock Location Aktif**
|
|
|
|
Di Status Lokasi Card akan muncul:
|
|
```
|
|
📍 Status Lokasi
|
|
Lat: -6.8955
|
|
Lon: 107.6105
|
|
Jarak: 85.2m
|
|
|
|
🧪 MOCK LOCATION (Testing Mode)
|
|
|
|
✓ Berada dalam area absensi
|
|
```
|
|
|
|
Warna icon settings di TopAppBar akan berbeda untuk menunjukkan mode testing.
|
|
|
|
---
|
|
|
|
## 🔐 Security Considerations
|
|
|
|
1. **Mock Location hanya untuk development mode**
|
|
2. **Tidak bisa diaktifkan dengan permission biasa**
|
|
3. **Harus di-compile ulang untuk mengubah logika**
|
|
4. **Server juga melakukan validasi lokasi** (double-check)
|
|
|
|
---
|
|
|
|
## 📊 Koordinat Reference
|
|
|
|
| Lokasi | Latitude | Longitude | Jarak | Status |
|
|
|--------|----------|-----------|-------|--------|
|
|
| Kampus | -6.8961 | 107.6100 | 0m | ✓ |
|
|
| Inside | -6.8955 | 107.6105 | 85m | ✓ |
|
|
| Edge | -6.8948 | 107.6110 | 125m | ✓ + ⚠️ |
|
|
| Outside | -6.8930 | 107.6120 | 200m | ✗ |
|
|
| Far Outside | -6.8900 | 107.6150 | 400m | ✗ |
|
|
|
|
---
|
|
|
|
## 💡 Best Practices
|
|
|
|
1. **Selalu test dengan mock location dulu** sebelum test dengan GPS asli
|
|
2. **Test semua 5 lokasi** untuk cover semua scenario
|
|
3. **Disable mock location sebelum release** ke production
|
|
4. **Gunakan logging** untuk debug koordinat yang eksak
|
|
5. **Test di device fisik** sebelum final release
|
|
|
|
---
|
|
|
|
## 🚀 Next Steps
|
|
|
|
Setelah testing selesai:
|
|
1. ✅ Test dengan 5 lokasi testing
|
|
2. ✅ Test dengan GPS asli
|
|
3. ✅ Test dengan berbagai device
|
|
4. ✅ Disable mock location
|
|
5. ✅ Deploy ke production
|
|
|
|
---
|
|
|
|
**Happy Testing! 🎉**
|
|
|